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, 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):
    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)
Example #4
0
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)
Example #5
0
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)
Example #6
0
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)
Example #7
0
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)
Example #8
0
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)
Example #9
0
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)