| #!/usr/bin/env python3 |
| |
| import datetime |
| import os |
| import pprint |
| import shutil |
| import subprocess |
| import sys |
| import tempfile |
| import time |
| |
| from library_submodules import * |
| |
| |
| __dir__ = os.path.dirname(__file__) |
| |
| |
| def header(l, s, *args, **kw): |
| s1 = s.format(*args, **kw) |
| s2 = l*len(s1) |
| return '{}\n{}\n'.format(s1, s2) |
| |
| |
| message_template = """\ |
| """ |
| |
| |
| def main(args): |
| assert len(args) == 3 |
| |
| out_dir = os.path.abspath(args.pop(0)) |
| patchfile = os.path.abspath(args.pop(0)) |
| apply_to_lib = args.pop(0) |
| |
| assert os.path.exists(patchfile), patchfile |
| assert os.path.isfile(patchfile), patchfile |
| |
| print() |
| print() |
| assert os.path.exists(out_dir), out_dir |
| git_clone_dir = os.path.join(out_dir, "skywater-pdk") |
| if os.path.exists(git_clone_dir): |
| print("Removing old directory.") |
| print('='*75, flush=True) |
| run('rm -rf {}'.format(git_clone_dir)) |
| print('='*75, flush=True) |
| |
| os.makedirs(git_clone_dir) |
| |
| for l in libraries.keys(): |
| if l != apply_to_lib: |
| continue |
| git_out_dir = os.path.join(git_clone_dir, l) |
| assert not os.path.exists(git_out_dir), git_out_dir |
| print() |
| print() |
| print('Doing update on', l) |
| print('='*75, flush=True) |
| print() |
| print('Cloning initial repo') |
| print('-'*20, flush=True) |
| git_reference = os.path.abspath(os.path.expanduser('~/gob/foss-eda-tools/skywater-pdk-libs-{0}/.git'.format(l))) |
| assert os.path.exists(git_reference), git_reference |
| git('clone --reference {1} https://foss-eda-tools.googlesource.com/skywater-pdk/libs/{0}.git'.format(l, git_reference), git_clone_dir) |
| assert os.path.exists(os.path.join(git_out_dir, ".git")), "Git directory was not created in:"+git_out_dir |
| git('fetch origin', git_out_dir) |
| git('fetch origin --tags', git_out_dir) |
| git('status', git_out_dir) |
| print('-'*20, flush=True) |
| tags = subprocess.check_output('git tag -l', shell=True, cwd=git_out_dir) |
| tags = tags.decode('utf-8') |
| versions = [tuple(int(i) for i in v[1:].split('.')) for v in tags.split()] |
| if (0,0,0) in versions: |
| versions.remove((0,0,0)) |
| for i, v in enumerate(versions): |
| pv = previous_v(v, versions) |
| ov = out_v(v, versions) |
| |
| v_branch = "branch-{}.{}.{}".format(*ov) |
| v_tag = "v{}.{}.{}".format(*ov) |
| |
| print() |
| print("Was:", pv, "Now patching", (v_branch, v_tag), "with", patchfile) |
| print('-'*20, flush=True) |
| |
| # Get us back to a very clean tree. |
| git('reset --hard HEAD', git_out_dir) |
| git('clean -f', git_out_dir) |
| git('clean -x -f', git_out_dir) |
| |
| # Checkout the right branch |
| git('checkout origin/{0} -b {0}'.format(v_branch), git_out_dir) |
| if v in [(0,0,9)]: |
| continue |
| elif v in [(0, 10, 0), (0, 10, 1), (0, 11, 0), (0, 12, 0), (0, 12, 1), (0, 13, 0)]: |
| npatchfile = patchfile.replace('-2', '-1') |
| else: |
| npatchfile = patchfile |
| |
| diff_pos = 'branch-{}.{}.{}'.format(*pv) |
| # Update the contents |
| git('am {}'.format(patchfile), git_out_dir) |
| if v == versions[0]: |
| continue |
| |
| # Create the merge commit |
| git('reset --soft HEAD^', git_out_dir) |
| git('merge {} --no-ff --no-commit --strategy=recursive'.format(diff_pos), git_out_dir) |
| git('commit -C HEAD@{1}', git_out_dir) |
| |
| git('branch -D master', git_out_dir, can_fail=True) |
| git('branch master', git_out_dir) |
| |
| print('='*75, flush=True) |
| |
| |
| |
| if __name__ == "__main__": |
| sys.exit(main(sys.argv[1:])) |