diff --git a/src/_premake_init.lua b/src/_premake_init.lua index 43afa5603..9a2f820c5 100644 --- a/src/_premake_init.lua +++ b/src/_premake_init.lua @@ -1871,6 +1871,17 @@ } } + newoption + { + trigger = "shell", + value = "VALUE", + description = "Select shell (for command token substitution)", + allowed = { + { "cmd", "Windows command shell" }, + { "posix", "For posix shells" }, + } + } + newoption { trigger = "scripts", diff --git a/src/base/os.lua b/src/base/os.lua index c195050ee..7cb3153f8 100644 --- a/src/base/os.lua +++ b/src/base/os.lua @@ -258,6 +258,13 @@ return table.contains(tags, id:lower()) end +-- +-- Retrieve the current target shell ID string. +-- + + function os.shell() + return _OPTIONS.shell or iif(os.target() == "windows", "cmd", "posix") + end --- -- Determine if a directory exists on the file system, and that it is a @@ -599,7 +606,7 @@ --- os.commandTokens = { - _ = { + posix = { chdir = function(v) return "cd " .. path.normalize(v) end, @@ -631,7 +638,7 @@ return "touch " .. path.normalize(v) end, }, - windows = { + cmd = { chdir = function(v) return "chdir " .. path.translate(path.normalize(v)) end, @@ -681,9 +688,12 @@ } function os.translateCommands(cmd, map) - map = map or os.target() + map = map or os.shell() if type(map) == "string" then - map = os.commandTokens[map] or os.commandTokens["_"] + if map == "windows" then -- For retro compatibility + map = "cmd" + end + map = os.commandTokens[map] or os.commandTokens["posix"] end local processOne = function(cmd) @@ -697,7 +707,7 @@ local token = cmd:sub(i + 1, j - 1):lower() local args = cmd:sub(j + 2) - local func = map[token] or os.commandTokens["_"][token] + local func = map[token] or os.commandTokens["posix"][token] if func then cmd = cmd:sub(1, i -1) .. func(args) end @@ -725,7 +735,7 @@ -- Apply os slashes for decorated command paths. --- function os.translateCommandAndPath(dir, map) - if map == 'windows' then + if map == 'windows' or map == 'cmd' then return path.translate(dir) end return dir @@ -737,7 +747,7 @@ function os.translateCommandsAndPaths(cmds, basedir, location, map) local translatedBaseDir = path.getrelative(location, basedir) - map = map or os.target() + map = map or os.shell() local translateFunction = function(value) local result = path.join(translatedBaseDir, value) diff --git a/website/docs/Tokens.md b/website/docs/Tokens.md index 639cc8549..d76825a01 100644 --- a/website/docs/Tokens.md +++ b/website/docs/Tokens.md @@ -72,7 +72,7 @@ file.extension -- (including '.'; eg ".cpp") ## Command Tokens -Command tokens represent a system level command in a platform-neutral way. +Command tokens represent a system level command in a shell-neutral way. ```lua postbuildcommands { @@ -92,11 +92,11 @@ You can use command tokens anywhere you specify a command line, including: * [prelinkcommands](prelinkcommands.md) * [rebuildcommands](rebuildcommands.md) -Command tokens are replaced with an appropriate command for the target platform. For Windows, path separators in the commmand arguments are converted to backslashes. +Command tokens are replaced with an appropriate command for the target shell. For Windows, path separators in the commmand arguments are converted to backslashes. The available tokens, and their replacements: -| Token | DOS | Posix | +| Token | DOS/cmd | Posix | |------------|---------------------------------------------|-----------------| | {CHDIR} | chdir {args} | cd {args} | | {COPYFILE} | copy /B /Y {args} | cp -f {args} |