Provide a way to 'tag' systems, and filter on those tags.

This commit is contained in:
Tom van Dijck 2017-05-10 16:43:28 -07:00
parent 34aaff9c66
commit 70e00883f8
3 changed files with 46 additions and 3 deletions

View File

@ -668,3 +668,22 @@
end
return id
end
--
-- Get a set of tags for different 'platforms'
--
function os.getSystemTags(name)
local tags =
{
["aix"] = { "aix", "posix" },
["bsd"] = { "bsd", "posix" },
["haiku"] = { "haiku", "posix" },
["linux"] = { "linux", "posix" },
["macosx"] = { "macosx", "darwin", "posix" },
["solaris"] = { "solaris", "posix" },
["windows"] = { "windows", "win32" },
}
return tags[name] or name
end

View File

@ -64,7 +64,7 @@
context.addFilter(self, "action", _ACTION)
self.system = self.system or p.action.current().targetos or os.target()
context.addFilter(self, "system", self.system)
context.addFilter(self, "system", os.getSystemTags(self.system))
-- Add command line options to the filtering options
local options = {}
@ -205,7 +205,7 @@
-- values that might already in the context to override my defaults.
self.system = self.system or p.action.current().targetos or os.target()
context.addFilter(self, "system", self.system)
context.addFilter(self, "system", os.getSystemTags(self.system))
context.addFilter(self, "architecture", self.architecture)
-- The kind is a configuration level value, but if it has been set at the
@ -580,7 +580,7 @@
-- allow the project script to override the default system
ctx.system = ctx.system or system
context.addFilter(ctx, "system", ctx.system)
context.addFilter(ctx, "system", os.getSystemTags(ctx.system))
-- allow the project script to override the default architecture
ctx.architecture = ctx.architecture or architecture

View File

@ -107,3 +107,27 @@
prepare()
test.isequal({}, cfg.defines)
end
--
-- Test filtering on system.
--
function suite.onFilterLinuxIsPosix()
system "linux"
filter { "system:posix" }
defines { "POSIX" }
filter { "system:not posix" }
defines { "NOTPOSIX" }
prepare()
test.isequal({ "POSIX" }, cfg.defines)
end
function suite.onFilterWindowsIsNotPosix()
system "windows"
filter { "system:posix" }
defines { "POSIX" }
filter { "system:not posix" }
defines { "NOTPOSIX" }
prepare()
test.isequal({ "NOTPOSIX" }, cfg.defines)
end