Skip to content

Commit

Permalink
Merge pull request #1145 from tempura-sukiyaki/xcode4-kind-utility
Browse files Browse the repository at this point in the history
Add support `kind:Utility` in xcode4
  • Loading branch information
samsinsane committed Aug 10, 2018
2 parents 11e1126 + fd49222 commit b64a7cc
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 20 deletions.
2 changes: 1 addition & 1 deletion modules/xcode/_preload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
56 changes: 56 additions & 0 deletions modules/xcode/tests/test_xcode_project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------------------------------------------------------------
Expand Down
88 changes: 69 additions & 19 deletions modules/xcode/xcode_common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,');')

Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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 */ = {')
Expand Down
1 change: 1 addition & 0 deletions modules/xcode/xcode_project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b64a7cc

Please sign in to comment.