2014-05-16 22:37:31 +04:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# 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/.
|
|
|
|
|
2014-06-16 21:17:21 +04:00
|
|
|
import sys
|
|
|
|
import os
|
2014-10-23 19:32:25 +04:00
|
|
|
import hashlib
|
2014-06-16 21:17:21 +04:00
|
|
|
import json
|
|
|
|
import re
|
|
|
|
import errno
|
2014-05-16 22:37:31 +04:00
|
|
|
from argparse import ArgumentParser
|
|
|
|
|
|
|
|
def getFileHashAndSize(filename):
|
2014-10-23 19:32:25 +04:00
|
|
|
sha512Hash = 'UNKNOWN'
|
2014-05-16 22:37:31 +04:00
|
|
|
size = 'UNKNOWN'
|
|
|
|
|
|
|
|
try:
|
|
|
|
# open in binary mode to make sure we get consistent results
|
|
|
|
# across all platforms
|
|
|
|
f = open(filename, "rb")
|
2014-10-23 19:32:25 +04:00
|
|
|
shaObj = hashlib.sha512(f.read())
|
|
|
|
sha512Hash = shaObj.hexdigest()
|
2014-05-16 22:37:31 +04:00
|
|
|
|
|
|
|
size = os.path.getsize(filename)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2014-10-23 19:32:25 +04:00
|
|
|
return (sha512Hash, size)
|
2014-05-16 22:37:31 +04:00
|
|
|
|
2014-10-25 02:24:33 +04:00
|
|
|
def getMarProperties(filename, partial=False):
|
2014-07-04 06:14:59 +04:00
|
|
|
if not os.path.exists(filename):
|
|
|
|
return {}
|
2014-10-25 02:24:33 +04:00
|
|
|
(mar_hash, mar_size) = getFileHashAndSize(filename)
|
|
|
|
martype = 'partial' if partial else 'complete'
|
2014-05-16 22:37:31 +04:00
|
|
|
return {
|
2014-10-25 02:24:33 +04:00
|
|
|
'%sMarFilename' % martype: os.path.basename(filename),
|
|
|
|
'%sMarSize' % martype: mar_size,
|
|
|
|
'%sMarHash' % martype: mar_hash,
|
2014-05-16 22:37:31 +04:00
|
|
|
}
|
|
|
|
|
2015-05-13 21:26:53 +03:00
|
|
|
def getUrlProperties(filename, package):
|
2014-05-16 22:37:31 +04:00
|
|
|
# let's create a switch case using name-spaces/dict
|
|
|
|
# rather than a long if/else with duplicate code
|
|
|
|
property_conditions = [
|
|
|
|
# key: property name, value: condition
|
|
|
|
('symbolsUrl', lambda m: m.endswith('crashreporter-symbols.zip') or
|
|
|
|
m.endswith('crashreporter-symbols-full.zip')),
|
|
|
|
('testsUrl', lambda m: m.endswith(('tests.tar.bz2', 'tests.zip'))),
|
|
|
|
('unsignedApkUrl', lambda m: m.endswith('apk') and
|
|
|
|
'unsigned-unaligned' in m),
|
|
|
|
('robocopApkUrl', lambda m: m.endswith('apk') and 'robocop' in m),
|
|
|
|
('jsshellUrl', lambda m: 'jsshell-' in m and m.endswith('.zip')),
|
|
|
|
('completeMarUrl', lambda m: m.endswith('.complete.mar')),
|
2014-10-25 02:24:33 +04:00
|
|
|
('partialMarUrl', lambda m: m.endswith('.mar') and '.partial.' in m),
|
2014-12-08 21:32:48 +03:00
|
|
|
('codeCoverageURL', lambda m: m.endswith('code-coverage-gcno.zip')),
|
2015-03-17 22:29:07 +03:00
|
|
|
('sdkUrl', lambda m: m.endswith(('sdk.tar.bz2', 'sdk.zip'))),
|
2015-05-15 21:30:24 +03:00
|
|
|
('testPackagesUrl', lambda m: m.endswith('test_packages.json')),
|
2015-05-13 21:26:53 +03:00
|
|
|
('packageUrl', lambda m: m.endswith(package)),
|
2014-05-16 22:37:31 +04:00
|
|
|
]
|
2015-05-15 21:30:24 +03:00
|
|
|
url_re = re.compile(r'''^(https?://.*?\.(?:tar\.bz2|dmg|zip|apk|rpm|mar|tar\.gz|json))$''')
|
2014-05-16 22:37:31 +04:00
|
|
|
properties = {}
|
|
|
|
|
2014-06-16 21:17:21 +04:00
|
|
|
try:
|
|
|
|
with open(filename) as f:
|
|
|
|
for line in f:
|
|
|
|
m = url_re.match(line)
|
|
|
|
if m:
|
|
|
|
m = m.group(1)
|
|
|
|
for prop, condition in property_conditions:
|
|
|
|
if condition(m):
|
|
|
|
properties.update({prop: m})
|
|
|
|
break
|
|
|
|
except IOError as e:
|
|
|
|
if e.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
properties = {prop: 'UNKNOWN' for prop, condition in property_conditions}
|
2014-05-16 22:37:31 +04:00
|
|
|
return properties
|
|
|
|
|
2014-11-07 01:10:13 +03:00
|
|
|
def getPartialInfo(props):
|
|
|
|
return [{
|
|
|
|
"from_buildid": props.get("previous_buildid"),
|
|
|
|
"size": props.get("partialMarSize"),
|
|
|
|
"hash": props.get("partialMarHash"),
|
|
|
|
"url": props.get("partialMarUrl"),
|
|
|
|
}]
|
|
|
|
|
2014-05-16 22:37:31 +04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = ArgumentParser(description='Generate mach_build_properties.json for automation builds.')
|
|
|
|
parser.add_argument("--complete-mar-file", required=True,
|
|
|
|
action="store", dest="complete_mar_file",
|
|
|
|
help="Path to the complete MAR file, relative to the objdir.")
|
2014-10-25 02:24:33 +04:00
|
|
|
parser.add_argument("--partial-mar-file", required=False,
|
|
|
|
action="store", dest="partial_mar_file",
|
|
|
|
help="Path to the partial MAR file, relative to the objdir.")
|
2014-05-16 22:37:31 +04:00
|
|
|
parser.add_argument("--upload-output", required=True,
|
|
|
|
action="store", dest="upload_output",
|
|
|
|
help="Path to the text output of 'make upload'")
|
2014-12-10 00:35:42 +03:00
|
|
|
parser.add_argument("--upload-files", required=True, nargs="+",
|
|
|
|
action="store", dest="upload_files",
|
|
|
|
help="List of files to be uploaded.")
|
2015-05-13 21:26:53 +03:00
|
|
|
parser.add_argument("--package", required=True,
|
|
|
|
action="store", dest="package",
|
|
|
|
help="Filename of the build package")
|
2014-05-16 22:37:31 +04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
json_data = getMarProperties(args.complete_mar_file)
|
2015-05-13 21:26:53 +03:00
|
|
|
json_data.update(getUrlProperties(args.upload_output, args.package))
|
2014-10-25 02:24:33 +04:00
|
|
|
if args.partial_mar_file:
|
|
|
|
json_data.update(getMarProperties(args.partial_mar_file, partial=True))
|
2014-11-07 01:10:13 +03:00
|
|
|
|
|
|
|
# Pull the previous buildid from the partial mar filename.
|
|
|
|
res = re.match(r'.*\.([0-9]+)-[0-9]+.mar', args.partial_mar_file)
|
|
|
|
if res:
|
|
|
|
json_data['previous_buildid'] = res.group(1)
|
|
|
|
|
|
|
|
# Set partialInfo to be a collection of the partial mar properties
|
|
|
|
# useful for balrog.
|
|
|
|
json_data['partialInfo'] = getPartialInfo(json_data)
|
2014-05-16 22:37:31 +04:00
|
|
|
|
2014-12-10 00:35:42 +03:00
|
|
|
json_data['uploadFiles'] = args.upload_files
|
2015-05-13 21:26:53 +03:00
|
|
|
json_data['packageFilename'] = args.package
|
2014-12-10 00:35:42 +03:00
|
|
|
|
2014-05-16 22:37:31 +04:00
|
|
|
with open('mach_build_properties.json', 'w') as outfile:
|
|
|
|
json.dump(json_data, outfile, indent=4)
|