diff options
author | Edward Cragg <edward.cragg@codethink.co.uk> | 2016-04-05 16:08:24 +0100 |
---|---|---|
committer | Paul Sherwood <paul.sherwood@codethink.co.uk> | 2016-04-21 10:30:44 +0000 |
commit | b7dfc88bd32c48034ce65304115a035f5b84239c (patch) | |
tree | c161c7c4be2da5be2182f4fdffe87a79de18c08e /scripts | |
parent | 19d8855a264f1f85730d63c7c7d3ba0336e061b5 (diff) | |
download | definitions-b7dfc88bd32c48034ce65304115a035f5b84239c.tar.gz |
scripts/licensecheck.py: Fall back to `git clone` if morph isn't available
This is a quick fix to allow the script to be run without dependence on morph.
As discussed on IRC, since it isn't a simple problem finding a way to safely
allow access to caches from different build tools, such a solution hasn't been
attempted. When falling back to `git clone`, this change prevents the script
from using an existing cache, generating its own instead by cloning from the
Baserock cache server, which takes longer.
Also add automatic creation of REPOS_DIR if it doesn't exist.
Change-Id: Id4b0977a2cae90068b6c2e2fd0c62470287bdfcb
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/licensecheck.py | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/scripts/licensecheck.py b/scripts/licensecheck.py index 59125ea1..08d0e1b4 100755 --- a/scripts/licensecheck.py +++ b/scripts/licensecheck.py @@ -84,6 +84,8 @@ def check_repo_if_needed(name, repo, ref, repos_dir, licenses_dir): if repo_name.endswith(".git"): repo_name = repo_name[:-4] + repo_url = scriptslib.parse_repo_alias(repo) + # Check if ref is sha1 to speedup if len(ref) == 40 and all(c in string.hexdigits for c in ref): license_file = license_file_name(repo_name, ref, licenses_dir) @@ -98,13 +100,31 @@ def check_repo_if_needed(name, repo, ref, repos_dir, licenses_dir): subprocess.check_call([ "git", "remote", "update", "origin", "--prune"], stderr=devnull, stdout=devnull, cwd=clone_path) + # Update submodules + subprocess.check_call( + ["git", "submodule", "update", "--recursive"], + stderr=devnull, stdout=devnull, cwd=clone_path) subprocess.check_call(["git", "checkout", ref], stderr=devnull, stdout=devnull, cwd=clone_path) else: sys.stderr.write("Getting repo '%s' ...\n" % repo_name) with open(os.devnull, 'w') as devnull: - subprocess.check_call(["morph", "get-repo", name, clone_path], - stdout=devnull, stderr=devnull) + try: + # Attempt to use morph to obtain a repository, from morph's + # existing local git cache if possible + subprocess.check_call( + ["morph", "get-repo", name, clone_path], + stdout=devnull, stderr=devnull) + + except (OSError, subprocess.CalledProcessError): + # Fall back to git clone, when morph hasn't been found on the + # system, or otherwise fails to get a repo. This is required + # where morph isn't available, e.g. when using YBD to build. + # YBD currently doesn't offer a similar 'get-repo' feature. + sys.stderr.write("Falling back to git clone.\n") + subprocess.check_call( + ["git", "clone", "--recursive", repo_url, clone_path], + stdout=devnull, stderr=devnull) # also clone submodules sha = subprocess.check_output( ["git", "rev-parse", "HEAD"], cwd=clone_path).strip() @@ -145,6 +165,9 @@ def main(): args = parser.parse_args() + if not os.path.exists(args.repos_dir): + os.makedirs(args.repos_dir) + system = scriptslib.load_yaml_file(args.system) license_files = [] for stratum in system['strata']: |