build/source_repos.py
author Magnus Melin <mkmelin+mozilla@iki.fi>
Sun, 29 Mar 2020 15:18:00 +0300
changeset 38604 082497e9e8f0c52340cac0ca9c2f1cfa37ced671
parent 38547 c8aea2febde1ce9fb9ddf30a5fc2fd540d9fa02e
child 38996 dce2046514b0a603c84bbf6cbf1cbc8730faf35e
permissions -rw-r--r--
Bug 1625675 - followup2 - add default128.png too to allowed-dupes.mn (also needed for linux CI not to fail). r=Paenglab

#  This Source Code Form is subject to the terms of the Mozilla Public
#  License, v. 2.0. If a copy of the MPL was not distributed with this
#  file, You can obtain one at http://mozilla.org/MPL/2.0/.

from __future__ import print_function, unicode_literals, absolute_import

import sys
import os

import buildconfig

sourcestamp_tmpl = """{buildid}
{comm_repo}/rev/{comm_rev}
{gecko_repo}/rev/{gecko_rev}
"""


def gen_platformini(output, platform_ini):
    gecko_repo = buildconfig.substs.get('MOZ_GECKO_SOURCE_REPO', '')
    gecko_rev = buildconfig.substs.get('MOZ_GECKO_SOURCE_CHANGESET', '')

    with open(platform_ini, 'r') as fp:
        data = fp.readlines()

    for i in range(len(data)):
        if data[i].startswith('SourceRepository='):
            data[i] = 'SourceRepository=%s\n' % gecko_repo
        elif data[i].startswith('SourceStamp='):
            data[i] = 'SourceStamp=%s\n' % gecko_rev

    with open(platform_ini, 'w') as fp:
        fp.writelines(data)

    output.write('platform.ini updated.\n')


def gen_sourcestamp(output):
    data = dict(buildid=os.environ.get('MOZ_BUILD_DATE', 'unknown'),
        gecko_repo=buildconfig.substs.get('MOZ_GECKO_SOURCE_REPO', None),
        gecko_rev=buildconfig.substs.get('MOZ_GECKO_SOURCE_CHANGESET', None),
        comm_repo=buildconfig.substs.get('MOZ_COMM_SOURCE_REPO', None),
        comm_rev=buildconfig.substs.get('MOZ_COMM_SOURCE_CHANGESET', None))

    output.write(sourcestamp_tmpl.format(**data))


def source_repo_header(output):
    """
    Appends the Gecko source repository information to source-repo.h
    This information should be set in buildconfig.substs by moz.configure
    """
    gecko_repo = buildconfig.substs.get('MOZ_GECKO_SOURCE_REPO', None)
    gecko_rev = buildconfig.substs.get('MOZ_GECKO_SOURCE_CHANGESET', None)
    comm_repo = buildconfig.substs.get('MOZ_COMM_SOURCE_REPO', None)
    comm_rev = buildconfig.substs.get('MOZ_COMM_SOURCE_CHANGESET', None)

    if None in [gecko_repo, gecko_rev, comm_repo, comm_rev]:
        Exception("Source information not found in buildconfig."
                  "Try setting GECKO_HEAD_REPOSITORY and GECKO_HEAD_REV"
                  "as well as MOZ_SOURCE_REPO and MOZ_SOURCE_CHANGESET"
                  "environment variables and running mach configure again.")

    output.write('#define MOZ_GECKO_SOURCE_STAMP {}\n'.format(gecko_rev))
    output.write('#define MOZ_COMM_SOURCE_STAMP {}\n'.format(comm_rev))
    output.write('#define MOZ_SOURCE_STAMP {}\n'.format(comm_rev))

    if buildconfig.substs.get('MOZ_INCLUDE_SOURCE_INFO'):
        gecko_source_url = '%s/rev/%s' % (gecko_repo, gecko_rev)
        comm_source_url = '%s/rev/%s' % (comm_repo, comm_rev)
        output.write('#define MOZ_GECKO_SOURCE_REPO {}\n'.format(gecko_repo))
        output.write('#define MOZ_GECKO_SOURCE_URL {}\n'.format(gecko_source_url))
        output.write('#define MOZ_COMM_SOURCE_REPO {}\n'.format(comm_repo))
        output.write('#define MOZ_COMM_SOURCE_URL {}\n'.format(comm_source_url))
        output.write('#define MOZ_SOURCE_REPO {}\n'.format(comm_repo))
        output.write('#define MOZ_SOURCE_URL {}\n'.format(comm_source_url))


def main(args):
    if args:
        func = globals().get(args[0])
        if func:
            return func(sys.stdout, *args[1:])

    return 1


if __name__ == '__main__':
    sys.exit(main(sys.argv[1:]))