Switch per-file build rules to use new build…() APIs

This commit is contained in:
Jason Perkins 2013-04-09 15:12:04 -04:00
parent d8308eb454
commit 0cd9bac896
10 changed files with 127 additions and 55 deletions

View File

@ -160,7 +160,7 @@
local rules
for cfg in project.eachconfig(prj) do
local filecfg = config.getfileconfig(cfg, node.abspath)
if filecfg and filecfg.buildrule then
if config.hasCustomBuildRule(filecfg) then
rules = true
break
end
@ -199,12 +199,12 @@
for cfg in project.eachconfig(prj) do
local filecfg = config.getfileconfig(cfg, node.abspath)
if filecfg then
local rule = filecfg.buildrule
_p('ifeq ($(config),%s)', make.esc(cfg.shortname))
_p('%s: %s', make.esc(rule.outputs[1]), make.esc(filecfg.relpath))
_p('\t@echo "%s"', rule.description or ("Building " .. filecfg.relpath))
for _, cmd in ipairs(rule.commands) do
local output = project.getrelative(prj, filecfg.buildoutputs[1])
_p('%s: %s', make.esc(output), make.esc(filecfg.relpath))
_p('\t@echo "%s"', filecfg.buildmessage or ("Building " .. filecfg.relpath))
for _, cmd in ipairs(filecfg.buildcommands) do
_p('\t$(SILENT) %s', cmd)
end
_p('endif')
@ -287,7 +287,7 @@
local filecfg = config.getfileconfig(cfg, node.abspath)
if filecfg and not filecfg.flags.ExcludeFromBuild then
incfg[cfg] = filecfg
custom = (filecfg.buildrule ~= nil)
custom = config.hasCustomBuildRule(filecfg)
else
inall = false
end
@ -329,7 +329,7 @@
if filecfg then
-- if the custom build outputs an object file, add it to
-- the link step automatically to match Visual Studio
local output = filecfg.buildrule.outputs[1]
local output = project.getrelative(prj, filecfg.buildoutputs[1])
if path.isobjectfile(output) then
table.insert(configs[cfg].objects, output)
end

View File

@ -927,7 +927,7 @@
function vc200x.compilerToolName(cfg, filecfg, depth)
local name
if filecfg and filecfg.buildrule then
if config.hasCustomBuildRule(filecfg) then
name = "VCCustomBuildTool"
else
name = iif(cfg.system == premake.XBOX360, "VCCLX360CompilerTool", "VCCLCompilerTool")
@ -947,9 +947,11 @@
function vc200x.customBuildTool(filecfg, depth)
if filecfg.buildrule then
_x(depth, 'CommandLine="%s"', table.concat(filecfg.buildrule.commands,'\r\n'))
_x(depth, 'Outputs="%s"', table.concat(filecfg.buildrule.outputs, ' '))
if config.hasCustomBuildRule(filecfg) then
_x(depth, 'CommandLine="%s"', table.concat(filecfg.buildcommands,'\r\n'))
local outputs = project.getrelative(filecfg.project, filecfg.buildoutputs)
_x(depth, 'Outputs="%s"', table.concat(outputs, ' '))
end
end

View File

@ -453,11 +453,11 @@
for cfg in project.eachconfig(prj) do
local condition = vc2010.condition(cfg)
local filecfg = config.getfileconfig(cfg, file.abspath)
if filecfg and filecfg.buildrule then
local commands = table.concat(filecfg.buildrule.commands,'\r\n')
if config.hasCustomBuildRule(filecfg) then
local commands = table.concat(filecfg.buildcommands,'\r\n')
_p(3,'<Command %s>%s</Command>', condition, premake.esc(commands))
local outputs = table.concat(filecfg.buildrule.outputs, ' ')
local outputs = table.concat(filecfg.buildoutputs, ' ')
_p(3,'<Outputs %s>%s</Outputs>', condition, premake.esc(outputs))
end
end
@ -490,7 +490,7 @@
local hasbuildrule = false
for cfg in project.eachconfig(prj) do
local filecfg = config.getfileconfig(cfg, node.abspath)
if filecfg and filecfg.buildrule then
if config.hasCustomBuildRule(filecfg) then
hasbuildrule = true
break
end

