Merge remote-tracking branch 'nickclark2016/issues/1603'

This commit is contained in:
starkos 2021-07-08 06:26:20 -04:00
commit 4be2a96761
6 changed files with 81 additions and 9 deletions

View File

@ -54,6 +54,11 @@
"ShowDependencies",
})
api.addAllowed("toolset", {
"dmd",
"gdc",
"ldc",
})
--
-- Register some D specific properties

View File

@ -205,7 +205,7 @@
-- identify the toolset used by this configurations (would be nicer if
-- this were computed and stored with the configuration up front)
local toolset = p.tools[_OPTIONS.dc or cfg.toolset or "dmd"]
local toolset = m.make.getToolset(cfg)
if not toolset then
error("Invalid toolset '" + (_OPTIONS.dc or cfg.toolset) + "'")
end
@ -217,6 +217,14 @@
end
end
function m.make.getToolset(cfg)
local toolset, err = p.api.checkValue(p.fields.toolset, _OPTIONS.dc or cfg.toolset or "dmd")
if err then
error { msg=err }
end
return p.tools[toolset]
end
function m.make.dTools(cfg, toolset)
local tool = toolset.gettoolname(cfg, "dc")
if tool then

View File

@ -175,7 +175,12 @@
_p(2,'<ignoreUnsupportedPragmas>0</ignoreUnsupportedPragmas>')
local compiler = { dmd="0", gdc="1", ldc="2" }
m.visuald.element(2, "compiler", compiler[_OPTIONS.dc or cfg.toolset or "dmd"])
local compilerName, err = p.api.checkValue(p.fields.toolset, _OPTIONS.dc or cfg.toolset or "dmd")
if err then
error { msg=err }
end
m.visuald.element(2, "compiler", compiler[compilerName])
m.visuald.element(2, "otherDMD", '0')
m.visuald.element(2, "program", '$(DMDInstallDir)windows\\bin\\dmd.exe')

View File

@ -30,7 +30,7 @@
local function prepare_cfg(calls)
prj = p.workspace.getproject(wks, 1)
local cfg = test.getconfig(prj, "Debug")
local toolset = p.tools.dmd
local toolset = m.make.getToolset(cfg) or p.tools.dmd
p.callArray(calls, cfg, toolset)
end
@ -193,3 +193,30 @@ all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)
@:
]]
end
function suite.make_dTools_dmd()
toolset "dmd"
prepare_cfg({ m.make.dTools })
test.capture [[
DC = dmd
]]
end
function suite.make_dTools_gdc()
toolset "gdc"
prepare_cfg({ m.make.dTools })
test.capture [[
DC = gdc
]]
end
function suite.make_dTools_ldc()
toolset "ldc"
prepare_cfg({ m.make.dTools })
test.capture [[
DC = ldc2
]]
end

View File

@ -350,6 +350,13 @@
end
else
field.allowed = field.allowed or {}
-- If we are trying to add where the current value is a function,
-- put the function in a table
if type(field.allowed) == "function" then
field.allowed = { field.allowed }
end
if field.allowed[value:lower()] == nil then
table.insert(field.allowed, value)
field.allowed[value:lower()] = value
@ -647,6 +654,23 @@
end
end
-- If a tool was not found, check to see if there is a function in the
-- table to check against. For each function in the table, check if
-- the value is allowed (break early if so).
if not canonical then
for _, allow in ipairs(field.allowed)
do
if type(allow) == "function" then
canonical = allow(value, kind or "string")
end
if canonical then
break
end
end
end
if not canonical then
return nil, "invalid value '" .. value .. "' for " .. field.name
end

View File

@ -10,12 +10,15 @@ If no toolset is specified for a configuration, the system or IDE default will b
`identifier` is a string identifier for the toolset. Premake includes the following toolsets by default.
| **Toolset identifier** | **Description** |
|------------|------------------------------------------------|
| `clang` | [Clang](http://clang.llvm.org) |
| `dotnet` | The system's default C# compiler |
| `gcc` | [GNU Compiler Collection](https://gcc.gnu.org) |
| `msc` | Microsoft C/C++ compiler |
| **Toolset identifier** | **Description** |
|------------|---------------------------------------------------------------|
| `clang` | [Clang](http://clang.llvm.org) |
| `dmd` | [Reference D Compiler](https://dlang.org/dmd-windows.html) |
| `dotnet` | The system's default C# compiler |
| `gcc` | [GNU Compiler Collection](https://gcc.gnu.org) |
| `gdc` | [GNU Compiler Collection D Compiler](https://gdcproject.org/) |
| `ldc` | [LLVM D Compiler](https://wiki.dlang.org/LDC) |
| `msc` | Microsoft C/C++ compiler |
If a specific toolset version is desired, it may be specified as part of the identifer, separated by a dash. See the examples below.