Skip to content

Commit

Permalink
Merge remote-tracking branch 'nickclark2016/issues/1603'
Browse files Browse the repository at this point in the history
  • Loading branch information
starkos committed Jul 8, 2021
2 parents d863ec9 + d953b33 commit 4be2a96
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 9 deletions.
5 changes: 5 additions & 0 deletions modules/d/_preload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
"ShowDependencies",
})

api.addAllowed("toolset", {
"dmd",
"gdc",
"ldc",
})

--
-- Register some D specific properties
Expand Down
10 changes: 9 additions & 1 deletion modules/d/actions/gmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion modules/d/actions/visuald.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
29 changes: 28 additions & 1 deletion modules/d/tests/test_gmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
24 changes: 24 additions & 0 deletions src/base/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions website/docs/toolset.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 4be2a96

Please sign in to comment.