summaryrefslogtreecommitdiff
path: root/ghwt.py
diff options
context:
space:
mode:
authorKyle Stone <kyle.stone@is4s.com>2020-01-28 16:37:38 -0500
committerKyle Stone <kyle.stone@is4s.com>2020-01-28 19:00:39 -0500
commitf9a31a25db5a9a08a5b102c6289029beddc7b07a (patch)
treec347646dddc5dc2a5585115e99fe96bac8ebabc4 /ghwt.py
parentbec46cc141eaa139840a4ad3f15c47549b3ed432 (diff)
downloadmeson-f9a31a25db5a9a08a5b102c6289029beddc7b07a.tar.gz
Put subprojects into folder specified by upstream wrap.
Diffstat (limited to 'ghwt.py')
-rwxr-xr-xghwt.py35
1 files changed, 19 insertions, 16 deletions
diff --git a/ghwt.py b/ghwt.py
index 7c2a6d16f..a030a1153 100755
--- a/ghwt.py
+++ b/ghwt.py
@@ -24,6 +24,7 @@ import configparser, hashlib
req_timeout = 600.0
private_repos = {'meson', 'wrapweb', 'meson-ci'}
+spdir = 'subprojects'
def gh_get(url):
r = urllib.request.urlopen(url, timeout=req_timeout)
@@ -39,12 +40,21 @@ def list_projects():
print(i)
return 0
-def unpack(sproj, branch, outdir):
- subprocess.check_call(['git', 'clone', '-b', branch, 'https://github.com/mesonbuild/{}.git'.format(sproj), outdir])
- usfile = os.path.join(outdir, 'upstream.wrap')
+def unpack(sproj, branch):
+ tmpdir = os.path.join(spdir, sproj + '_ghwt')
+ shutil.rmtree(tmpdir, ignore_errors=True)
+ subprocess.check_call(['git', 'clone', '-b', branch, 'https://github.com/mesonbuild/{}.git'.format(sproj), tmpdir])
+ usfile = os.path.join(tmpdir, 'upstream.wrap')
assert(os.path.isfile(usfile))
config = configparser.ConfigParser(interpolation=None)
config.read(usfile)
+ outdir = os.path.join(spdir, sproj)
+ if 'directory' in config['wrap-file']:
+ outdir = os.path.join(spdir, config['wrap-file']['directory'])
+ if os.path.isdir(outdir):
+ print('Subproject is already there. To update, nuke the {} dir and reinstall.'.format(outdir))
+ shutil.rmtree(tmpdir)
+ return 1
us_url = config['wrap-file']['source_url']
us = urllib.request.urlopen(us_url, timeout=req_timeout).read()
h = hashlib.sha256()
@@ -56,7 +66,6 @@ def unpack(sproj, branch, outdir):
print(' expected:', should)
print(' obtained:', dig)
return 1
- spdir = os.path.dirname(outdir)
ofilename = os.path.join(spdir, config['wrap-file']['source_filename'])
with open(ofilename, 'wb') as ofile:
ofile.write(us)
@@ -65,30 +74,24 @@ def unpack(sproj, branch, outdir):
shutil.unpack_archive(ofilename, outdir)
else:
shutil.unpack_archive(ofilename, spdir)
- extdir = os.path.join(spdir, config['wrap-file']['directory'])
- assert(os.path.isdir(extdir))
- shutil.move(os.path.join(outdir, '.git'), extdir)
- subprocess.check_call(['git', 'reset', '--hard'], cwd=extdir)
- shutil.rmtree(outdir)
- shutil.move(extdir, outdir)
+ assert(os.path.isdir(outdir))
+ shutil.move(os.path.join(tmpdir, '.git'), outdir)
+ subprocess.check_call(['git', 'reset', '--hard'], cwd=outdir)
+ shutil.rmtree(tmpdir)
shutil.rmtree(os.path.join(outdir, '.git'))
os.unlink(ofilename)
def install(sproj):
- sproj_dir = os.path.join('subprojects', sproj)
- if not os.path.isdir('subprojects'):
+ if not os.path.isdir(spdir):
print('Run this in your source root and make sure there is a subprojects directory in it.')
return 1
- if os.path.isdir(sproj_dir):
- print('Subproject is already there. To update, nuke the dir and reinstall.')
- return 1
blist = gh_get('https://api.github.com/repos/mesonbuild/{}/branches'.format(sproj))
blist = [b['name'] for b in blist]
blist = [b for b in blist if b != 'master']
blist.sort()
branch = blist[-1]
print('Using branch', branch)
- return unpack(sproj, branch, sproj_dir)
+ return unpack(sproj, branch)
def run(args):
if not args or args[0] == '-h' or args[0] == '--help':