Revision control

Other Tools

1
# This Source Code Form is subject to the terms of the Mozilla Public
2
# License, v. 2.0. If a copy of the MPL was not distributed with this
3
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5
from __future__ import print_function, unicode_literals
6
7
import sys
8
import os
9
10
import buildconfig
11
12
sourcestamp_tmpl = """{buildid}
13
{comm_repo}/rev/{comm_rev}
14
{gecko_repo}/rev/{gecko_rev}
15
"""
16
17
18
def gen_platformini(output, platform_ini):
19
gecko_repo = buildconfig.substs.get('MOZ_GECKO_SOURCE_REPO', '')
20
gecko_rev = buildconfig.substs.get('MOZ_GECKO_SOURCE_CHANGESET', '')
21
22
with open(platform_ini, 'r') as fp:
23
data = fp.readlines()
24
25
for i in range(len(data)):
26
if data[i].startswith('SourceRepository='):
27
data[i] = 'SourceRepository=%s\n' % gecko_repo
28
elif data[i].startswith('SourceStamp='):
29
data[i] = 'SourceStamp=%s\n' % gecko_rev
30
31
with open(platform_ini, 'w') as fp:
32
fp.writelines(data)
33
34
output.write('platform.ini updated.\n')
35
36
37
def gen_sourcestamp(output):
38
data = dict(buildid=os.environ.get('MOZ_BUILD_DATE', 'unknown'),
39
gecko_repo=buildconfig.substs.get('MOZ_GECKO_SOURCE_REPO', None),
40
gecko_rev=buildconfig.substs.get('MOZ_GECKO_SOURCE_CHANGESET', None),
41
comm_repo=buildconfig.substs.get('MOZ_COMM_SOURCE_REPO', None),
42
comm_rev=buildconfig.substs.get('MOZ_COMM_SOURCE_CHANGESET', None))
43
44
output.write(sourcestamp_tmpl.format(**data))
45
46
47
def source_repo_header(output):
48
"""
49
Appends the Gecko source repository information to source-repo.h
50
This information should be set in buildconfig.substs by moz.configure
51
"""
52
gecko_repo = buildconfig.substs.get('MOZ_GECKO_SOURCE_REPO', None)
53
gecko_rev = buildconfig.substs.get('MOZ_GECKO_SOURCE_CHANGESET', None)
54
comm_repo = buildconfig.substs.get('MOZ_COMM_SOURCE_REPO', None)
55
comm_rev = buildconfig.substs.get('MOZ_COMM_SOURCE_CHANGESET', None)
56
57
if None in [gecko_repo, gecko_rev, comm_repo, comm_rev]:
58
Exception("Source information not found in buildconfig."
59
"Try setting GECKO_HEAD_REPOSITORY and GECKO_HEAD_REV"
60
"as well as MOZ_SOURCE_REPO and MOZ_SOURCE_CHANGESET"
61
"environment variables and running mach configure again.")
62
63
output.write('#define MOZ_GECKO_SOURCE_STAMP {}\n'.format(gecko_rev))
64
output.write('#define MOZ_COMM_SOURCE_STAMP {}\n'.format(comm_rev))
65
output.write('#define MOZ_SOURCE_STAMP {}\n'.format(comm_rev))
66
67
if buildconfig.substs.get('MOZ_INCLUDE_SOURCE_INFO'):
68
gecko_source_url = '%s/rev/%s' % (gecko_repo, gecko_rev)
69
comm_source_url = '%s/rev/%s' % (comm_repo, comm_rev)
70
output.write('#define MOZ_GECKO_SOURCE_REPO {}\n'.format(gecko_repo))
71
output.write('#define MOZ_GECKO_SOURCE_URL {}\n'.format(gecko_source_url))
72
output.write('#define MOZ_COMM_SOURCE_REPO {}\n'.format(comm_repo))
73
output.write('#define MOZ_COMM_SOURCE_URL {}\n'.format(comm_source_url))
74
output.write('#define MOZ_SOURCE_REPO {}\n'.format(comm_repo))
75
output.write('#define MOZ_SOURCE_URL {}\n'.format(comm_source_url))
76
77
78
def main(args):
79
if args:
80
func = globals().get(args[0])
81
if func:
82
return func(sys.stdout, *args[1:])
83
84
return 1
85
86
87
if __name__ == '__main__':
88
sys.exit(main(sys.argv[1:]))