Make target declaration unnecessary #1943

This commit is contained in:
Thomas Nagy 2017-04-09 11:28:25 +02:00
parent 26bd012695
commit d300a7ce0f
No known key found for this signature in database
GPG Key ID: 49B4C67C05277AAA
1 changed files with 134 additions and 112 deletions

View File

@ -470,84 +470,17 @@ class PBXProject(XCodeNode):
return t
return None
class xcode(Build.BuildContext):
cmd = 'xcode6'
fun = 'build'
@TaskGen.feature('c', 'cxx')
@TaskGen.after('process_uselib_vars', 'apply_incpaths')
def process_xcode(self):
if not hasattr(self, 'target_type'):
return
bld = self.bld
tg = self
file_refs = dict()
build_files = dict()
p = bld.project
products_group = bld.products_group
def as_nodes(self, files):
""" Returns a list of waflib.Nodes from a list of string of file paths """
nodes = []
for x in files:
if not isinstance(x, str):
d = x
else:
d = self.srcnode.find_node(x)
nodes.append(d)
return nodes
def create_group(self, name, files):
"""
Returns a new PBXGroup containing the files (paths) passed in the files arg
:type files: string
"""
group = PBXGroup(name)
"""
Do not use unique file reference here, since XCode seem to allow only one file reference
to be referenced by a group.
"""
files = [(PBXFileReference(d.name, d.abspath())) for d in self.as_nodes(files)]
group.add(files)
return group
def unique_filereference(self, fileref):
"""
Returns a unique fileref, possibly an existing one if the paths are the same.
Use this after you've constructed a PBXFileReference to make sure there is
only one PBXFileReference for the same file in the same project.
"""
if fileref not in self.file_refs:
self.file_refs[fileref] = fileref
return self.file_refs[fileref]
def unique_buildfile(self, buildfile):
"""
Returns a unique buildfile, possibly an existing one.
Use this after you've constructed a PBXBuildFile to make sure there is
only one PBXBuildFile for the same file in the same project.
"""
if buildfile not in self.build_files:
self.build_files[buildfile] = buildfile
return self.build_files[buildfile]
def execute(self):
"""
Entry point
"""
self.restore()
if not self.all_envs:
self.load_envs()
self.recurse([self.run_dir])
appname = getattr(Context.g_module, Context.APPNAME, os.path.basename(self.srcnode.abspath()))
p = PBXProject(appname, ('Xcode 3.2', 46), self.env)
# If we don't create a Products group, then
# XCode will create one, which entails that
# we'll start to see duplicate files in the UI
# for some reason.
products_group = PBXGroup('Products')
p.mainGroup.children.append(products_group)
for g in self.groups:
for tg in g:
if not isinstance(tg, TaskGen.task_gen):
continue
tg.post()
target_group = PBXGroup(tg.name)
p.mainGroup.children.append(target_group)
@ -571,18 +504,18 @@ class xcode(Build.BuildContext):
sources = []
if hasattr(tg, 'source_files') and isinstance(tg.source_files, dict):
for grpname,files in tg.source_files.items():
group = self.create_group(grpname, files)
group = bld.create_group(grpname, files)
target_group.children.append(group)
sources.extend(group.children)
else:
src = getattr(tg, 'source_files', []) or tg.source
group = self.create_group("Source", src)
group = bld.create_group("Source", src)
target_group.children.append(group)
sources.extend(group.children)
# FIXME too complex
sources = list(filter(lambda fileref: os.path.splitext(fileref.path)[1] in XCODE_EXTS, sources))
buildfiles = [self.unique_buildfile(PBXBuildFile(fileref)) for fileref in sources]
buildfiles = [bld.unique_buildfile(PBXBuildFile(fileref)) for fileref in sources]
target.add_build_phase(PBXSourcesBuildPhase(buildfiles))
# Create build settings which can override the project settings. Defaults to none if user
@ -604,8 +537,8 @@ class xcode(Build.BuildContext):
# If 'export_headers' is present, add files to the Headers build phase in xcode.
# These are files that'll get packed into the Framework for instance.
exp_hdrs = getattr(tg, 'export_headers', [])
hdrs = self.as_nodes(Utils.to_list(exp_hdrs))
files = [self.unique_filereference(PBXFileReference(n.name, n.abspath())) for n in hdrs]
hdrs = bld.as_nodes(Utils.to_list(exp_hdrs))
files = [bld.unique_filereference(PBXFileReference(n.name, n.abspath())) for n in hdrs]
target.add_build_phase(PBXHeadersBuildPhase([PBXBuildFile(f, {'ATTRIBUTES': ('Public',)}) for f in files]))
# Merge frameworks and libs into one list, and prefix the frameworks
@ -633,7 +566,7 @@ class xcode(Build.BuildContext):
# The keys represents different build configuration, e.g. Debug, Release and so on..
# Insert our generated build settings to all configuration names
keys = set(settings.keys() + self.env.PROJ_CONFIGURATION.keys())
keys = set(settings.keys() + bld.env.PROJ_CONFIGURATION.keys())
for k in keys:
if k in settings:
settings[k].update(bldsettings)
@ -645,6 +578,95 @@ class xcode(Build.BuildContext):
p.add_target(target)
class xcode(Build.BuildContext):
cmd = 'xcode6'
fun = 'build'
def as_nodes(self, files):
""" Returns a list of waflib.Nodes from a list of string of file paths """
nodes = []
for x in files:
if not isinstance(x, str):
d = x
else:
d = self.srcnode.find_node(x)
nodes.append(d)
return nodes
def create_group(self, name, files):
"""
Returns a new PBXGroup containing the files (paths) passed in the files arg
:type files: string
"""
group = PBXGroup(name)
"""
Do not use unique file reference here, since XCode seem to allow only one file reference
to be referenced by a group.
"""
files = [(PBXFileReference(d.name, d.abspath())) for d in self.as_nodes(files)]
group.add(files)
return group
def unique_filereference(self, ref):
"""
Returns a unique file reference, possibly an existing one if the paths are the same.
Use this after you've constructed a PBXFileReference to make sure there is
only one PBXFileReference for the same file in the same project.
"""
try:
file_refs = self.file_refs
except AttributeError:
file_refs = self.file_refs = {}
if ref not in file_refs:
file_refs[ref] = ref
return file_refs[ref]
def unique_buildfile(self, buildfile):
"""
Returns a unique buildfile, possibly an existing one.
Use this after you've constructed a PBXBuildFile to make sure there is
only one PBXBuildFile for the same file in the same project.
"""
try:
build_files = self.build_files
except AttributeError:
build_files = self.build_files = {}
if buildfile not in build_files:
build_files[buildfile] = buildfile
return build_files[buildfile]
def execute(self):
"""
Entry point
"""
self.restore()
if not self.all_envs:
self.load_envs()
self.recurse([self.run_dir])
appname = getattr(Context.g_module, Context.APPNAME, os.path.basename(self.srcnode.abspath()))
p = PBXProject(appname, ('Xcode 3.2', 46), self.env)
# If we don't create a Products group, then
# XCode will create one, which entails that
# we'll start to see duplicate files in the UI
# for some reason.
products_group = PBXGroup('Products')
p.mainGroup.children.append(products_group)
self.project = p
self.products_group = products_group
# post all task generators
# the process_xcode method above will be called for each target
self.cur = 0
while self.cur < len(self.groups):
self.post_group()
self.cur += 1
node = self.bldnode.make_node('%s.xcodeproj' % appname)
node.mkdir()
node = node.make_node('project.pbxproj')