[6a3a178] | 1 | #!/usr/bin/env python3
|
---|
| 2 |
|
---|
| 3 | import argparse
|
---|
| 4 | import os
|
---|
| 5 | import shutil
|
---|
| 6 | import subprocess
|
---|
| 7 | import sys
|
---|
| 8 | import tarfile
|
---|
| 9 | import tempfile
|
---|
| 10 | import urllib.request
|
---|
| 11 |
|
---|
| 12 | BASE_URL = "https://github.com/nodejs/gyp-next/archive/"
|
---|
| 13 | CHECKOUT_PATH = os.path.dirname(os.path.realpath(__file__))
|
---|
| 14 | CHECKOUT_GYP_PATH = os.path.join(CHECKOUT_PATH, 'gyp')
|
---|
| 15 |
|
---|
| 16 | parser = argparse.ArgumentParser()
|
---|
| 17 | parser.add_argument("tag", help="gyp tag to update to")
|
---|
| 18 | args = parser.parse_args()
|
---|
| 19 |
|
---|
| 20 | tar_url = BASE_URL + args.tag + ".tar.gz"
|
---|
| 21 |
|
---|
| 22 | changed_files = subprocess.check_output(["git", "diff", "--name-only"]).strip()
|
---|
| 23 | if changed_files:
|
---|
| 24 | raise Exception("Can't update gyp while you have uncommitted changes in node-gyp")
|
---|
| 25 |
|
---|
| 26 | with tempfile.TemporaryDirectory() as tmp_dir:
|
---|
| 27 | tar_file = os.path.join(tmp_dir, 'gyp.tar.gz')
|
---|
| 28 | unzip_target = os.path.join(tmp_dir, 'gyp')
|
---|
| 29 | with open(tar_file, 'wb') as f:
|
---|
| 30 | print("Downloading gyp-next@" + args.tag + " into temporary directory...")
|
---|
| 31 | print("From: " + tar_url)
|
---|
| 32 | with urllib.request.urlopen(tar_url) as in_file:
|
---|
| 33 | f.write(in_file.read())
|
---|
| 34 |
|
---|
| 35 | print("Unzipping...")
|
---|
| 36 | with tarfile.open(tar_file, "r:gz") as tar_ref:
|
---|
| 37 | tar_ref.extractall(unzip_target)
|
---|
| 38 |
|
---|
| 39 | print("Moving to current checkout (" + CHECKOUT_PATH + ")...")
|
---|
| 40 | if os.path.exists(CHECKOUT_GYP_PATH):
|
---|
| 41 | shutil.rmtree(CHECKOUT_GYP_PATH)
|
---|
| 42 | shutil.move(os.path.join(unzip_target, os.listdir(unzip_target)[0]), CHECKOUT_GYP_PATH)
|
---|
| 43 |
|
---|
| 44 | subprocess.check_output(["git", "add", "gyp"], cwd=CHECKOUT_PATH)
|
---|
| 45 | subprocess.check_output(["git", "commit", "-m", "gyp: update gyp to " + args.tag])
|
---|