def getIconFilenames(dir): # We want the processed Info.plist in the .app, not the one in the project. # Xcode consolidates asset catalog info into that plist, so it's a reliable # source for the names of icon files, regardless of how they got to be that way. packagedInfoPlist, _ = lib.loadPlist(os.path.join(dir, 'Info.plist')) iPhoneIcons = packagedInfoPlist.valueForKeyPath_('CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles') or [] iPadIcons = packagedInfoPlist.valueForKeyPath_('CFBundleIcons~ipad.CFBundlePrimaryIcon.CFBundleIconFiles') or [] allIconNames = set(itertools.chain(iPhoneIcons, iPadIcons)) resSuffixes = ['', '@2x', '@3x'] devSuffixes = ['', '~ipad'] fns = [os.path.join(dir, fn + res + dev + '.png') for fn in allIconNames for res in resSuffixes for dev in devSuffixes] return filter(os.path.exists, fns) if __name__ == '__main__': sourceDir = lib.getEnv('CODESIGNING_FOLDER_PATH') iconFns = getIconFilenames(sourceDir) for fn in iconFns: badgeFile(fn, sourceDir, lib.targetingStaging, lib.version, lib.buildNumber) print('Badged the following icon files: ' + ', '.join([os.path.basename(fn) for fn in iconFns]))
imp = warning imp += '#import "' + outputBasename + '.h"\n\n' imp += '\n\n'.join(lines[1]) headerFn = os.path.join(outputDir, outputBasename + '.h') impFn = os.path.join(outputDir, outputBasename + '.m') with open(headerFn, 'w') as f: f.write(header.encode('utf-8')) with open(impFn, 'w') as f: f.write(imp.encode('utf-8')) if __name__ == '__main__': outBasename = 'AssetCatalogIdentifiers' prefix = lib.classPrefix projectDir = os.path.join(lib.getEnv('SRCROOT'), lib.getEnv('PROJECT_NAME')) catalogDirs = list(lib.recursiveGlob(projectDir, '*.xcassets', includeDirs = True)) lines = ([], []) for catalogDir in catalogDirs: hString, mString = headerAndImpContentsForCatalog(catalogDir, prefix) if hString: lines[0].append(hString) lines[1].append(mString) outDir = os.path.join(projectDir, 'Other-Sources', 'Generated') assembleAndOutput(lines, outDir, outBasename) print 'Generated {}.h and .m for image assets in the following catalog(s): {}'.format(outBasename, ', '.join([os.path.basename(d) for d in catalogDirs]))
# Don't run in continuous integration or if we're not a build for release if lib.inContinuousIntegration or not lib.isDistributionOrAdHocBuildForDevice: print('Not removing localizations; this is an internal build') exit(0) # The project object has a knownRegions property that is an array of # locale strings (e.g. "Base", "en") that were set up in Xcode. knownRegions = lib.getProjectKeypath('knownRegions') if not knownRegions: lib.warn('The project is reporting that there are no known localizations in your project.\nPlease report this at {}'.format(lib.REPORT_URL)) exit(0) print('Keeping localizations for regions: ' + ', '.join(knownRegions)) regionsAndFoldersToDelete = [] lprojFolders = glob(os.path.join(lib.getEnv('CODESIGNING_FOLDER_PATH'), '*.lproj')) for lprojFolder in lprojFolders: region = lib.bareFilename(lprojFolder) if not region in knownRegions: regionsAndFoldersToDelete.append((region, lprojFolder)) if regionsAndFoldersToDelete: print('Removing extraneous localizations: ' + ', '.join([t[0] for t in regionsAndFoldersToDelete])) try: for _, folder in regionsAndFoldersToDelete: rmtree(folder) except Exception, e: lib.warn('Error deleting localization directories: {!s}\n\nPlease report this at {}'.format(e, lib.REPORT_URL))
exit(0) # The project object has a knownRegions property that is an array of # locale strings (e.g. "Base", "en") that were set up in Xcode. knownRegions = lib.getProjectKeypath("knownRegions") if not knownRegions: lib.warn( "The project is reporting that there are no known localizations in your project.\nPlease report this at {}".format( lib.REPORT_URL ) ) exit(0) print "Keeping localizations for regions: " + ", ".join(knownRegions) regionsAndFoldersToDelete = [] lprojFolders = glob(os.path.join(lib.getEnv("CODESIGNING_FOLDER_PATH"), "*.lproj")) for lprojFolder in lprojFolders: region = lib.bareFilename(lprojFolder) if not region in knownRegions: regionsAndFoldersToDelete.append((region, lprojFolder)) if regionsAndFoldersToDelete: print "Removing extraneous localizations: " + ", ".join([t[0] for t in regionsAndFoldersToDelete]) try: for _, folder in regionsAndFoldersToDelete: rmtree(folder) except Exception, e: lib.die("Error deleting localization directories: {!s}\n\nPlease report this at {}".format(e, lib.REPORT_URL))
packagedInfoPlist, _ = lib.loadPlist(os.path.join(dir, 'Info.plist')) iPhoneIcons = packagedInfoPlist.valueForKeyPath_( 'CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles') or [] iPadIcons = packagedInfoPlist.valueForKeyPath_( 'CFBundleIcons~ipad.CFBundlePrimaryIcon.CFBundleIconFiles') or [] allIconNames = set(itertools.chain(iPhoneIcons, iPadIcons)) resSuffixes = ['', '@2x', '@3x'] devSuffixes = ['', '~ipad'] fns = [ os.path.join(dir, fn + res + dev + '.png') for fn in allIconNames for res in resSuffixes for dev in devSuffixes ] return filter(os.path.exists, fns) if __name__ == '__main__': sourceDir = lib.getEnv('CODESIGNING_FOLDER_PATH') iconFns = getIconFilenames(sourceDir) for fn in iconFns: badgeFile(fn, sourceDir, lib.targetingStaging, lib.version, lib.buildNumber) print('Badged the following icon files: ' + ', '.join([os.path.basename(fn) for fn in iconFns]))
headerFn = os.path.join(outputDir, outputBasename + '.h') impFn = os.path.join(outputDir, outputBasename + '.m') with open(headerFn, 'w') as f: f.write(header.encode('utf-8')) with open(impFn, 'w') as f: f.write(imp.encode('utf-8')) if __name__ == '__main__': outBasename = 'AssetCatalogIdentifiers' prefix = lib.classPrefix projectDir = os.path.join(lib.getEnv('SRCROOT'), lib.getEnv('PROJECT_NAME')) catalogDirs = list( lib.recursiveGlob(projectDir, '*.xcassets', includeDirs=True)) lines = ([], []) for catalogDir in catalogDirs: hString, mString = headerAndImpContentsForCatalog(catalogDir, prefix) if hString: lines[0].append(hString) lines[1].append(mString) outDir = os.path.join(projectDir, 'Other-Sources', 'Generated') assembleAndOutput(lines, outDir, outBasename) print(