def abspath(obj): """ complete the path for obj: (PBXBuildFile, BPXFileReference, PBXGroup, ...)""" path = None source_tree = obj.pbx_sourceTree if source_tree == pbxconsts.SOURCE_TREE.group: owner = func.get_list_item(obj.owners().values(), 0) path = owner.abspath() if not owner is None else None if not path is None and not obj.pbx_path is None: objpath = os.path.normpath(obj.pbx_path) path = os.path.join(path, objpath) elif source_tree == pbxconsts.SOURCE_TREE.absolute: path = normalize_path(obj.path) else: path_mapper = { pbxconsts.SOURCE_TREE.source_root: u'$(SOURCE_ROOT)', pbxconsts.SOURCE_TREE.sdkroot: u'$(SDKROOT)', pbxconsts.SOURCE_TREE.developer_dir: u'$(DEVELOPER_DIR)', pbxconsts.SOURCE_TREE.built_products_dir: u'$(BUILT_PRODUCTS_DIR)' } if source_tree in path_mapper: objpath = os.path.normpath( obj.pbx_path if not obj.pbx_path is None else '') path = os.path.join(path_mapper[source_tree], objpath) else: raise ValueError('{0} Unknown sourceTree: {1}'.format( obj, source_tree)) return path
def comment(self): """ override """ owner = func.get_list_item(self.owners().values(), 0) projname = owner.displayname().encode( 'utf-8') if not owner is None else None return u'Build configuration list for {isa} "{name}"'.format(\ isa=u'(null)' if owner is None else owner.isa, \ name=u'(null)' if projname is None else projname)
def buildsettings(self, name, target=None, config=None, default=None): """ get the project's common build settings, :param name: the name of build setting :param target: the 'PBXTarget' or 'guid' or 'target name', from which to get the build setting :param config: the 'XCBuildConfiguration' or 'guid' or 'config name' """ if name in [u'PROJECT_DIR', u'SRCROOT', u'SOURCE_ROOT']: return self.project_dir() elif name == u'PROJECT_NAME': return self.project_name() elif name == u'PROJECT_FILE_PATH': return self.__project_file_path else: def __get_setting(config, name, cfglist, default): cfg = config if cfg is None: cfg = cfglist.defaultConfiguration( ) if not cfglist is None else None elif pbxhelper.is_valid_guid(config): cfg = self.get_object(config) elif func.isstr(config): cfg = cfglist.getconfig( config) if not cfglist is None else None if not isinstance(cfg, config_imp.XCBuildConfiguration): return None return cfg.get_build_setting(name, default=default) # end of __get_setting() if not target is None: from xcodeproj.pbxproj.objects import target as target_imp from xcodeproj.pbxproj.objects import config as config_imp tobj = target if tobj is None: tobj = func.get_list_item(self.pbx_rootObject.pbx_targets, 0) elif pbxhelper.is_valid_guid(target): tobj = self.get_object(target) elif func.isstr(target): tobj = self.get_target(target) if not isinstance(tobj, target_imp.PBXTarget): return None return __get_setting(config, name, tobj.pbx_buildConfigurationList, default) elif not config is None: return __get_setting(config, name, None, default) if os.getenv(u'PROJECT_FILE_PATH') == self.__project_file_path: return os.getenv(name) return None
def defaultConfiguration(self): """ return build-configuration specified by defaultConfigurationName or return the first one in configuration list """ config = None if not self.pbx_defaultConfigurationName is None: config = self.getconfig(self.pbx_defaultConfigurationName) if config is None: config = func.get_list_item(self.pbx_buildConfigurations, 0) return config
def get_build_phase(self, isa, name=None, create=False): """ get build phase, create a new one if not exists """ def __cmp(phase): if phase.isa == isa: return True if name is None else phase.displayname() == name return False bp = func.get_list_item(func.take(lambda o:__cmp(o), self.pbx_buildPhases), 0) if bp is None and create: bp = self.create_build_phase(isa, name) return bp
def getconfig(self, name, auto_create=False): """ return config with name, otherwise return None """ if name is None: return None config = func.get_list_item(\ func.take(lambda c: c.pbx_name == name, self.pbx_buildConfigurations), 0) if config is None and auto_create: config = self.project().new_object(u'XCBuildConfiguration') config.pbx_name = name self.addconfig(config) return config
def comment(self): """ override """ refcomment = None parentcomment = None if not self.pbx_fileRef is None: refcomment = self.pbx_fileRef.comment() owner = func.get_list_item(self.owners().values(), 0) if not owner is None: parentcomment = owner.comment() comment = u'{ref} in {parent}'.format(\ ref=unicode(refcomment) if not refcomment is None else u'(null)', \ parent=unicode(parentcomment) if not parentcomment is None else u'(null)') return comment
def addgroup(self, abspath=None, sourcetree=pbxconsts.SOURCE_TREE.group, name=None, move=True): """ return the group object specified the 'abspath', not include the children :param abspath: the group's abspath in disk, if None, using the parent's path """ group_name = os.path.basename( abspath) if name is None or len(name) == 0 else name abspath = abspath if not abspath is None else self.realpath() subgroup = func.get_list_item(func.take(\ lambda o: o.isa == u'PBXGroup' and o.realpath() == abspath \ and o.displayname() == group_name, self.pbx_children), 0) if subgroup is None: subgroup = self.project().new_object(u'PBXGroup') pbxpath.set_path_with_source_tree(subgroup, abspath, source_tree=sourcetree, \ parent_group=self) if not name is None: subgroup.pbx_name = name self.addchild(subgroup, move=move) return subgroup
def get_variant_group(self, abspath, name): """ return the variant group in specified path and name """ return func.get_list_item(\ func.take(lambda o: o.realpath() == abspath and o.pbx_name == name, \ self.__objects.get(u'PBXVariantGroup', default=dict()).values()), 0)
def fileref_for_path(self, abspath): """ return the filereferece object with abspath in disk """ return func.get_list_item(\ func.take(lambda o: o.realpath() == abspath, \ self.__objects.get(u'PBXFileReference', default=dict()).values()), 0)
def gettarget(self, name): return func.get_list_item(func.take(lambda o:o.pbx_name == name, self.pbx_targets), 0)