Don't add a file to a target if it isn't built on any configuration

Without this, files are added to the exclude list on all configurations,
which disables autocompletion on Xcode. If a file is just excluded in
some configurations it's handled the old way.
This commit is contained in:
Jordi Vilalta Prat 2018-06-14 19:39:44 +02:00
parent e9dda518cf
commit 97e3a07c1c
2 changed files with 35 additions and 2 deletions

View File

@ -812,7 +812,7 @@
_p(3,'files = (')
tree.traverse(tr, {
onleaf = function(node)
if xcode.getbuildcategory(node) == "Sources" then
if xcode.getbuildcategory(node) == "Sources" and node.buildid then
_p(4,'%s /* %s in Sources */,', node.buildid, node.name)
end
end

View File

@ -15,6 +15,39 @@
local fileconfig = p.fileconfig
local tree = p.tree
--
-- Checks if a node must be excluded completely from a target or not. It will
-- return true only if the node has the "ExcludeFromBuild" flag in all the
-- configurations.
--
-- @param node
-- The node to check.
-- @param prj
-- The project being generated.
-- @returns
-- A boolean, telling whether the node must be excluded from its target or not.
--
function xcode.mustExcludeFromTarget(node, prj)
if not node.configs then
return false
end
local value
for cfg in premake.project.eachconfig(prj) do
local filecfg = premake.fileconfig.getconfig(node, cfg)
if filecfg then
local newValue = not not filecfg.flags.ExcludeFromBuild
if value == nil then
value = newValue
elseif value ~= newValue then
print("WARNING: " .. node.name .. " is excluded in just some configurations. Autocompletion will not work correctly on this file in Xcode.")
return false
end
end
end
return value
end
--
-- Create a tree corresponding to what is shown in the Xcode project browser
-- pane, with nodes for files and folders, resources, frameworks, and products.
@ -108,7 +141,7 @@
node.isResource = xcode.isItemResource(prj, node)
-- assign build IDs to buildable files
if xcode.getbuildcategory(node) and not node.excludefrombuild then
if xcode.getbuildcategory(node) and not node.excludefrombuild and not xcode.mustExcludeFromTarget(node, tr.project) then
node.buildid = xcode.newid(node.name, "build", node.path)
end