Merge pull request #939 from premake/resolve_rule_props
Resolve the rule properties for gmake (#162)
This commit is contained in:
commit
a3c80ae238
@ -237,6 +237,26 @@
|
||||
cpp.addRuleFile(cfg, node)
|
||||
end
|
||||
|
||||
function cpp.prepareEnvironment(rule, environ, cfg)
|
||||
for _, prop in ipairs(rule.propertydefinition) do
|
||||
local fld = p.rule.getPropertyField(rule, prop)
|
||||
local value = cfg[fld.name]
|
||||
if value ~= nil then
|
||||
|
||||
if fld.kind == "path" then
|
||||
value = gmake2.path(cfg, value)
|
||||
elseif fld.kind == "list:path" then
|
||||
value = gmake2.path(cfg, value)
|
||||
end
|
||||
|
||||
value = p.rule.expandString(rule, prop, value)
|
||||
if value ~= nil and #value > 0 then
|
||||
environ[prop.name] = p.esc(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function cpp.addRuleFile(cfg, node)
|
||||
local rules = cfg.project._gmake.rules
|
||||
local rule = rules[path.getextension(node.abspath):lower()]
|
||||
@ -246,7 +266,8 @@
|
||||
local environ = table.shallowcopy(filecfg.environ)
|
||||
|
||||
if rule.propertydefinition then
|
||||
p.rule.prepareEnvironment(rule, environ, "$(%s)")
|
||||
cpp.prepareEnvironment(rule, environ, cfg)
|
||||
cpp.prepareEnvironment(rule, environ, filecfg)
|
||||
end
|
||||
|
||||
local shadowContext = p.context.extent(rule, environ)
|
||||
@ -298,7 +319,6 @@
|
||||
cpp.linkCmd,
|
||||
cpp.bindirs,
|
||||
cpp.exepaths,
|
||||
cpp.ruleProperties,
|
||||
gmake2.settings,
|
||||
gmake2.preBuildCmds,
|
||||
gmake2.preLinkCmds,
|
||||
@ -491,29 +511,6 @@
|
||||
end
|
||||
|
||||
|
||||
function cpp.ruleProperties(cfg, toolset)
|
||||
for i = 1, #cfg.rules do
|
||||
local rule = p.global.getRule(cfg.rules[i])
|
||||
|
||||
for prop in p.rule.eachProperty(rule) do
|
||||
local fld = p.rule.getPropertyField(rule, prop)
|
||||
local value = cfg[fld.name]
|
||||
if value ~= nil then
|
||||
if fld.kind == "path" then
|
||||
value = gmake2.path(cfg, value)
|
||||
elseif fld.kind == "list:path" then
|
||||
value = gmake2.path(cfg, value)
|
||||
end
|
||||
|
||||
value = p.rule.expandString(rule, prop, value)
|
||||
if value ~= nil and #value > 0 then
|
||||
p.outln(prop.name .. ' = ' .. p.esc(value))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--
|
||||
-- Write out the per file configurations.
|
||||
--
|
||||
|
@ -165,6 +165,26 @@
|
||||
end
|
||||
|
||||
|
||||
function utility.prepareEnvironment(rule, environ, cfg)
|
||||
for _, prop in ipairs(rule.propertydefinition) do
|
||||
local fld = p.rule.getPropertyField(rule, prop)
|
||||
local value = cfg[fld.name]
|
||||
if value ~= nil then
|
||||
|
||||
if fld.kind == "path" then
|
||||
value = gmake2.path(cfg, value)
|
||||
elseif fld.kind == "list:path" then
|
||||
value = gmake2.path(cfg, value)
|
||||
end
|
||||
|
||||
value = p.rule.expandString(rule, prop, value)
|
||||
if value ~= nil and #value > 0 then
|
||||
environ[prop.name] = p.esc(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function utility.addRuleFile(cfg, node)
|
||||
local rules = cfg.project._gmake.rules
|
||||
local rule = rules[path.getextension(node.abspath):lower()]
|
||||
@ -174,7 +194,8 @@
|
||||
local environ = table.shallowcopy(filecfg.environ)
|
||||
|
||||
if rule.propertydefinition then
|
||||
p.rule.prepareEnvironment(rule, environ, "$(%s)")
|
||||
utility.prepareEnvironment(rule, environ, cfg)
|
||||
utility.prepareEnvironment(rule, environ, filecfg)
|
||||
end
|
||||
|
||||
local shadowContext = p.context.extent(rule, environ)
|
||||
@ -209,7 +230,6 @@
|
||||
|
||||
utility.elements.configuration = function(cfg)
|
||||
return {
|
||||
utility.ruleProperties,
|
||||
gmake2.settings,
|
||||
gmake2.preBuildCmds,
|
||||
gmake2.preLinkCmds,
|
||||
@ -218,30 +238,6 @@
|
||||
end
|
||||
|
||||
|
||||
function utility.ruleProperties(cfg, toolset)
|
||||
for i = 1, #cfg.rules do
|
||||
local rule = p.global.getRule(cfg.rules[i])
|
||||
|
||||
for prop in p.rule.eachProperty(rule) do
|
||||
local fld = p.rule.getPropertyField(rule, prop)
|
||||
local value = cfg[fld.name]
|
||||
if value ~= nil then
|
||||
if fld.kind == "path" then
|
||||
value = gmake2.path(cfg, value)
|
||||
elseif fld.kind == "list:path" then
|
||||
value = gmake2.path(cfg, value)
|
||||
end
|
||||
|
||||
value = p.rule.expandString(rule, prop, value)
|
||||
if value ~= nil and #value > 0 then
|
||||
p.outln(prop.name .. ' = ' .. p.esc(value))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Write out the file sets.
|
||||
|
@ -18,6 +18,29 @@
|
||||
function suite.setup()
|
||||
p.escaper(gmake2.esc)
|
||||
gmake2.cpp.initialize()
|
||||
|
||||
rule "TestRule"
|
||||
display "Test Rule"
|
||||
fileextension ".rule"
|
||||
|
||||
propertydefinition {
|
||||
name = "TestProperty",
|
||||
kind = "boolean",
|
||||
value = false,
|
||||
switch = "-p"
|
||||
}
|
||||
|
||||
propertydefinition {
|
||||
name = "TestProperty2",
|
||||
kind = "boolean",
|
||||
value = false,
|
||||
switch = "-p2"
|
||||
}
|
||||
|
||||
buildmessage 'Rule-ing %{file.name}'
|
||||
buildcommands 'dorule %{TestProperty} %{TestProperty2} "%{file.path}"'
|
||||
buildoutputs { "%{file.basename}.obj" }
|
||||
|
||||
wks = test.createWorkspace()
|
||||
end
|
||||
|
||||
@ -139,3 +162,32 @@ obj/Release/hello.obj: hello.x hello.x.inc hello.x.inc2
|
||||
endif
|
||||
]]
|
||||
end
|
||||
|
||||
function suite.customRuleWithProps()
|
||||
|
||||
rules { "TestRule" }
|
||||
|
||||
files { "test.rule", "test2.rule" }
|
||||
|
||||
testRuleVars {
|
||||
TestProperty = true
|
||||
}
|
||||
|
||||
filter "files:test2.rule"
|
||||
testRuleVars {
|
||||
TestProperty2 = true
|
||||
}
|
||||
|
||||
prepare()
|
||||
test.capture [[
|
||||
# File Rules
|
||||
# #############################################
|
||||
|
||||
test.obj: test.rule
|
||||
@echo Rule-ing test.rule
|
||||
$(SILENT) dorule -p "test.rule"
|
||||
test2.obj: test2.rule
|
||||
@echo Rule-ing test2.rule
|
||||
$(SILENT) dorule -p -p2 "test2.rule"
|
||||
]]
|
||||
end
|
||||
|
@ -174,6 +174,15 @@
|
||||
end
|
||||
end
|
||||
|
||||
-- bool just emits the switch
|
||||
if type(value) == "boolean" then
|
||||
if value then
|
||||
return prop.switch
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
-- enum?
|
||||
if prop.values then
|
||||
local i = table.indexof(prop.values, value)
|
||||
|
Reference in New Issue
Block a user