diff --git a/xcode_common.lua b/xcode_common.lua index 5159d5c..2adceb8 100644 --- a/xcode_common.lua +++ b/xcode_common.lua @@ -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 @@ -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, { @@ -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 @@ -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 = (') @@ -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 diff --git a/xcode_project.lua b/xcode_project.lua index e17ca57..d29bfa1 100644 --- a/xcode_project.lua +++ b/xcode_project.lua @@ -111,6 +111,7 @@ tree.insert(tr, tr.projects) end + local generated = {} -- Final setup tree.traverse(tr, { onnode = function(node) @@ -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 @@ -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 @@ -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)