From cf931f673f930b1e620948def8faf7fa6f45ac95 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Mon, 5 Jul 2021 09:22:01 +1200 Subject: [PATCH] update script to update exsting checkout --- Makefile | 16 +++++++--------- scripts/checkout-part.py | 27 --------------------------- scripts/update-part.py | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 36 deletions(-) delete mode 100755 scripts/checkout-part.py create mode 100755 scripts/update-part.py diff --git a/Makefile b/Makefile index c3984d00..24a40f11 100644 --- a/Makefile +++ b/Makefile @@ -50,23 +50,21 @@ flake8: @echo 'tox -e flake8' is preferred to 'make flake8' $(PYTHON) -m flake8 $(CHECK_DIRS) --exclude gettext38.py,contextlib38.py -unit: +unit: gitdeps python3 -m unittest discover -integration: +integration: gitdeps echo "Running integration tests..." ./scripts/runtests.sh check: unit integration -curtin: - ./scripts/checkout-part.py curtin +curtin: snapcraft.yaml + ./scripts/update-part.py curtin -probert: - @if [ ! -d "$(PROBERTDIR)" ]; then \ - ./scripts/checkout-part.py probert && \ - (cd probert && $(PYTHON) setup.py build_ext -i); \ - fi +probert: snapcraft.yaml + ./scripts/update-part.py probert + (cd probert && $(PYTHON) setup.py build_ext -i); gitdeps: curtin probert diff --git a/scripts/checkout-part.py b/scripts/checkout-part.py deleted file mode 100755 index a257316b..00000000 --- a/scripts/checkout-part.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/python3 -import subprocess -import sys -import yaml - -part = sys.argv[1] - - -def r(*args): - print('running', args) - subprocess.run(args, check=True) - - -with open("snapcraft.yaml") as f: - config = yaml.safe_load(f)["parts"][part] - -r('git', 'clone', config['source'], part) - - -c = None -for k in "source-commit", "source-tag", "source-branch": - if k in config: - c = config[k] - break - -if c is not None: - r('git', '-c', 'advice.detachedHead=false', '-C', part, 'checkout', c) diff --git a/scripts/update-part.py b/scripts/update-part.py new file mode 100755 index 00000000..648f1134 --- /dev/null +++ b/scripts/update-part.py @@ -0,0 +1,40 @@ +#!/usr/bin/python3 +import os +import subprocess +import sys +import yaml + +part = sys.argv[1] + + +def r(*args, **kw): + print('running', args) + subprocess.run(args, check=True, **kw) + + +def o(*args, **kw): + return subprocess.run(args, check=True, stdout=subprocess.PIPE).stdout + + +with open("snapcraft.yaml") as f: + config = yaml.safe_load(f)["parts"][part] + + +c = "master" +for k in "source-commit", "source-tag", "source-branch": + if k in config: + c = config[k] + break + +if not os.path.isdir(part): + r('git', 'clone', config['source'], part) + +expected = o('git', '-C', part, 'rev-parse', c) +actual = o('git', '-C', part, 'rev-parse', 'HEAD') + +if expected != actual: + try: + r('git', '-c', 'advice.detachedHead=false', '-C', part, 'checkout', c) + except subprocess.CalledProcessError: + r('git', '-C', part, 'fetch', config['source']) + r('git', '-c', 'advice.detachedHead=false', '-C', part, 'checkout', c)