From fd49222a82602d34dc44ae6aecb2b24ff3ac73f9 Mon Sep 17 00:00:00 2001 From: tempura-sukiyaki <10625603+tempura-sukiyaki@users.noreply.github.com> Date: Wed, 1 Aug 2018 17:31:10 +0900 Subject: [PATCH] Add support `kind:Utility` in xcode4 --- modules/xcode/_preload.lua | 2 +- modules/xcode/tests/test_xcode_project.lua | 56 ++++++++++++++ modules/xcode/xcode_common.lua | 88 +++++++++++++++++----- modules/xcode/xcode_project.lua | 1 + 4 files changed, 127 insertions(+), 20 deletions(-) diff --git a/modules/xcode/_preload.lua b/modules/xcode/_preload.lua index fb8fd8c16f..d97a03e327 100644 --- a/modules/xcode/_preload.lua +++ b/modules/xcode/_preload.lua @@ -55,7 +55,7 @@ -- The capabilities of this action - valid_kinds = { "ConsoleApp", "WindowedApp", "SharedLib", "StaticLib", "Makefile", "None" }, + valid_kinds = { "ConsoleApp", "WindowedApp", "SharedLib", "StaticLib", "Makefile", "Utility", "None" }, valid_languages = { "C", "C++" }, valid_tools = { cc = { "gcc", "clang" }, diff --git a/modules/xcode/tests/test_xcode_project.lua b/modules/xcode/tests/test_xcode_project.lua index 28129673fb..620e73861b 100644 --- a/modules/xcode/tests/test_xcode_project.lua +++ b/modules/xcode/tests/test_xcode_project.lua @@ -686,6 +686,62 @@ end +--------------------------------------------------------------------------- +-- PBXAggregateTarget tests +--------------------------------------------------------------------------- + + function suite.PBXAggregateTarget_OnUtility() + kind "Utility" + prepare() + xcode.PBXAggregateTarget(tr) + test.capture [[ +/* Begin PBXAggregateTarget section */ + [MyProject:target] /* MyProject */ = { + isa = PBXAggregateTarget; + buildConfigurationList = [MyProject:cfg] /* Build configuration list for PBXAggregateTarget "MyProject" */; + buildPhases = ( + ); + buildRules = ( + ); + dependencies = ( + ); + name = MyProject; + productName = MyProject; + }; +/* End PBXAggregateTarget section */ + ]] + end + + + function suite.PBXAggregateTarget_OnBuildCommands() + kind "Utility" + prebuildcommands { "prebuildcmd" } + prelinkcommands { "prelinkcmd" } + postbuildcommands { "postbuildcmd" } + prepare() + xcode.PBXAggregateTarget(tr) + test.capture [[ +/* Begin PBXAggregateTarget section */ + [MyProject:target] /* MyProject */ = { + isa = PBXAggregateTarget; + buildConfigurationList = [MyProject:cfg] /* Build configuration list for PBXAggregateTarget "MyProject" */; + buildPhases = ( + 9607AE1010C857E500CD1376 /* Prebuild */, + 9607AE3510C85E7E00CD1376 /* Prelink */, + 9607AE3710C85E8F00CD1376 /* Postbuild */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = MyProject; + productName = MyProject; + }; +/* End PBXAggregateTarget section */ + ]] + end + + --------------------------------------------------------------------------- -- PBXProject tests --------------------------------------------------------------------------- diff --git a/modules/xcode/xcode_common.lua b/modules/xcode/xcode_common.lua index 15e0f2703a..34cbc516b7 100644 --- a/modules/xcode/xcode_common.lua +++ b/modules/xcode/xcode_common.lua @@ -575,6 +575,14 @@ return end + local function isAggregateTarget(node) + local productsId = xcode.newid("Products") + return node.id == productsId and node.parent.project and node.parent.project.kind == "Utility" + end + if isAggregateTarget(node) then + return + end + settings[node.productgroupid or node.id] = function() -- project references get special treatment if node.parent == tr.projects then @@ -586,7 +594,9 @@ _p(3,'isa = PBXGroup;') _p(3,'children = (') for _, childnode in ipairs(node.children) do - _p(4,'%s /* %s */,', childnode.id, childnode.name) + if not isAggregateTarget(childnode) then + _p(4,'%s /* %s */,', childnode.id, childnode.name) + end end _p(3,');') @@ -621,8 +631,30 @@ end - function xcode.PBXNativeTarget(tr) - _p('/* Begin PBXNativeTarget section */') + local function xcode_PBXAggregateOrNativeTarget(tr, pbxTargetName) + local kinds = { + Aggregate = { + "Utility", + }, + Native = { + "ConsoleApp", + "WindowedApp", + "SharedLib", + "StaticLib", + }, + } + local hasTarget = false + for _, node in ipairs(tr.products.children) do + hasTarget = table.contains(kinds[pbxTargetName], node.cfg.kind) + if hasTarget then + break + end + end + if not hasTarget then + return + end + + _p('/* Begin PBX%sTarget section */', pbxTargetName) for _, node in ipairs(tr.products.children) do local name = tr.project.name @@ -644,18 +676,22 @@ end _p(2,'%s /* %s */ = {', node.targetid, name) - _p(3,'isa = PBXNativeTarget;') - _p(3,'buildConfigurationList = %s /* Build configuration list for PBXNativeTarget "%s" */;', node.cfgsection, escapeSetting(name)) + _p(3,'isa = PBX%sTarget;', pbxTargetName) + _p(3,'buildConfigurationList = %s /* Build configuration list for PBX%sTarget "%s" */;', node.cfgsection, pbxTargetName, escapeSetting(name)) _p(3,'buildPhases = (') if hasBuildCommands('prebuildcommands') then _p(4,'9607AE1010C857E500CD1376 /* Prebuild */,') end - _p(4,'%s /* Resources */,', node.resstageid) - _p(4,'%s /* Sources */,', node.sourcesid) + if pbxTargetName == "Native" then + _p(4,'%s /* Resources */,', node.resstageid) + _p(4,'%s /* Sources */,', node.sourcesid) + end if hasBuildCommands('prelinkcommands') then _p(4,'9607AE3510C85E7E00CD1376 /* Prelink */,') end - _p(4,'%s /* Frameworks */,', node.fxstageid) + if pbxTargetName == "Native" then + _p(4,'%s /* Frameworks */,', node.fxstageid) + end if hasBuildCommands('postbuildcommands') then _p(4,'9607AE3710C85E8F00CD1376 /* Postbuild */,') end @@ -671,26 +707,40 @@ _p(3,'name = %s;', stringifySetting(name)) - local p - if node.cfg.kind == "ConsoleApp" then - p = "$(HOME)/bin" - elseif node.cfg.kind == "WindowedApp" then - p = "$(HOME)/Applications" - end - if p then - _p(3,'productInstallPath = %s;', stringifySetting(p)) + if pbxTargetName == "Native" then + local p + if node.cfg.kind == "ConsoleApp" then + p = "$(HOME)/bin" + elseif node.cfg.kind == "WindowedApp" then + p = "$(HOME)/Applications" + end + if p then + _p(3,'productInstallPath = %s;', stringifySetting(p)) + end end _p(3,'productName = %s;', stringifySetting(name)) - _p(3,'productReference = %s /* %s */;', node.id, node.name) - _p(3,'productType = %s;', stringifySetting(xcode.getproducttype(node))) + if pbxTargetName == "Native" then + _p(3,'productReference = %s /* %s */;', node.id, node.name) + _p(3,'productType = %s;', stringifySetting(xcode.getproducttype(node))) + end _p(2,'};') end - _p('/* End PBXNativeTarget section */') + _p('/* End PBX%sTarget section */', pbxTargetName) _p('') end + function xcode.PBXAggregateTarget(tr) + xcode_PBXAggregateOrNativeTarget(tr, "Aggregate") + end + + + function xcode.PBXNativeTarget(tr) + xcode_PBXAggregateOrNativeTarget(tr, "Native") + end + + function xcode.PBXProject(tr) _p('/* Begin PBXProject section */') _p(2,'08FB7793FE84155DC02AAC07 /* Project object */ = {') diff --git a/modules/xcode/xcode_project.lua b/modules/xcode/xcode_project.lua index 819b77231e..0681a88775 100644 --- a/modules/xcode/xcode_project.lua +++ b/modules/xcode/xcode_project.lua @@ -177,6 +177,7 @@ xcode.PBXFrameworksBuildPhase(tr) xcode.PBXGroup(tr) xcode.PBXNativeTarget(tr) + xcode.PBXAggregateTarget(tr) xcode.PBXProject(tr) xcode.PBXReferenceProxy(tr) xcode.PBXResourcesBuildPhase(tr)