def _validate(self): resolved, issues = super(PBXGroup, self)._validate() self._validate_children(resolved, issues) if self.pbx_sourceTree is None: issues.append(u'{0} invalid sourceTree: {1}'.format( self, self.pbx_sourceTree)) elif not self == self.project().pbx_rootObject.pbx_mainGroup \ and not func.isstr(self.pbx_name) and not func.isstr(self.pbx_path): issues.append(u'{0} invalid name / path.'.format(self)) return resolved, issues
def _validate(self): resolved, issues = super(PBXFileReference, self)._validate() if self.pbx_sourceTree is None: issues.append(u'{0} invalid sourceTree: {1}'.format( self, self.pbx_sourceTree)) elif not func.isstr(self.pbx_name) and not func.isstr(self.pbx_path): issues.append(u'{0} invalid name / path.'.format(self)) elif not func.isstr(self.pbx_explicitFileType) and not func.isstr( self.pbx_lastKnownFileType): issues.append( u'{0} invalid explicitFileType / lastKnownFileType.'.format( self)) return resolved, issues
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 __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)
def __parse_dict_attr_val(self, dic, pbxkey): for k, v in dic.items(): depkey = u'{0}.{1}'.format(pbxkey, k) if func.isstr(v) and pbxhelper.is_valid_guid(v): obj = self.project().get_object(v) if not obj is None: obj.add_referrer(self, depkey) dic[k] = obj else: dic[k] = v elif func.isseq(v): dic[k] = self.__parse_arr_attr_val(v, depkey) elif func.isdict(v): self.__parse_dict_attr_val(v, depkey)
def remove_referrer(self, obj): """ mark up that 'obj' no longer referred to self """ if isinstance(obj, abstract.PBXAbstract): self.__referrers.pop(obj.guid, None) obj.__remove_dependency_attr(self) elif func.isstr(obj): guid = unicode(obj) self.__referrers.pop(guid, None) obj = self.__xcproj.get_object(obj) if not obj is None: obj.__remove_dependency_attr(self) if len(self.__referrers) == 0: self.__xcproj.remove_object(self) self.__owners = None # need to re-caculate owners
def add_referrer(self, obj, keypath): """ mark up that 'obj' referred to self """ refer = None if isinstance(obj, abstract.PBXAbstract): self.__xcproj.add_object(obj) refer = obj elif func.isstr(obj): refer = self.__xcproj.get_object(obj) if refer is None: raise ValueError( u'[XcodeProj] object not found:{0}'.format(obj)) if not refer is None: self.__referrers[refer.guid] = refer refer.__add_dependency_attr(self, keypath) self.__owners = None # need to re-caculate owners
def __parse_arr_attr_val(self, arr, pbxkey): newarr = [] for val in arr: if func.isstr(val) and pbxhelper.is_valid_guid(val): obj = self.project().get_object(val) if not obj is None: obj.add_referrer(self, pbxkey) newarr.append(obj) else: newarr.append(val) # error? elif func.isseq(val): newarr.append(self.__parse_arr_attr_val(val, pbxkey)) elif func.isdict(val): self.__parse_dict_attr_val(val, pbxkey) newarr.append(val) else: newarr.append(val) return newarr
def deduplicate_paths(self, paths): """ return deduplicate paths complete and normalize the paths, deduplicate the result """ if func.isstr(paths): return paths if not func.isseq(paths): return u'' path_dict = dict() for path in paths: normpath = path while func.hasprefix(normpath, '"') and func.hassubfix( normpath, '"'): normpath = normpath[1:len(normpath) - 1] normpath = pbxpath.normalize_path(normpath) realpath = pbxpath.realpath(self.project(), normpath) if realpath in path_dict: continue if not func.hassubfix(realpath, os.sep + '**'): p = os.path.join(realpath, '**') if p in path_dict: continue else: p = realpath[0:len(realpath) - len(os.sep + '**')] path_dict.pop(p, None) path_dict[realpath] = (path, normpath) return [ p[1] for p in sorted(path_dict.values(), key=lambda p: paths.index(p[0])) ]