def createBuild(baseDir, type, outFile=None, buildNum=None, releaseBuild=False, keyFile=None): metadata = readMetadata(baseDir, type) version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) if not outFile: outFile = getDefaultFileName(baseDir, metadata, version, 'safariextz' if keyFile else 'zip') params = { 'type': type, 'baseDir': baseDir, 'releaseBuild': releaseBuild, 'version': version, 'devenv': False, 'metadata': metadata, } requiredAssets = () requiredAssetsPath = None if metadata.has_section('buildConfig'): requiredAssets = re.split(r'\s+', metadata.get('buildConfig', 'requiredAssets')) requiredAssetsPath = metadata.get('buildConfig', 'requiredAssetsPath') files = Files(getPackageFiles(params), getIgnoredFiles(params), requiredAssets=requiredAssets, requiredAssetsPath=requiredAssetsPath, process=lambda path, data: processFile(path, data, params)) if metadata.has_section('mapping'): files.readMappedFiles(metadata.items('mapping')) files.read(baseDir) if metadata.has_section('convert_js'): convertJS(params, files) if metadata.has_section('convert_img'): from imageConversion import convertImages convertImages(params, files) if metadata.has_section('preprocess'): files.preprocess( [f for f, _ in metadata.items('preprocess')], {'needsExt': True} ) if metadata.has_section('import_locales'): importGeckoLocales(params, files) files['lib/info.js'] = createInfoModule(params) files['background.html'] = createBackgroundPage(params) files['Info.plist'] = createManifest(params, files) fixAbsoluteUrls(files) dirname = metadata.get('general', 'basename') + '.safariextension' for filename in files.keys(): files[os.path.join(dirname, filename)] = files.pop(filename) if keyFile: createSignedXarArchive(outFile, files, keyFile) else: files.zip(outFile)
def createBuild(baseDir, type='chrome', outFile=None, buildNum=None, releaseBuild=False, keyFile=None, devenv=False): metadata = readMetadata(baseDir, type) version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) if outFile == None: file_extension = get_extension(type, keyFile is not None) outFile = getDefaultFileName(metadata, version, file_extension) params = { 'type': type, 'baseDir': baseDir, 'releaseBuild': releaseBuild, 'version': version, 'devenv': devenv, 'metadata': metadata, } mapped = metadata.items('mapping') if metadata.has_section( 'mapping') else [] files = Files(getPackageFiles(params), getIgnoredFiles(params), process=lambda path, data: processFile(path, data, params)) files.readMappedFiles(mapped) files.read(baseDir, skip=[opt for opt, _ in mapped]) if metadata.has_section('bundles'): bundle_tests = devenv and metadata.has_option('general', 'testScripts') create_bundles(params, files, bundle_tests) if metadata.has_section('preprocess'): files.preprocess( [f for f, _ in metadata.items('preprocess')], {'needsExt': True}, ) if metadata.has_section('import_locales'): import_locales(params, files) files['manifest.json'] = createManifest(params, files) if type == 'chrome': fix_translations_for_chrome(files) if devenv: add_devenv_requirements(files, metadata, params) zipdata = files.zipToString() signature = None pubkey = None if keyFile != None: signature = signBinary(zipdata, keyFile) pubkey = getPublicKey(keyFile) writePackage(outFile, pubkey, signature, zipdata)
def createBuild(baseDir, type='edge', outFile=None, # noqa: preserve API. buildNum=None, releaseBuild=False, keyFile=None, devenv=False): metadata = packager.readMetadata(baseDir, type) version = packager.getBuildVersion(baseDir, metadata, releaseBuild, buildNum) outfile = outFile or packager.getDefaultFileName(metadata, version, 'appx') params = { 'type': type, 'baseDir': baseDir, 'releaseBuild': releaseBuild, 'version': version, 'devenv': devenv, 'metadata': metadata, } files = packager.Files(packagerChrome.getPackageFiles(params), packagerChrome.getIgnoredFiles(params)) if metadata.has_section('mapping'): mapped = metadata.items('mapping') files.readMappedFiles(mapped) files.read(baseDir, skip=[filename for filename, _ in mapped]) else: files.read(baseDir) if metadata.has_section('bundles'): bundle_tests = devenv and metadata.has_option('general', 'testScripts') packagerChrome.create_bundles(params, files, bundle_tests) if metadata.has_section('preprocess'): files.preprocess(metadata.options('preprocess'), {'needsExt': True}) if metadata.has_section('import_locales'): packagerChrome.import_locales(params, files) files['manifest.json'] = packagerChrome.createManifest(params, files) if devenv: packagerChrome.add_devenv_requirements(files, metadata, params) move_files_to_extension(files) if metadata.has_section('appx_assets'): for name, path in metadata.items('appx_assets'): path = os.path.join(baseDir, path) files.read(path, '{}/{}'.format(ASSETS_DIR, name)) files[MANIFEST] = create_appx_manifest(params, files, buildNum, releaseBuild) files[BLOCKMAP] = create_appx_blockmap(files) files[CONTENT_TYPES] = create_content_types_map(files.keys() + [BLOCKMAP]) files.zip(outfile, compression=zipfile.ZIP_STORED)
def createBuild(baseDir, type, outFile=None, buildNum=None, releaseBuild=False, keyFile=None, devenv=False): metadata = readMetadata(baseDir, type) version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) if not outFile: outFile = getDefaultFileName(metadata, version, 'safariextz' if keyFile else 'zip') params = { 'type': type, 'baseDir': baseDir, 'releaseBuild': releaseBuild, 'version': version, 'devenv': devenv, 'metadata': metadata, } mapped = metadata.items('mapping') if metadata.has_section('mapping') else [] files = Files(getPackageFiles(params), getIgnoredFiles(params), process=lambda path, data: processFile(path, data, params)) files.readMappedFiles(mapped) files.read(baseDir, skip=[opt for opt, _ in mapped]) if metadata.has_section('convert_js'): convertJS(params, files) if metadata.has_section('preprocess'): files.preprocess( [f for f, _ in metadata.items('preprocess')], {'needsExt': True} ) if metadata.has_section('import_locales'): importGeckoLocales(params, files) if metadata.has_option('general', 'testScripts'): files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmpl', ('general', 'testScripts')) if keyFile: certs, key = get_certificates_and_key(keyFile) params['developerIdentifier'] = get_developer_identifier(certs) files['lib/info.js'] = createInfoModule(params) files['background.html'] = createScriptPage(params, 'background.html.tmpl', ('general', 'backgroundScripts')) files['Info.plist'] = createManifest(params, files) fixAbsoluteUrls(files) dirname = metadata.get('general', 'basename') + '.safariextension' for filename in files.keys(): files[os.path.join(dirname, filename)] = files.pop(filename) if not devenv and keyFile: createSignedXarArchive(outFile, files, certs, key) else: files.zip(outFile)
def createBuild(baseDir, type, outFile=None, buildNum=None, releaseBuild=False, keyFile=None, devenv=False): metadata = readMetadata(baseDir, type) version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) if not outFile: outFile = getDefaultFileName(metadata, version, "safariextz" if keyFile else "zip") params = { "type": type, "baseDir": baseDir, "releaseBuild": releaseBuild, "version": version, "devenv": devenv, "metadata": metadata, } mapped = metadata.items("mapping") if metadata.has_section("mapping") else [] files = Files( getPackageFiles(params), getIgnoredFiles(params), process=lambda path, data: processFile(path, data, params) ) files.readMappedFiles(mapped) files.read(baseDir, skip=[opt for opt, _ in mapped]) if metadata.has_section("convert_js"): convertJS(params, files) if metadata.has_section("preprocess"): files.preprocess([f for f, _ in metadata.items("preprocess")], {"needsExt": True}) if metadata.has_section("import_locales"): importGeckoLocales(params, files) if metadata.has_option("general", "testScripts"): files["qunit/index.html"] = createScriptPage(params, "testIndex.html.tmpl", ("general", "testScripts")) if keyFile: from buildtools import xarfile certs, key = xarfile.read_certificates_and_key(keyFile) params["developerIdentifier"] = get_developer_identifier(certs) files["lib/info.js"] = createInfoModule(params) files["background.html"] = createScriptPage(params, "background.html.tmpl", ("general", "backgroundScripts")) files["Info.plist"] = createManifest(params, files) fixAbsoluteUrls(files) dirname = metadata.get("general", "basename") + ".safariextension" for filename in files.keys(): files[os.path.join(dirname, filename)] = files.pop(filename) if not devenv and keyFile: from buildtools import xarfile xarfile.create(outFile, files, keyFile) else: files.zip(outFile)
def createBuild(baseDir, type, outFile=None, buildNum=None, releaseBuild=False, keyFile=None): metadata = readMetadata(baseDir, type) version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) if not outFile: outFile = getDefaultFileName(baseDir, metadata, version, 'safariextz' if keyFile else 'zip') params = { 'type': type, 'baseDir': baseDir, 'releaseBuild': releaseBuild, 'version': version, 'devenv': False, 'metadata': metadata, } files = Files(getPackageFiles(params), getIgnoredFiles(params), process=lambda path, data: processFile(path, data, params)) if metadata.has_section('mapping'): files.readMappedFiles(metadata.items('mapping')) files.read(baseDir) if metadata.has_section('convert_js'): convertJS(params, files) if metadata.has_section('convert_img'): from imageConversion import convertImages convertImages(params, files) if metadata.has_section('preprocess'): files.preprocess([f for f, _ in metadata.items('preprocess')], {'needsExt': True}) if metadata.has_section('import_locales'): importGeckoLocales(params, files) files['lib/info.js'] = createInfoModule(params) files['background.html'] = createBackgroundPage(params) files['Info.plist'] = createManifest(params, files) fixAbsoluteUrls(files) dirname = metadata.get('general', 'basename') + '.safariextension' for filename in files.keys(): files[os.path.join(dirname, filename)] = files.pop(filename) if keyFile: createSignedXarArchive(outFile, files, keyFile) else: files.zip(outFile)
def createBuild(baseDir, type='chrome', outFile=None, buildNum=None, releaseBuild=False, keyFile=None, experimentalAPI=False, devenv=False): metadata = readMetadata(baseDir, type) version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) if outFile == None: outFile = getDefaultFileName(baseDir, metadata, version, 'crx' if keyFile else 'zip') params = { 'type': type, 'baseDir': baseDir, 'releaseBuild': releaseBuild, 'version': version, 'experimentalAPI': experimentalAPI, 'devenv': devenv, 'metadata': metadata, } files = Files(getPackageFiles(params), getIgnoredFiles(params), process=lambda path, data: processFile(path, data, params)) files['manifest.json'] = createManifest(params) if metadata.has_section('mapping'): files.readMappedFiles(metadata.items('mapping')) files.read(baseDir) if metadata.has_section('convert_js'): convertJS(params, files) if metadata.has_section('convert_img'): from imageConversion import convertImages convertImages(params, files) if metadata.has_section('preprocess'): files.preprocess( [f for f, _ in metadata.items('preprocess')], {'needsExt': True} ) if metadata.has_section('import_locales'): importGeckoLocales(params, files) if devenv: files['devenvPoller__.js'] = createPoller(params) if (metadata.has_option('general', 'backgroundScripts') and 'lib/info.js' in re.split(r'\s+', metadata.get('general', 'backgroundScripts')) and 'lib/info.js' not in files): files['lib/info.js'] = createInfoModule(params) zipdata = files.zipToString() signature = None pubkey = None if keyFile != None: signature = signBinary(zipdata, keyFile) pubkey = getPublicKey(keyFile) writePackage(outFile, pubkey, signature, zipdata)
def createBuild(baseDir, type='gecko', outFile=None, locales=None, buildNum=None, releaseBuild=False, keyFile=None, multicompartment=False): if locales == None: locales = getLocales(baseDir) elif locales == 'all': locales = getLocales(baseDir, True) metadata = readMetadata(baseDir, type) version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) if outFile == None: outFile = getDefaultFileName(metadata, version, 'xpi') contributors = getContributors(metadata) params = { 'baseDir': baseDir, 'locales': locales, 'releaseBuild': releaseBuild, 'version': version.encode('utf-8'), 'metadata': metadata, 'contributors': contributors, 'multicompartment': multicompartment, 'jsonRequires': {}, } mapped = metadata.items('mapping') if metadata.has_section( 'mapping') else [] skip = [opt for opt, _ in mapped] + ['chrome'] files = Files(getPackageFiles(params), getIgnoredFiles(params), process=lambda path, data: processFile(path, data, params)) files['install.rdf'] = createManifest(params) files.readMappedFiles(mapped) files.read(baseDir, skip=skip) for name, path in getChromeSubdirs(baseDir, params['locales']).iteritems(): if os.path.isdir(path): files.read(path, 'chrome/%s' % name, skip=skip) importLocales(params, files) fixupLocales(params, files) processJSONFiles(params, files) if not 'bootstrap.js' in files: addMissingFiles(params, files) if metadata.has_section('preprocess'): files.preprocess([f for f, _ in metadata.items('preprocess')]) if keyFile: signFiles(files, keyFile) files.zip(outFile, sortKey=lambda x: '!' if x == 'META-INF/zigbert.rsa' else x)
def createBuild(baseDir, type='edge', outFile=None, # noqa: preserve API. buildNum=None, releaseBuild=False, keyFile=None, devenv=False): metadata = packager.readMetadata(baseDir, type) version = packager.getBuildVersion(baseDir, metadata, releaseBuild, buildNum) outfile = outFile or packager.getDefaultFileName(metadata, version, 'appx') params = { 'type': type, 'baseDir': baseDir, 'releaseBuild': releaseBuild, 'version': version, 'devenv': devenv, 'metadata': metadata, } files = packager.Files(packagerChrome.getPackageFiles(params), packagerChrome.getIgnoredFiles(params)) if metadata.has_section('mapping'): mapped = metadata.items('mapping') files.readMappedFiles(mapped) files.read(baseDir, skip=[filename for filename, _ in mapped]) else: files.read(baseDir) if metadata.has_section('convert_js'): packagerChrome.convertJS(params, files) if metadata.has_section('preprocess'): files.preprocess(metadata.options('preprocess'), {'needsExt': True}) if metadata.has_section('import_locales'): packagerChrome.importGeckoLocales(params, files) files['manifest.json'] = packagerChrome.createManifest(params, files) move_files_to_extension(files) if metadata.has_section('appx_assets'): for name, path in metadata.items('appx_assets'): path = os.path.join(baseDir, path) files.read(path, '{}/{}'.format(ASSETS_DIR, name)) files[MANIFEST] = create_appx_manifest(params, files, releaseBuild) files[BLOCKMAP] = create_appx_blockmap(files) files[CONTENT_TYPES] = create_content_types_map(files.keys() + [BLOCKMAP]) files.zip(outfile, compression=zipfile.ZIP_STORED)
def createBuild(baseDir, type='chrome', outFile=None, buildNum=None, releaseBuild=False, keyFile=None, devenv=False): metadata = readMetadata(baseDir, type) version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) if outFile == None: file_extension = get_extension(type, keyFile is not None) outFile = getDefaultFileName(metadata, version, file_extension) params = { 'type': type, 'baseDir': baseDir, 'releaseBuild': releaseBuild, 'version': version, 'devenv': devenv, 'metadata': metadata, } mapped = metadata.items('mapping') if metadata.has_section('mapping') else [] files = Files(getPackageFiles(params), getIgnoredFiles(params), process=lambda path, data: processFile(path, data, params)) files.readMappedFiles(mapped) files.read(baseDir, skip=[opt for opt, _ in mapped]) if metadata.has_section('bundles'): bundle_tests = devenv and metadata.has_option('general', 'testScripts') create_bundles(params, files, bundle_tests) if metadata.has_section('preprocess'): files.preprocess( [f for f, _ in metadata.items('preprocess')], {'needsExt': True}, ) if metadata.has_section('import_locales'): import_locales(params, files) files['manifest.json'] = createManifest(params, files) if type == 'chrome': fix_translations_for_chrome(files) if devenv: add_devenv_requirements(files, metadata, params) zipdata = files.zipToString() signature = None pubkey = None if keyFile != None: signature = signBinary(zipdata, keyFile) pubkey = getPublicKey(keyFile) writePackage(outFile, pubkey, signature, zipdata)
def createBuild(baseDir, type="gecko", outFile=None, locales=None, buildNum=None, releaseBuild=False, keyFile=None, multicompartment=False): if locales == None: locales = getLocales(baseDir) elif locales == 'all': locales = getLocales(baseDir, True) metadata = readMetadata(baseDir, type) version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) if outFile == None: outFile = getDefaultFileName(metadata, version, 'xpi') contributors = getContributors(metadata) params = { 'baseDir': baseDir, 'locales': locales, 'releaseBuild': releaseBuild, 'version': version.encode('utf-8'), 'metadata': metadata, 'contributors': contributors, 'multicompartment': multicompartment, 'jsonRequires': {}, } mapped = metadata.items('mapping') if metadata.has_section('mapping') else [] skip = [opt for opt, _ in mapped] + ['chrome'] files = Files(getPackageFiles(params), getIgnoredFiles(params), process=lambda path, data: processFile(path, data, params)) files['install.rdf'] = createManifest(params) files.readMappedFiles(mapped) files.read(baseDir, skip=skip) for name, path in getChromeSubdirs(baseDir, params['locales']).iteritems(): if os.path.isdir(path): files.read(path, 'chrome/%s' % name, skip=skip) importLocales(params, files) fixupLocales(params, files) processJSONFiles(params, files) if not 'bootstrap.js' in files: addMissingFiles(params, files) if metadata.has_section('preprocess'): files.preprocess([f for f, _ in metadata.items('preprocess')]) if keyFile: signFiles(files, keyFile) files.zip(outFile, sortKey=lambda x: '!' if x == 'META-INF/zigbert.rsa' else x)
def create_build(platform, base_dir, target_path, version, key_file=None): """Create a build for the target platform and version.""" if platform == 'edge': import buildtools.packagerEdge as packager else: import buildtools.packagerChrome as packager metadata = readMetadata(base_dir, platform) update_metadata(metadata, version) build_path = os.path.join( target_path, getDefaultFileName(metadata, version, get_extension(platform, key_file is not None)), ) packager.createBuild(base_dir, type=platform, outFile=build_path, releaseBuild=True, keyFile=key_file) return build_path
def createBuild(baseDir, type='chrome', outFile=None, buildNum=None, releaseBuild=False, keyFile=None, experimentalAPI=False, devenv=False): metadata = readMetadata(baseDir, type) version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) if outFile == None: outFile = getDefaultFileName(baseDir, metadata, version, 'crx' if keyFile else 'zip') params = { 'type': type, 'baseDir': baseDir, 'releaseBuild': releaseBuild, 'version': version, 'experimentalAPI': experimentalAPI, 'devenv': devenv, 'metadata': metadata, } files = Files(getPackageFiles(params), getIgnoredFiles(params), process=lambda path, data: processFile(path, data, params)) files['manifest.json'] = createManifest(params) if metadata.has_section('mapping'): files.readMappedFiles(metadata.items('mapping')) files.read(baseDir) if metadata.has_section('convert_js'): convertJS(params, files) if metadata.has_section('import_locales'): importGeckoLocales(params, files) if devenv: files['devenvPoller__.js'] = createPoller(params) zipdata = files.zipToString() signature = None pubkey = None if keyFile != None: signature = signBinary(zipdata, keyFile) pubkey = getPublicKey(keyFile) writePackage(outFile, pubkey, signature, zipdata)
def create_build(platform, base_dir, target_path, version, key_file=None): """Create a build for the target platform and version.""" if platform == 'edge': import buildtools.packagerEdge as packager else: import buildtools.packagerChrome as packager metadata = readMetadata(base_dir, platform) update_metadata(metadata, version) build_path = os.path.join( target_path, getDefaultFileName(metadata, version, get_extension(platform, key_file is not None)), ) packager.createBuild(base_dir, type=platform, outFile=build_path, releaseBuild=True, keyFile=key_file) return build_path
def run(baseDir, type, version, keyFile, downloadsRepo): if type == 'gecko': import buildtools.packagerGecko as packager elif type == 'safari': import buildtools.packagerSafari as packager elif type == 'edge': import buildtools.packagerEdge as packager elif type == 'chrome': import buildtools.packagerChrome as packager # Replace version number in metadata file "manually", ConfigParser will mess # up the order of lines. metadata = readMetadata(baseDir, type) with open(metadata.option_source('general', 'version'), 'r+b') as file: rawMetadata = file.read() rawMetadata = re.sub(r'^(\s*version\s*=\s*).*', r'\g<1>%s' % version, rawMetadata, flags=re.I | re.M) file.seek(0) file.write(rawMetadata) file.truncate() # Read extension name from locale data import buildtools.packagerGecko as packagerGecko if type == 'gecko': locales_base = baseDir else: # This is somewhat of a hack but reading out locale import config here would be too much locales_base = os.path.join(baseDir, 'adblockplus') locales = packagerGecko.readLocaleMetadata(locales_base, [packagerGecko.defaultLocale]) extensionName = locales[packagerGecko.defaultLocale]['name'] # Now commit the change and tag it subprocess.check_call([ 'hg', 'commit', '-R', baseDir, '-m', 'Releasing %s %s' % (extensionName, version) ]) tag_name = version if type in {'safari', 'edge'}: tag_name = '{}-{}'.format(tag_name, type) subprocess.check_call(['hg', 'tag', '-R', baseDir, '-f', tag_name]) # Create a release build downloads = [] if type == 'gecko': buildPath = os.path.join(downloadsRepo, getDefaultFileName(metadata, version, 'xpi')) packager.createBuild(baseDir, type=type, outFile=buildPath, releaseBuild=True) downloads.append(buildPath) elif type == 'chrome': # Create both signed and unsigned Chrome builds (the latter for Chrome Web Store). buildPath = os.path.join(downloadsRepo, getDefaultFileName(metadata, version, 'crx')) packager.createBuild(baseDir, type=type, outFile=buildPath, releaseBuild=True, keyFile=keyFile) downloads.append(buildPath) buildPathUnsigned = os.path.join( baseDir, getDefaultFileName(metadata, version, 'zip')) packager.createBuild(baseDir, type=type, outFile=buildPathUnsigned, releaseBuild=True, keyFile=None) elif type == 'safari': buildPath = os.path.join( downloadsRepo, getDefaultFileName(metadata, version, 'safariextz')) packager.createBuild(baseDir, type='safari', outFile=buildPath, releaseBuild=True, keyFile=keyFile) downloads.append(buildPath) elif type == 'edge': # We only offer the Edge extension for use through the Windows Store buildPath = os.path.join(downloadsRepo, getDefaultFileName(metadata, version, 'appx')) packager.createBuild(baseDir, type=type, outFile=buildPath, releaseBuild=True) downloads.append(buildPath) # Create source archive archivePath = os.path.splitext(buildPath)[0] + '-source.tgz' create_sourcearchive(baseDir, archivePath) downloads.append(archivePath) # Now add the downloads and commit subprocess.check_call(['hg', 'add', '-R', downloadsRepo] + downloads) subprocess.check_call([ 'hg', 'commit', '-R', downloadsRepo, '-m', 'Releasing %s %s' % (extensionName, version) ]) # Push all changes subprocess.check_call(['hg', 'push', '-R', baseDir]) subprocess.check_call(['hg', 'push', '-R', downloadsRepo])
def createBuild(baseDir, type='edge', outFile=None, # noqa: preserve API. buildNum=None, releaseBuild=False, keyFile=None, devenv=False): metadata = packager.readMetadata(baseDir, type) version = packager.getBuildVersion(baseDir, metadata, releaseBuild, buildNum) outfile = outFile or packager.getDefaultFileName(metadata, version, 'appx') params = { 'type': type, 'baseDir': baseDir, 'releaseBuild': releaseBuild, 'version': version, 'devenv': devenv, 'metadata': metadata, } files = packager.Files(packagerChrome.getPackageFiles(params), packagerChrome.getIgnoredFiles(params)) if metadata.has_section('mapping'): mapped = metadata.items('mapping') files.readMappedFiles(mapped) files.read(baseDir, skip=[filename for filename, _ in mapped]) else: files.read(baseDir) if metadata.has_section('bundles'): bundle_tests = devenv and metadata.has_option('general', 'testScripts') packagerChrome.create_bundles(params, files, bundle_tests) if metadata.has_section('preprocess'): files.preprocess(metadata.options('preprocess'), {'needsExt': True}) if metadata.has_section('import_locales'): packagerChrome.import_locales(params, files) # The Windows Store will reject the build unless every translation of the # product name has been reserved. This is hard till impossible to manage # with community translations, so we don't translate the product name for # Microsoft Edge. Furthermore, manifoldjs fails with a server error if the # product name is tranlated into Azerbajani. data = json.loads(files['_locales/{}/messages.json'.format(defaultLocale)]) files['manifest.json'] = re.sub( r'__MSG_(name(?:_devbuild|_releasebuild)?)__', lambda m: data[m.group(1)]['message'], packagerChrome.createManifest(params, files), ) if devenv: packagerChrome.add_devenv_requirements(files, metadata, params) zipped = StringIO() files.zip(zipped) zipped.seek(0) if devenv: shutil.copyfileobj(zipped, outfile) return tmp_dir = tempfile.mkdtemp('adblockplus_package') try: src_dir = os.path.join(tmp_dir, 'src') ext_dir = os.path.join(tmp_dir, 'ext') with ZipFile(zipped, 'r') as zip_file: zip_file.extractall(src_dir) cmd_env = os.environ.copy() cmd_env['SRC_FOLDER'] = src_dir cmd_env['EXT_FOLDER'] = ext_dir # prepare the extension with manifoldjs cmd = ['npm', 'run', '--silent', 'build-edge'] subprocess.check_call(cmd, env=cmd_env, cwd=os.path.dirname(__file__)) manifold_folder = glob(os.path.join(ext_dir, '*', 'edgeextension'))[0] manifest_folder = os.path.join(manifold_folder, 'manifest') asset_folder = os.path.join(manifest_folder, ASSETS_DIR) # update incomplete appxmanifest intermediate_manifest = os.path.join(manifest_folder, MANIFEST) update_appx_manifest(intermediate_manifest, baseDir, files, metadata, releaseBuild, buildNum) # cleanup placeholders, copy actual images shutil.rmtree(asset_folder) os.mkdir(asset_folder) if metadata.has_section('appx_assets'): for name, path in metadata.items('appx_assets'): path = os.path.join(baseDir, path) target = os.path.join(asset_folder, name) shutil.copyfile(path, target) # package app with manifoldjs cmd = ['npm', 'run', '--silent', 'package-edge'] subprocess.check_call(cmd, env=cmd_env, cwd=os.path.dirname(__file__)) package = os.path.join(manifold_folder, 'package', 'edgeExtension.appx') shutil.copyfile(package, outfile) finally: shutil.rmtree(tmp_dir, ignore_errors=True)
def run(baseDir, type, version, keyFile, downloadsRepo): if type == "gecko": import buildtools.packagerGecko as packager elif type == "safari": import buildtools.packagerSafari as packager elif type == "edge": import buildtools.packagerEdge as packager elif type == "chrome": import buildtools.packagerChrome as packager # Replace version number in metadata file "manually", ConfigParser will mess # up the order of lines. metadata = readMetadata(baseDir, type) with open(metadata.option_source("general", "version"), "r+b") as file: rawMetadata = file.read() rawMetadata = re.sub(r"^(\s*version\s*=\s*).*", r"\g<1>%s" % version, rawMetadata, flags=re.I | re.M) file.seek(0) file.write(rawMetadata) file.truncate() # Read extension name from locale data import buildtools.packagerGecko as packagerGecko if type == "gecko": locales_base = baseDir else: # This is somewhat of a hack but reading out locale import config here would be too much locales_base = os.path.join(baseDir, "adblockplus") locales = packagerGecko.readLocaleMetadata(locales_base, [packagerGecko.defaultLocale]) extensionName = locales[packagerGecko.defaultLocale]["name"] # Now commit the change and tag it subprocess.check_call(["hg", "commit", "-R", baseDir, "-m", "Releasing %s %s" % (extensionName, version)]) tag_name = version if type in {"safari", "edge"}: tag_name = "{}-{}".format(tag_name, type) subprocess.check_call(["hg", "tag", "-R", baseDir, "-f", tag_name]) # Create a release build downloads = [] if type == "gecko": buildPath = os.path.join(downloadsRepo, getDefaultFileName(metadata, version, "xpi")) packager.createBuild(baseDir, type=type, outFile=buildPath, releaseBuild=True) downloads.append(buildPath) elif type == "chrome": # Create both signed and unsigned Chrome builds (the latter for Chrome Web Store). buildPath = os.path.join(downloadsRepo, getDefaultFileName(metadata, version, "crx")) packager.createBuild(baseDir, type=type, outFile=buildPath, releaseBuild=True, keyFile=keyFile) downloads.append(buildPath) buildPathUnsigned = os.path.join(baseDir, getDefaultFileName(metadata, version, "zip")) packager.createBuild(baseDir, type=type, outFile=buildPathUnsigned, releaseBuild=True, keyFile=None) elif type == "safari": buildPath = os.path.join(downloadsRepo, getDefaultFileName(metadata, version, "safariextz")) packager.createBuild(baseDir, type="safari", outFile=buildPath, releaseBuild=True, keyFile=keyFile) downloads.append(buildPath) elif type == "edge": # We only offer the Edge extension for use through the Windows Store buildPath = os.path.join(downloadsRepo, getDefaultFileName(metadata, version, "appx")) packager.createBuild(baseDir, type=type, outFile=buildPath, releaseBuild=True) downloads.append(buildPath) # Create source archive archivePath = os.path.splitext(buildPath)[0] + "-source.tgz" create_sourcearchive(baseDir, archivePath) downloads.append(archivePath) # Now add the downloads and commit subprocess.check_call(["hg", "add", "-R", downloadsRepo] + downloads) subprocess.check_call(["hg", "commit", "-R", downloadsRepo, "-m", "Releasing %s %s" % (extensionName, version)]) # Push all changes subprocess.check_call(["hg", "push", "-R", baseDir]) subprocess.check_call(["hg", "push", "-R", downloadsRepo])
def createBuild(baseDir, type, outFile=None, buildNum=None, releaseBuild=False, keyFile=None, devenv=False): metadata = readMetadata(baseDir, type) version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) if not outFile: outFile = getDefaultFileName(metadata, version, 'safariextz' if keyFile else 'zip') params = { 'type': type, 'baseDir': baseDir, 'releaseBuild': releaseBuild, 'version': version, 'devenv': devenv, 'metadata': metadata, } mapped = metadata.items('mapping') if metadata.has_section( 'mapping') else [] files = Files(getPackageFiles(params), getIgnoredFiles(params), process=lambda path, data: processFile(path, data, params)) files.readMappedFiles(mapped) files.read(baseDir, skip=[opt for opt, _ in mapped]) if metadata.has_section('convert_js'): convertJS(params, files) if metadata.has_section('preprocess'): files.preprocess([f for f, _ in metadata.items('preprocess')], {'needsExt': True}) if metadata.has_section('import_locales'): importGeckoLocales(params, files) if metadata.has_option('general', 'testScripts'): files['qunit/index.html'] = createScriptPage( params, 'testIndex.html.tmpl', ('general', 'testScripts')) if keyFile: from buildtools import xarfile certs, key = xarfile.read_certificates_and_key(keyFile) params['developerIdentifier'] = get_developer_identifier(certs) files['lib/info.js'] = createInfoModule(params) files['background.html'] = createScriptPage( params, 'background.html.tmpl', ('general', 'backgroundScripts')) files['Info.plist'] = createManifest(params, files) dirname = metadata.get('general', 'basename') + '.safariextension' for filename in files.keys(): files[os.path.join(dirname, filename)] = files.pop(filename) if not devenv and keyFile: from buildtools import xarfile xarfile.create(outFile, files, keyFile) else: files.zip(outFile)
def createBuild(baseDir, type='chrome', outFile=None, buildNum=None, releaseBuild=False, keyFile=None, devenv=False): metadata = readMetadata(baseDir, type) version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) if outFile == None: outFile = getDefaultFileName(metadata, version, 'crx' if keyFile else 'zip') params = { 'type': type, 'baseDir': baseDir, 'releaseBuild': releaseBuild, 'version': version, 'devenv': devenv, 'metadata': metadata, } mapped = metadata.items('mapping') if metadata.has_section('mapping') else [] files = Files(getPackageFiles(params), getIgnoredFiles(params), process=lambda path, data: processFile(path, data, params)) files.readMappedFiles(mapped) files.read(baseDir, skip=[opt for opt, _ in mapped]) if metadata.has_section('convert_js'): convertJS(params, files) if metadata.has_section('preprocess'): files.preprocess( [f for f, _ in metadata.items('preprocess')], {'needsExt': True} ) if metadata.has_section('import_locales'): importGeckoLocales(params, files) files['manifest.json'] = createManifest(params, files) if type == 'chrome': fixTranslationsForCWS(files) if devenv: import buildtools import random files.read(os.path.join(buildtools.__path__[0], 'chromeDevenvPoller__.js'), relpath='devenvPoller__.js') files['devenvVersion__'] = str(random.random()) if (metadata.has_option('general', 'backgroundScripts') and 'lib/info.js' in metadata.get('general', 'backgroundScripts').split() and 'lib/info.js' not in files): files['lib/info.js'] = createInfoModule(params) if metadata.has_option('general', 'testScripts'): files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmpl', ('general', 'testScripts')) zipdata = files.zipToString() signature = None pubkey = None if keyFile != None: signature = signBinary(zipdata, keyFile) pubkey = getPublicKey(keyFile) writePackage(outFile, pubkey, signature, zipdata)
def createBuild(baseDir, type='chrome', outFile=None, buildNum=None, releaseBuild=False, keyFile=None, devenv=False): metadata = readMetadata(baseDir, type) version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) if outFile == None: outFile = getDefaultFileName(metadata, version, 'crx' if keyFile else 'zip') params = { 'type': type, 'baseDir': baseDir, 'releaseBuild': releaseBuild, 'version': version, 'devenv': devenv, 'metadata': metadata, } mapped = metadata.items('mapping') if metadata.has_section( 'mapping') else [] files = Files(getPackageFiles(params), getIgnoredFiles(params), process=lambda path, data: processFile(path, data, params)) files.readMappedFiles(mapped) files.read(baseDir, skip=[opt for opt, _ in mapped]) if metadata.has_section('convert_js'): convertJS(params, files) if metadata.has_section('preprocess'): files.preprocess([f for f, _ in metadata.items('preprocess')], {'needsExt': True}) if metadata.has_section('import_locales'): importGeckoLocales(params, files) files['manifest.json'] = createManifest(params, files) if type == 'chrome': fixTranslationsForCWS(files) if devenv: import buildtools import random files.read(os.path.join(buildtools.__path__[0], 'chromeDevenvPoller__.js'), relpath='devenvPoller__.js') files['devenvVersion__'] = str(random.random()) if (metadata.has_option('general', 'backgroundScripts') and 'lib/info.js' in metadata.get('general', 'backgroundScripts').split() and 'lib/info.js' not in files): files['lib/info.js'] = createInfoModule(params) if metadata.has_option('general', 'testScripts'): files['qunit/index.html'] = createScriptPage( params, 'testIndex.html.tmpl', ('general', 'testScripts')) zipdata = files.zipToString() signature = None pubkey = None if keyFile != None: signature = signBinary(zipdata, keyFile) pubkey = getPublicKey(keyFile) writePackage(outFile, pubkey, signature, zipdata)
def createBuild(baseDir, type='edge', outFile=None, # noqa: preserve API. buildNum=None, releaseBuild=False, keyFile=None, devenv=False): metadata = packager.readMetadata(baseDir, type) version = packager.getBuildVersion(baseDir, metadata, releaseBuild, buildNum) outfile = outFile or packager.getDefaultFileName(metadata, version, 'appx') params = { 'type': type, 'baseDir': baseDir, 'releaseBuild': releaseBuild, 'version': version, 'devenv': devenv, 'metadata': metadata, } files = packager.Files(packagerChrome.getPackageFiles(params), packagerChrome.getIgnoredFiles(params)) if metadata.has_section('mapping'): mapped = metadata.items('mapping') files.readMappedFiles(mapped) files.read(baseDir, skip=[filename for filename, _ in mapped]) else: files.read(baseDir) if metadata.has_section('bundles'): bundle_tests = devenv and metadata.has_option('general', 'testScripts') packagerChrome.create_bundles(params, files, bundle_tests) if metadata.has_section('preprocess'): files.preprocess(metadata.options('preprocess'), {'needsExt': True}) if metadata.has_section('import_locales'): packagerChrome.import_locales(params, files) # The Windows Store will reject the build unless every translation of the # product name has been reserved. This is hard till impossible to manage # with community translations, so we don't translate the product name for # Microsoft Edge. Furthermore, manifoldjs fails with a server error if the # product name is tranlated into Azerbajani. data = json.loads(files['_locales/{}/messages.json'.format(defaultLocale)]) files['manifest.json'] = re.sub( r'__MSG_(name(?:_devbuild)?)__', lambda m: data[m.group(1)]['message'], packagerChrome.createManifest(params, files), ) if devenv: packagerChrome.add_devenv_requirements(files, metadata, params) zipped = StringIO() files.zip(zipped) zipped.seek(0) if devenv: shutil.copyfileobj(zipped, outfile) return tmp_dir = tempfile.mkdtemp('adblockplus_package') try: src_dir = os.path.join(tmp_dir, 'src') ext_dir = os.path.join(tmp_dir, 'ext') with ZipFile(zipped, 'r') as zip_file: zip_file.extractall(src_dir) cmd_env = os.environ.copy() cmd_env['SRC_FOLDER'] = src_dir cmd_env['EXT_FOLDER'] = ext_dir # prepare the extension with manifoldjs cmd = ['npm', 'run', '--silent', 'build-edge'] subprocess.check_call(cmd, env=cmd_env, cwd=os.path.dirname(__file__)) manifold_folder = glob(os.path.join(ext_dir, '*', 'edgeextension'))[0] manifest_folder = os.path.join(manifold_folder, 'manifest') asset_folder = os.path.join(manifest_folder, ASSETS_DIR) # update incomplete appxmanifest intermediate_manifest = os.path.join(manifest_folder, MANIFEST) update_appx_manifest(intermediate_manifest, baseDir, files, metadata, releaseBuild, buildNum) # cleanup placeholders, copy actual images shutil.rmtree(asset_folder) os.mkdir(asset_folder) if metadata.has_section('appx_assets'): for name, path in metadata.items('appx_assets'): path = os.path.join(baseDir, path) target = os.path.join(asset_folder, name) shutil.copyfile(path, target) # package app with manifoldjs cmd = ['npm', 'run', '--silent', 'package-edge'] subprocess.check_call(cmd, env=cmd_env, cwd=os.path.dirname(__file__)) package = os.path.join(manifold_folder, 'package', 'edgeExtension.appx') shutil.copyfile(package, outfile) finally: shutil.rmtree(tmp_dir, ignore_errors=True)