Put subprojects into folder specified by upstream wrap.

pull/6537/head
Kyle Stone 5 years ago
parent bec46cc141
commit f9a31a25db
  1. 35
      ghwt.py

@ -24,6 +24,7 @@ import configparser, hashlib
req_timeout = 600.0 req_timeout = 600.0
private_repos = {'meson', 'wrapweb', 'meson-ci'} private_repos = {'meson', 'wrapweb', 'meson-ci'}
spdir = 'subprojects'
def gh_get(url): def gh_get(url):
r = urllib.request.urlopen(url, timeout=req_timeout) r = urllib.request.urlopen(url, timeout=req_timeout)
@ -39,12 +40,21 @@ def list_projects():
print(i) print(i)
return 0 return 0
def unpack(sproj, branch, outdir): def unpack(sproj, branch):
subprocess.check_call(['git', 'clone', '-b', branch, 'https://github.com/mesonbuild/{}.git'.format(sproj), outdir]) tmpdir = os.path.join(spdir, sproj + '_ghwt')
usfile = os.path.join(outdir, 'upstream.wrap') 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)) assert(os.path.isfile(usfile))
config = configparser.ConfigParser(interpolation=None) config = configparser.ConfigParser(interpolation=None)
config.read(usfile) 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_url = config['wrap-file']['source_url']
us = urllib.request.urlopen(us_url, timeout=req_timeout).read() us = urllib.request.urlopen(us_url, timeout=req_timeout).read()
h = hashlib.sha256() h = hashlib.sha256()
@ -56,7 +66,6 @@ def unpack(sproj, branch, outdir):
print(' expected:', should) print(' expected:', should)
print(' obtained:', dig) print(' obtained:', dig)
return 1 return 1
spdir = os.path.dirname(outdir)
ofilename = os.path.join(spdir, config['wrap-file']['source_filename']) ofilename = os.path.join(spdir, config['wrap-file']['source_filename'])
with open(ofilename, 'wb') as ofile: with open(ofilename, 'wb') as ofile:
ofile.write(us) ofile.write(us)
@ -65,30 +74,24 @@ def unpack(sproj, branch, outdir):
shutil.unpack_archive(ofilename, outdir) shutil.unpack_archive(ofilename, outdir)
else: else:
shutil.unpack_archive(ofilename, spdir) shutil.unpack_archive(ofilename, spdir)
extdir = os.path.join(spdir, config['wrap-file']['directory']) assert(os.path.isdir(outdir))
assert(os.path.isdir(extdir)) shutil.move(os.path.join(tmpdir, '.git'), outdir)
shutil.move(os.path.join(outdir, '.git'), extdir) subprocess.check_call(['git', 'reset', '--hard'], cwd=outdir)
subprocess.check_call(['git', 'reset', '--hard'], cwd=extdir) shutil.rmtree(tmpdir)
shutil.rmtree(outdir)
shutil.move(extdir, outdir)
shutil.rmtree(os.path.join(outdir, '.git')) shutil.rmtree(os.path.join(outdir, '.git'))
os.unlink(ofilename) os.unlink(ofilename)
def install(sproj): def install(sproj):
sproj_dir = os.path.join('subprojects', sproj) if not os.path.isdir(spdir):
if not os.path.isdir('subprojects'):
print('Run this in your source root and make sure there is a subprojects directory in it.') print('Run this in your source root and make sure there is a subprojects directory in it.')
return 1 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 = gh_get('https://api.github.com/repos/mesonbuild/{}/branches'.format(sproj))
blist = [b['name'] for b in blist] blist = [b['name'] for b in blist]
blist = [b for b in blist if b != 'master'] blist = [b for b in blist if b != 'master']
blist.sort() blist.sort()
branch = blist[-1] branch = blist[-1]
print('Using branch', branch) print('Using branch', branch)
return unpack(sproj, branch, sproj_dir) return unpack(sproj, branch)
def run(args): def run(args):
if not args or args[0] == '-h' or args[0] == '--help': if not args or args[0] == '-h' or args[0] == '--help':

Loading…
Cancel
Save