View File

@ -96,10 +96,8 @@
--
function api.callback(field, value)
if field.deprecated and not field.warned then
local msg = "** Warning: %s has been deprecated.\n See %s for more information."
print(string.format(msg, field.name, _PREMAKE_URL))
field.warned = true
if field.deprecated then
api.deprecated(field)
end
local target = api.gettarget(field.scope)
@ -126,6 +124,22 @@
end
--
-- Display an API deprecation warning for a specific field.
--
-- @param field
-- The field description object.
--
function api.deprecated(field)
if not field.warned then
local msg = "** Warning: %s has been deprecated.\n See %s for more information.\n"
io.stderr:write(string.format(msg, field.name, _PREMAKE_URL))
field.warned = true
end
end
--
-- The remover: adds values to be removed to the "removes" field on
-- current configuration. Removes are keyed by the associated field,
@ -519,6 +533,13 @@
},
}
api.register {
name = "buildmessage",
scope = "config",
kind = "string",
tokens = true,
}
api.register {
name = "buildcommands",
scope = "config",
@ -533,6 +554,13 @@
tokens = true,
}
api.register {
name = "buildoutputs",
scope = "config",
kind = "file-list",
tokens = true,
}
api.register {
name = "buildrule",
scope = "config",
@ -1021,6 +1049,17 @@
}
-- Deprecated 09 Apr 2013
function buildrule(rule)
api.deprecated(premake.fields.buildrule)
if rule.description then
buildmessage(rule.description)
end
buildcommands(rule.commands)
buildoutputs(rule.outputs)
end
api.reset()

View File

