Skip to content

Commit

Permalink
Implement libuv updater script
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimyr committed Jun 17, 2020
1 parent b82cf5a commit 1f3625c
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
67 changes: 67 additions & 0 deletions util/update_libuv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python

from argparse import ArgumentParser
import sys
from os import path
from subprocess import CalledProcessError, run
import shutil
import platform
from util import clean_dir, remove_dir

parser = ArgumentParser()
parser.add_argument("version", nargs="?")

args = parser.parse_args(sys.argv[1:])

libuv_version = args.version.strip("v")

DEPS_DIR = path.join(path.dirname(__file__), "../deps/")
LIBUV_DIR = path.join(DEPS_DIR, "libuv")


def move(item, src, dest):
return shutil.move(path.join(src, item), path.join(dest, item))


def main(args):
libuv_repo = path.join(DEPS_DIR, "libuv_" + libuv_version)

print("Cloning libuv...")
run(
[
"git",
"clone",
"--quiet",
"--depth=1",
"https://github.com/libuv/libuv.git",
libuv_repo,
]
)

print("Getting tags...")
run(["git", "fetch", "--quiet", "--depth=1", "--tags"], cwd=libuv_repo)

print("Checking out libuv v" + libuv_version + "...")
try:
run(
["git", "checkout", "--quiet", "v" + libuv_version],
cwd=libuv_repo,
check=True,
)
except CalledProcessError:
print("Failed to checkout libuv: v" + libuv_version)
remove_dir(libuv_repo)
exit(1)

print("Copying header and source files...")
clean_dir(LIBUV_DIR)
move("src", libuv_repo, LIBUV_DIR)
move("include", libuv_repo, LIBUV_DIR)
remove_dir(libuv_repo)

print("Storing version information...")
with open(path.join(LIBUV_DIR, "version.md"), "w") as writer:
writer.write(libuv_version + " release")


main(sys.argv)
32 changes: 32 additions & 0 deletions util/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import os.path
import platform
import shutil
import subprocess
import sys


def clean_dir(dir):
"""If dir exists, deletes it and recreates it, otherwise creates it."""
if os.path.isdir(dir):
remove_dir(dir)

os.makedirs(dir)


def ensure_dir(dir):
"""Creates dir if not already there."""
if os.path.isdir(dir):
return

os.makedirs(dir)


def remove_dir(dir):
"""Recursively removes dir."""
if platform.system() == "Windows":
# rmtree gives up on readonly files on Windows
# rd doesn't like paths with forward slashes
subprocess.check_call(["cmd", "/c", "rd", "/s", "/q", dir.replace("/", "\\")])
else:
shutil.rmtree(dir)

0 comments on commit 1f3625c

Please sign in to comment.