aboutsummaryrefslogtreecommitdiff
path: root/scripts/external_revision_generator.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/external_revision_generator.py')
-rw-r--r--scripts/external_revision_generator.py32
1 files changed, 25 insertions, 7 deletions
diff --git a/scripts/external_revision_generator.py b/scripts/external_revision_generator.py
index 6edb9738e..497291ae1 100644
--- a/scripts/external_revision_generator.py
+++ b/scripts/external_revision_generator.py
@@ -24,6 +24,7 @@ import argparse
import hashlib
import subprocess
import uuid
+import json
def generate(symbol_name, commit_id, output_header_file):
# Write commit ID to output header file
@@ -85,21 +86,36 @@ def get_commit_id_from_file(rev_file):
return sha1.hexdigest()
def get_commit_id_from_uuid():
- unique_uuid = str(uuid.uuid4())
- sha1 = hashlib.sha1();
- sha1.update(unique_uuid.encode())
- return sha1.hexdigest()
+ unique_uuid = str(uuid.uuid4())
+ sha1 = hashlib.sha1();
+ sha1.update(unique_uuid.encode())
+ return sha1.hexdigest()
+
+def get_commit_id_from_json(json_file, json_keys):
+ with open(json_file) as json_stream:
+ json_data = json.load(json_stream)
+ for key in json_keys.split(','):
+ if type(json_data) == list:
+ json_data = json_data[int(key)]
+ else:
+ json_data = json_data[key]
+ return json_data
def main():
parser = argparse.ArgumentParser()
- parser.add_argument("-s", "--symbol_name", metavar="SYMBOL_NAME", required=True, help="C symbol name")
- parser.add_argument("-o", "--output_header_file", metavar="OUTPUT_HEADER_FILE", required=True, help="output header file path")
rev_method_group = parser.add_mutually_exclusive_group(required=True)
rev_method_group.add_argument("--git_dir", metavar="SOURCE_DIR", help="git working copy directory")
rev_method_group.add_argument("--rev_file", metavar="REVISION_FILE", help="source revision file path (must contain a SHA1 hash")
rev_method_group.add_argument("--from_uuid", action='store_true', help="base SHA1 on a dynamically generated UUID")
+ rev_method_group.add_argument("--json_file", metavar="JSON_FILE", help="path to json file")
+ parser.add_argument("-s", "--symbol_name", metavar="SYMBOL_NAME", required=True, help="C symbol name")
+ parser.add_argument("-o", "--output_header_file", metavar="OUTPUT_HEADER_FILE", required=True, help="output header file path")
+ parser.add_argument("--json_keys", action='store', metavar="JSON_KEYS", help="comma-separated list of keys specifying SHA1 location in root json object for --json_file option")
args = parser.parse_args()
+ if ('json_file' in args) != ('json_keys' in args):
+ parser.error('--json_file and --json_keys must be provided together')
+
# We can either parse the latest Git commit ID out of the specified repository (preferred where possible),
# or computing the SHA1 hash of the contents of a file passed on the command line and (where necessary --
# e.g. when building the layers outside of a Git environment).
@@ -113,7 +129,9 @@ def main():
elif args.rev_file is not None:
# Read the commit ID from a file.
commit_id = get_commit_id_from_file(args.rev_file)
- elif args.from_uuid is not None:
+ elif args.json_file is not None:
+ commit_id = get_commit_id_from_json(args.json_file, args.json_keys)
+ elif args.from_uuid:
commit_id = get_commit_id_from_uuid()
if not is_sha1(commit_id):