4 sys
.path
.insert(1, os
.path
.dirname(sys
.path
[0])) # noqa - don't warn about imports
6 from mozharness
.base
.log
import FATAL
7 from mozharness
.base
.script
import BaseScript
8 from mozharness
.mozilla
.mock
import ERROR_MSGS
11 class Repackage(BaseScript
):
13 def __init__(self
, require_config_file
=False):
23 require_config_file
=require_config_file
,
27 def download_input(self
):
29 dirs
= self
.query_abs_dirs()
31 input_home
= config
['input_home'].format(**dirs
)
33 for path
, url
in config
["download_config"].items():
34 status
= self
.download_file(url
=url
,
36 parent_dir
=input_home
)
38 self
.fatal("Unable to fetch signed input from %s" % url
)
41 # Ensure mar is executable
42 self
.chmod(os
.path
.join(input_home
, path
), 0755)
46 if self
.config
.get("run_configure", True):
50 def query_abs_dirs(self
):
53 abs_dirs
= super(Repackage
, self
).query_abs_dirs()
55 for directory
in abs_dirs
:
56 value
= abs_dirs
[directory
]
57 abs_dirs
[directory
] = value
60 dirs
['abs_tools_dir'] = os
.path
.join(abs_dirs
['abs_work_dir'], 'tools')
61 dirs
['abs_mozilla_dir'] = os
.path
.join(abs_dirs
['abs_work_dir'], 'src')
63 if config
.get('locale'):
64 locale_dir
= "{}{}".format(os
.path
.sep
, config
['locale'])
65 dirs
['output_home'] = config
['output_home'].format(locale
=locale_dir
, **abs_dirs
)
66 for key
in dirs
.keys():
67 if key
not in abs_dirs
:
68 abs_dirs
[key
] = dirs
[key
]
69 self
.abs_dirs
= abs_dirs
74 dirs
= self
.query_abs_dirs()
76 # Make sure the upload dir is around.
77 self
.mkdir_p(dirs
['output_home'])
79 for repack_config
in config
["repackage_config"]:
80 command
= [sys
.executable
, 'mach', '--log-no-times', 'repackage'] + \
82 for arg
in list(repack_config
)]
85 cwd
=dirs
['abs_mozilla_dir'],
89 def _run_tooltool(self
):
91 dirs
= self
.query_abs_dirs()
92 manifest_src
= os
.environ
.get('TOOLTOOL_MANIFEST')
94 manifest_src
= config
.get('tooltool_manifest_src')
96 return self
.warning(ERROR_MSGS
['tooltool_manifest_undetermined'])
98 tooltool_manifest_path
= os
.path
.join(dirs
['abs_mozilla_dir'],
101 sys
.executable
, '-u',
102 os
.path
.join(dirs
['abs_mozilla_dir'], 'mach'),
107 '--tooltool-manifest',
108 tooltool_manifest_path
,
109 '--artifact-manifest',
110 os
.path
.join(dirs
['abs_mozilla_dir'], 'toolchains.json'),
112 config
['tooltool_url'],
114 auth_file
= self
._get
_tooltool
_auth
_file
()
116 cmd
.extend(['--authentication-file', auth_file
])
117 cache
= config
.get('tooltool_cache')
119 cmd
.extend(['--cache-dir', cache
])
121 self
.run_command(cmd
, cwd
=dirs
['abs_mozilla_dir'], halt_on_failure
=True)
123 def _get_tooltool_auth_file(self
):
124 # set the default authentication file based on platform; this
125 # corresponds to where puppet puts the token
126 if 'tooltool_authentication_file' in self
.config
:
127 fn
= self
.config
['tooltool_authentication_file']
128 elif self
._is
_windows
():
129 fn
= r
'c:\builds\relengapi.tok'
131 fn
= '/builds/relengapi.tok'
133 # if the file doesn't exist, don't pass it to tooltool (it will just
134 # fail). In taskcluster, this will work OK as the relengapi-proxy will
135 # take care of auth. Everywhere else, we'll get auth failures if
137 if os
.path
.exists(fn
):
140 def _get_mozconfig(self
):
141 """assign mozconfig."""
143 dirs
= self
.query_abs_dirs()
144 abs_mozconfig_path
= ''
146 # first determine the mozconfig path
147 if c
.get('src_mozconfig'):
148 self
.info('Using in-tree mozconfig')
149 abs_mozconfig_path
= os
.path
.join(dirs
['abs_mozilla_dir'], c
['src_mozconfig'])
151 self
.fatal("'src_mozconfig' must be in the config "
152 "in order to determine the mozconfig.")
155 self
.read_from_file(abs_mozconfig_path
, error_level
=FATAL
)
157 # finally, copy the mozconfig to a path that 'mach build' expects it to be
158 self
.copyfile(abs_mozconfig_path
, os
.path
.join(dirs
['abs_mozilla_dir'], '.mozconfig'))
160 def _run_configure(self
):
161 dirs
= self
.query_abs_dirs()
162 command
= [sys
.executable
, 'mach', '--log-no-times', 'configure']
163 return self
.run_command(
165 cwd
=dirs
['abs_mozilla_dir'],
167 halt_on_failure
=True,
171 if __name__
== '__main__':
173 repack
.run_and_exit()