Skip to content

Commit

Permalink
Fix os.translateCommandsAndPaths.
Browse files Browse the repository at this point in the history
Fix msvc rule with `%[path]`.
Fix xcode4 with `%[path]`.
  • Loading branch information
Jarod42 committed May 13, 2023
1 parent 3f1e4f8 commit 363560a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion modules/vstudio/vs2010_rules_props.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@

-- write out the result.
if buildcommands and #buildcommands > 0 then
local cmds = os.translateCommands(buildcommands, p.WINDOWS)
local cmds = os.translateCommandsAndPaths(buildcommands, r.basedir, r.location, p.WINDOWS)
cmds = table.concat(cmds, p.eol())
p.x('<CommandLineTemplate>%s</CommandLineTemplate>', cmds)
end
Expand Down
2 changes: 1 addition & 1 deletion modules/xcode/xcode_common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@

if #commands > 0 then
table.insert(commands, 1, 'set -e') -- Tells the shell to exit when any command fails
commands = os.translateCommands(commands, p.MACOSX)
commands = os.translateCommandsAndPaths(commands, tr.project.basedir, tr.project.location, p.MACOSX)
if not wrapperWritten then
_p('/* Begin PBXShellScriptBuildPhase section */')
wrapperWritten = true
Expand Down
6 changes: 3 additions & 3 deletions src/base/os.lua
Original file line number Diff line number Diff line change
Expand Up @@ -735,12 +735,12 @@
-- Translate decorated command paths into their OS equivalents.
---
function os.translateCommandsAndPaths(cmds, basedir, location, map)
local translatedBaseDir = path.getrelative(location, basedir)

map = map or os.target()
location = path.getabsolute(location)
basedir = path.getabsolute(basedir)

local translateFunction = function(value)
local result = path.join(translatedBaseDir, value)
local result = path.getrelative(location, path.join(basedir, value))
result = os.translateCommandAndPath(result, map)
if value:endswith('/') or value:endswith('\\') or -- if original path ends with a slash then ensure the same
value:endswith('/"') or value:endswith('\\"') then
Expand Down
3 changes: 3 additions & 0 deletions tests/base/test_os.lua
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,9 @@
test.isequal('cmdtool "../foo/path1" "../foo/path2/"', os.translateCommandsAndPaths("cmdtool %[path1] %[path2/]", '../foo', '.', 'osx'))
end

function suite.translateCommandsAndPaths_RelativePath()
test.isequal('cmdtool "path1" "../bar/path2/"', os.translateCommandsAndPaths("cmdtool %[../foo/path1] %[path2/]", './bar', './foo', 'osx'))
end

--
-- Helpers
Expand Down

0 comments on commit 363560a

Please sign in to comment.