Merge pull request #788 from Blizzard/os-tags

Provide a way to 'tag' systems, and filter on those tags.
This commit is contained in:
Tom van Dijck 2017-06-13 08:32:42 -07:00 committed by GitHub
commit 6437cfddd9
3 changed files with 46 additions and 3 deletions

View File

@ -713,3 +713,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)
context.addFilter(self, "tags", self.tags)
@ -581,7 +581,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