Skip to content
This repository was archived by the owner on Jun 2, 2019. It is now read-only.

support custom build commands #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 68 additions & 1 deletion xcode_common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
if node.isResource then
return "Resources"
end
if node.ruleid then
return "Sources"
end
return categories[path.getextension(node.name)]
end

Expand Down Expand Up @@ -364,6 +367,57 @@
-- in the .pbxproj file
---------------------------------------------------------------------------

function xcode.PBXBuildRule( tr )
local settings = {};
tree.traverse(tr, {
onnode = function(node)
if node.ruleid then

settings[node.ruleid] = function(level)
_p(level,'%s /* PBXBuildRule */ = {',node.ruleid)
_p(level+1,'isa = PBXBuildRule;')
_p(level+1,'name = %s ;',stringifySetting('build ' .. node.name))
_p(level+1,'compilerSpec = com.apple.compilers.proxy.script;')
_p(level+1,'filePatterns = %s ;',path.getabsolute(node.path))
_p(level+1,'fileType = pattern.proxy;')
_p(level+1,'isEditable = 1;')
local commands = {}
local outputs = {}
for cfg in project.eachconfig(tr.project) do
local filecfg = fileconfig.getconfig(node, cfg)
if filecfg then
table.insert(commands, 'if [ "${CONFIGURATION}" = "' .. cfg.buildcfg .. '" ]; then')
table.insert(commands, string.format('\techo "%s"', filecfg.buildmessage or ("Building " .. filecfg.relpath)))
local cmds = os.translateCommands(filecfg.buildcommands)
for _, cmd in ipairs(cmds) do
table.insert(commands,'\t' .. cmd)
end
table.insert(commands,'fi')
for _,v in ipairs(filecfg.buildoutputs) do
outputs[v] = true
end
end
end
_p(level+1,'script = %s ;', stringifySetting(table.concat(commands, '\n')))
_p(level+1,'outputFiles = (')
for v,_ in pairs(outputs) do
_p(level+2,' "%s", ',stringifySetting(v))
end
_p(level+1,');')
_p(level,'};')
end
end
end
})

if not table.isempty(settings) then
_p('/* Begin PBXBuildRule section */')
printSettingsTable(2, settings);
_p('/* End PBXBuildRule section */')
_p('')
end
end

function xcode.PBXBuildFile(tr)
local settings = {};
tree.traverse(tr, {
Expand Down Expand Up @@ -600,6 +654,16 @@


function xcode.PBXNativeTarget(tr)

local buildRules = {}
tree.traverse(tr, {
onnode = function(node)
if node.ruleid then
buildRules[node.ruleid] = node
end
end
})

_p('/* Begin PBXNativeTarget section */')
for _, node in ipairs(tr.products.children) do
local name = tr.project.name
Expand Down Expand Up @@ -639,6 +703,9 @@
end
_p(3,');')
_p(3,'buildRules = (')
for ruleid, node in pairs(buildRules) do
_p(4,'%s /* PBXBuildRule */,',ruleid)
end
_p(3,');')

_p(3,'dependencies = (')
Expand Down Expand Up @@ -812,7 +879,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
Expand Down
32 changes: 31 additions & 1 deletion xcode_project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
tree.insert(tr, tr.projects)
end

local generated = {}
-- Final setup
tree.traverse(tr, {
onnode = function(node)
Expand All @@ -119,7 +120,24 @@

node.isResource = xcode.isItemResource(prj, node)

-- assign build IDs to buildable files

-- check to see if this file has custom rules
if node.configs then

for cfg in project.eachconfig(prj) do
local filecfg = fileconfig.getconfig(node, cfg)
if fileconfig.hasCustomBuildRule(filecfg) then
if not node.ruleid then
node.ruleid = xcode.newid(node.name, "rule", node.path)
end
for _,v in ipairs(filecfg.buildoutputs) do
generated[path.getabsolute(v)] = true
end
end
end
end

-- assign build IDs to buildable files
if xcode.getbuildcategory(node) then
node.buildid = xcode.newid(node.name, "build", node.path)
end
Expand All @@ -131,6 +149,17 @@
end
}, true)

-- remove from build generated files
if not table.isempty(generated) then
tree.traverse(tr, {
onnode = function(node)
if node.buildid and generated[path.getabsolute(node.path)] then
node.buildid = nil
end
end
},true)
end

-- Plug in the product node into the Products folder in the tree. The node
-- was built in xcode.prepareWorkspace() in xcode_common.lua; it contains IDs
-- that are necessary for inter-project dependencies
Expand Down Expand Up @@ -159,6 +188,7 @@
function m.generateProject(prj)
local tr = xcode.buildprjtree(prj)
p.callArray(m.elements.project, prj)
xcode.PBXBuildRule(tr)
xcode.PBXBuildFile(tr)
xcode.PBXContainerItemProxy(tr)
xcode.PBXFileReference(tr)
Expand Down