From 97e3a07c1c9457e93bfb8adc94f286030f56cb99 Mon Sep 17 00:00:00 2001 From: Jordi Vilalta Prat Date: Thu, 14 Jun 2018 19:39:44 +0200 Subject: [PATCH 1/2] 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. --- modules/xcode/xcode_common.lua | 2 +- modules/xcode/xcode_project.lua | 35 ++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/modules/xcode/xcode_common.lua b/modules/xcode/xcode_common.lua index 20585c9a..8896b2d1 100644 --- a/modules/xcode/xcode_common.lua +++ b/modules/xcode/xcode_common.lua @@ -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 diff --git a/modules/xcode/xcode_project.lua b/modules/xcode/xcode_project.lua index 819b7723..2f98cb52 100644 --- a/modules/xcode/xcode_project.lua +++ b/modules/xcode/xcode_project.lua @@ -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 From 2724cf672b46f5229273bbb5ae90587688372e89 Mon Sep 17 00:00:00 2001 From: Jordi Vilalta Prat Date: Wed, 22 Aug 2018 11:41:37 +0200 Subject: [PATCH 2/2] Use p.warn() instead of print() --- modules/xcode/xcode_project.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/xcode/xcode_project.lua b/modules/xcode/xcode_project.lua index 2f98cb52..133135f6 100644 --- a/modules/xcode/xcode_project.lua +++ b/modules/xcode/xcode_project.lua @@ -40,7 +40,7 @@ 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.") + p.warn(node.name .. " is excluded in just some configurations. Autocompletion will not work correctly on this file in Xcode.") return false end end