@ -461,3 +461,19 @@
function config.gettargetinfo(cfg)
return buildtargetinfo(cfg, cfg.kind, "target")
end
--
-- Checks to see if the project or file configuration contains a
-- custom build rule.
--
-- @param cfg
-- A project or file configuration.
-- @return
-- True if the configuration contains settings for a custom
-- build rule.
--
function config.hasCustomBuildRule(cfg)
return cfg and (#cfg.buildcommands > 0) and (#cfg.buildoutputs > 0)
end

View File

@ -52,14 +52,12 @@ $(OBJDIR)/hello1.o: src/hello.cpp
function suite.customBuildRule()
files { "hello.x" }
configuration "**.x"
buildrule {
description = "Compiling %{file.name}",
commands = {
'cxc -c "%{file.path}" -o "%{cfg.objdir}/%{file.basename}.xo"',
'c2o -c "%{cfg.objdir}/%{file.basename}.xo" -o "%{cfg.objdir}/%{file.basename}.obj"'
},
outputs = { "%{cfg.objdir}/%{file.basename}.obj" }
buildmessage "Compiling %{file.name}"
buildcommands {
'cxc -c "%{file.path}" -o "%{cfg.objdir}/%{file.basename}.xo"',
'c2o -c "%{cfg.objdir}/%{file.basename}.xo" -o "%{cfg.objdir}/%{file.basename}.obj"'
}
buildoutputs { "%{cfg.objdir}/%{file.basename}.obj" }
prepare()
test.capture [[
ifeq ($(config),debug)

View File

@ -129,14 +129,12 @@ RESOURCES := \
function suite.customBuildRule()
files { "hello.x" }
configuration "**.x"
buildrule {
description = "Compiling %{file.name}",
commands = {
'cxc -c "%{file.path}" -o "%{cfg.objdir}/%{file.basename}.xo"',
'c2o -c "%{cfg.objdir}/%{file.basename}.xo" -o "%{cfg.objdir}/%{file.basename}.obj"'
},
outputs = { "%{cfg.objdir}/%{file.basename}.obj" }
buildmessage "Compiling %{file.name}"
buildcommands {
'cxc -c "%{file.path}" -o "%{cfg.objdir}/%{file.basename}.xo"',
'c2o -c "%{cfg.objdir}/%{file.basename}.xo" -o "%{cfg.objdir}/%{file.basename}.obj"'
}
buildoutputs { "%{cfg.objdir}/%{file.basename}.obj" }
prepare()
test.capture [[
OBJECTS := \

View File

@ -260,14 +260,12 @@
function suite.customBuildTool_onBuildRule()
files { "hello.x" }
configuration "**.x"
buildrule {
description = "Compiling $(InputFile)",
commands = {
'cxc -c "$(InputFile)" -o "$(IntDir)/$(InputName).xo"',
'c2o -c "$(IntDir)/$(InputName).xo" -o "$(IntDir)/$(InputName).obj"'
},
outputs = { "$(IntDir)/$(InputName).obj" }
buildmessage "Compiling $(InputFile)"
buildcommands {
'cxc -c "$(InputFile)" -o "$(IntDir)/$(InputName).xo"',
'c2o -c "$(IntDir)/$(InputName).xo" -o "$(IntDir)/$(InputName).obj"'
}
buildoutputs { "$(IntDir)/$(InputName).obj" }
prepare()
test.capture [[
<File
@ -285,6 +283,33 @@
]]
end
function suite.customBuildTool_onBuildRuleWithTokens()
files { "hello.x" }
objdir "../../../tmp"
configuration "**.x"
buildmessage "Compiling $(InputFile)"
buildcommands {
'cxc -c %{file.relpath} -o %{cfg.objdir}/%{file.basename}.xo',
'c2o -c %{cfg.objdir}/%{file.basename}.xo -o %{cfg.objdir}/%{file.basename}.obj'
}
buildoutputs { "%{cfg.objdir}/%{file.basename}.obj" }
prepare()
test.capture [[
<File
RelativePath="hello.x"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="cxc -c hello.x -o obj/Debug/hello.xo&#x0D;&#x0A;c2o -c obj/Debug/hello.xo -o obj/Debug/hello.obj"
Outputs="obj/Debug/hello.obj"
/>
</FileConfiguration>
]]
end
--
-- If two files at different folder levels have the same name, a different

View File

@ -72,10 +72,8 @@
function suite.customBuild_onBuildRule()
files { "hello.cg" }
configuration "**.cg"
buildrule {
commands = { "cgc $(InputFile)" },
outputs = { "$(InputName).obj" }
}
buildcommands { "cgc $(InputFile)" }
buildoutputs { "$(InputName).obj" }
prepare()
test.capture [[
<ItemGroup>

View File

@ -6,7 +6,7 @@
T.vs2010_filters = { }
local suite = T.vs2010_filters
local vc2010 = premake.vstudio.vc2010
local vc2010 = premake.vstudio.vc2010
--
@ -14,7 +14,7 @@
--
local sln, prj
function suite.setup()
_ACTION = "vs2010"
sln = test.createsolution()
@ -68,10 +68,8 @@
function suite.itemGroup_onBuildRule()
files { "hello.c", "hello.h", "hello.rc", "hello.cg" }
configuration "**.cg"
buildrule {
commands = { "cgc $(InputFile)" },
outputs = { "$(InputName).obj" }
}
buildcommands { "cgc $(InputFile)" }
buildoutputs { "$(InputName).obj" }
prepare("CustomBuild")
test.capture [[
<ItemGroup>
@ -83,10 +81,8 @@
function suite.itemGroup_onSingleConfigBuildRule()
files { "hello.c", "hello.h", "hello.rc", "hello.cg" }
configuration { "Release", "**.cg" }
buildrule {
commands = { "cgc $(InputFile)" },
outputs = { "$(InputName).obj" }
}
buildcommands { "cgc $(InputFile)" }
buildoutputs { "$(InputName).obj" }
prepare("CustomBuild")
test.capture [[
<ItemGroup>