aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/wrap/wrap.py
diff options
context:
space:
mode:
Diffstat (limited to 'mesonbuild/wrap/wrap.py')
-rw-r--r--mesonbuild/wrap/wrap.py30
1 files changed, 27 insertions, 3 deletions
diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py
index e05c641..19ed39a 100644
--- a/mesonbuild/wrap/wrap.py
+++ b/mesonbuild/wrap/wrap.py
@@ -93,9 +93,19 @@ class Resolver:
def resolve(self, packagename):
fname = os.path.join(self.subdir_root, packagename + '.wrap')
dirname = os.path.join(self.subdir_root, packagename)
- if os.path.isdir(dirname):
- # The directory is there? Great, use it.
- return packagename
+ try:
+ if os.listdir(dirname):
+ # The directory is there and not empty? Great, use it.
+ return packagename
+ else:
+ mlog.warning('Subproject directory %s is empty, possibly because of an unfinished'
+ 'checkout, removing to reclone' % dirname)
+ os.rmdir(checkoutdir)
+ except NotADirectoryError:
+ raise RuntimeError('%s is not a directory, can not use as subproject.' % dirname)
+ except FileNotFoundError:
+ pass
+
if not os.path.isfile(fname):
# No wrap file with this name? Give up.
return None
@@ -118,6 +128,15 @@ class Resolver:
revno = p.get('revision')
is_there = os.path.isdir(checkoutdir)
if is_there:
+ try:
+ subprocess.check_call(['git', 'rev-parse'])
+ is_there = True
+ except subprocess.CalledProcessError:
+ raise RuntimeError('%s is not empty but is not a valid '
+ 'git repository, we can not work with it'
+ ' as a subproject directory.' % (
+ checkoutdir))
+
if revno.lower() == 'head':
# Failure to do pull is not a fatal error,
# because otherwise you can't develop without
@@ -134,6 +153,11 @@ class Resolver:
if revno.lower() != 'head':
subprocess.check_call(['git', 'checkout', revno],
cwd=checkoutdir)
+ push_url = p.get('push-url')
+ if push_url:
+ subprocess.check_call(['git', 'remote', 'set-url',
+ '--push', 'origin', push_url],
+ cwd=checkoutdir)
def get_hg(self, p):
checkoutdir = os.path.join(self.subdir_root, p.get('directory'))
revno = p.get('revision')