premake / premake/premake-core

forced slash replacement

Open
#41 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug enhancement question
Dominant language
C
Stars
3.6k
Forks
654
Avg merge
1d 1h
Merged PRs (30d)
13

Description

prerequisites

premake5.lua

local qt_bin_path = "C:/dev/mx/v1/dep/qt/qt_33_x64_bin"

solution "myTestSln"
  location "testfiles/sln"

  platforms "x64"
  configurations "release"
  project "myTestPrj1"
    kind "Utility"
    files (qt_bin_path.."/bin/QtDeclarative_sofistik33_x64_4.dll")

    filter "files:**/*.dll"
      buildmessage ([[%{file.name} (copy)]])
      buildcommands [[xcopy /y "%{file.path:gsub("/","\\")}" "bla"]]
      buildoutputs ("bla")
    filter "*"

Problem
The resulting path can be an absolute and all "" in the path are replaced by "/". There is - afaik - no possibility to change the slashes and not all Windows tools - like xcopy - can handle paths with "/".

Cause
If premake is detecting absolute paths in non path variables, they are replaced by relative paths. This is not possible all the time (not sure but here can be a bug, too). It's never possible on Windows system where files are placed over different Partitions (C:; D:).

detoken.lua:66

local isAbs = path.isabsolute(result)
if isAbs and not field.paths and basedir then
  result = path.getrelative(basedir, result)
end

The path.getrelative function calls path.normalize which replaces all the "" to "/". This is not the system specification but required for further processing in premake.

path_normalize.c:30

if (ch == '\\') {
  ch = '/';
}

possible Solution
Allow avoiding path fixing.

detoken.lua:66

local isAbs = path.isabsolute(result)
if type(result) == "string" and result:find("!$") then
  result = result:match("(.-)!$"):gsub("/","\\")
elseif isAbs and not field.paths and basedir then
  result = path.getrelative(basedir, result)
end

premake5.lua (part replacement)

buildcommands [[xcopy /y "%{file.path.."!"}" "bla"]]

Or is there a way I didn't see?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied premake5.lua reproduction, then inspect detoken.lua:66 and path_normalize.c:30 to trace where the absolute path becomes relative and Windows separators are changed. Compare the generated build command with the expected xcopy command and determine a narrowly scoped way to preserve the required path form without breaking normal path processing.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, lua
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.