aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/wrap/wrap.py
diff options
context:
space:
mode:
authorMichael Hirsch, Ph.D <scivision@users.noreply.github.com>2019-11-26 23:23:08 -0500
committerMichael Hirsch, Ph.D <scivision@users.noreply.github.com>2019-12-05 23:07:18 -0500
commitdc19768175685586dbb08940ab804a5402bbc279 (patch)
tree200cbec6f212d2d65ef973ecef676be073c55ba9 /mesonbuild/wrap/wrap.py
parent0494a763402eada02bdd4d5c211816ac73745eb2 (diff)
downloadmeson-dc19768175685586dbb08940ab804a5402bbc279.zip
meson-dc19768175685586dbb08940ab804a5402bbc279.tar.gz
meson-dc19768175685586dbb08940ab804a5402bbc279.tar.bz2
wrap: raise WrapException instead of Python exception when program not available
Diffstat (limited to 'mesonbuild/wrap/wrap.py')
-rw-r--r--mesonbuild/wrap/wrap.py59
1 files changed, 36 insertions, 23 deletions
diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py
index 0b1903f..a95cfd2 100644
--- a/mesonbuild/wrap/wrap.py
+++ b/mesonbuild/wrap/wrap.py
@@ -51,11 +51,11 @@ masquerade_str = 'wrapdb.mesonbuild.com'
def quiet_git(cmd: typing.List[str], workingdir: str) -> typing.Tuple[bool, str]:
- try:
- pc = subprocess.run(['git', '-C', workingdir] + cmd, universal_newlines=True,
- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- except FileNotFoundError as e:
- return False, str(e)
+ git = shutil.which('git')
+ if not git:
+ return False, 'Git program not found.'
+ pc = subprocess.run([git, '-C', workingdir] + cmd, universal_newlines=True,
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if pc.returncode != 0:
return False, pc.stderr
return True, pc.stdout
@@ -195,6 +195,9 @@ class Resolver:
raise WrapException(m)
def resolve_git_submodule(self) -> bool:
+ git = shutil.which('git')
+ if not git:
+ raise WrapException('Git program not found.')
# Are we in a git repository?
ret, out = quiet_git(['rev-parse'], self.subdir_root)
if not ret:
@@ -211,12 +214,13 @@ class Resolver:
raise WrapException('git submodule has merge conflicts')
# Submodule exists, but is deinitialized or wasn't initialized
elif out.startswith('-'):
- if subprocess.call(['git', '-C', self.subdir_root, 'submodule', 'update', '--init', self.dirname]) == 0:
+ if subprocess.run([git, '-C', self.subdir_root,
+ 'submodule', 'update', '--init', self.dirname]).returncode == 0:
return True
raise WrapException('git submodule failed to init')
# Submodule looks fine, but maybe it wasn't populated properly. Do a checkout.
elif out.startswith(' '):
- subprocess.call(['git', 'checkout', '.'], cwd=self.dirname)
+ subprocess.run([git, 'checkout', '.'], cwd=self.dirname)
# Even if checkout failed, try building it anyway and let the user
# handle any problems manually.
return True
@@ -239,6 +243,9 @@ class Resolver:
self.apply_patch()
def get_git(self) -> None:
+ git = shutil.which('git')
+ if not git:
+ raise WrapException('Git program not found.')
revno = self.wrap.get('revision')
is_shallow = False
depth_option = [] # type: typing.List[str]
@@ -249,42 +256,42 @@ class Resolver:
if is_shallow and self.is_git_full_commit_id(revno):
# git doesn't support directly cloning shallowly for commits,
# so we follow https://stackoverflow.com/a/43136160
- subprocess.check_call(['git', 'init', self.directory], cwd=self.subdir_root)
- subprocess.check_call(['git', 'remote', 'add', 'origin', self.wrap.get('url')],
+ subprocess.check_call([git, 'init', self.directory], cwd=self.subdir_root)
+ subprocess.check_call([git, 'remote', 'add', 'origin', self.wrap.get('url')],
cwd=self.dirname)
revno = self.wrap.get('revision')
- subprocess.check_call(['git', 'fetch', *depth_option, 'origin', revno],
+ subprocess.check_call([git, 'fetch', *depth_option, 'origin', revno],
cwd=self.dirname)
- subprocess.check_call(['git', 'checkout', revno], cwd=self.dirname)
+ subprocess.check_call([git, 'checkout', revno], cwd=self.dirname)
if self.wrap.values.get('clone-recursive', '').lower() == 'true':
- subprocess.check_call(['git', 'submodule', 'update',
+ subprocess.check_call([git, 'submodule', 'update',
'--init', '--checkout', '--recursive', *depth_option],
cwd=self.dirname)
push_url = self.wrap.values.get('push-url')
if push_url:
- subprocess.check_call(['git', 'remote', 'set-url',
+ subprocess.check_call([git, 'remote', 'set-url',
'--push', 'origin', push_url],
cwd=self.dirname)
else:
if not is_shallow:
- subprocess.check_call(['git', 'clone', self.wrap.get('url'),
+ subprocess.check_call([git, 'clone', self.wrap.get('url'),
self.directory], cwd=self.subdir_root)
if revno.lower() != 'head':
- if subprocess.call(['git', 'checkout', revno], cwd=self.dirname) != 0:
- subprocess.check_call(['git', 'fetch', self.wrap.get('url'), revno], cwd=self.dirname)
- subprocess.check_call(['git', 'checkout', revno], cwd=self.dirname)
+ if subprocess.run([git, 'checkout', revno], cwd=self.dirname).returncode != 0:
+ subprocess.check_call([git, 'fetch', self.wrap.get('url'), revno], cwd=self.dirname)
+ subprocess.check_call([git, 'checkout', revno], cwd=self.dirname)
else:
- subprocess.check_call(['git', 'clone', *depth_option,
+ subprocess.check_call([git, 'clone', *depth_option,
'--branch', revno,
self.wrap.get('url'),
self.directory], cwd=self.subdir_root)
if self.wrap.values.get('clone-recursive', '').lower() == 'true':
- subprocess.check_call(['git', 'submodule', 'update',
+ subprocess.check_call([git, 'submodule', 'update',
'--init', '--checkout', '--recursive', *depth_option],
cwd=self.dirname)
push_url = self.wrap.values.get('push-url')
if push_url:
- subprocess.check_call(['git', 'remote', 'set-url',
+ subprocess.check_call([git, 'remote', 'set-url',
'--push', 'origin', push_url],
cwd=self.dirname)
@@ -296,15 +303,21 @@ class Resolver:
def get_hg(self) -> None:
revno = self.wrap.get('revision')
- subprocess.check_call(['hg', 'clone', self.wrap.get('url'),
+ hg = shutil.which('hg')
+ if not hg:
+ raise WrapException('Mercurial program not found.')
+ subprocess.check_call([hg, 'clone', self.wrap.get('url'),
self.directory], cwd=self.subdir_root)
if revno.lower() != 'tip':
- subprocess.check_call(['hg', 'checkout', revno],
+ subprocess.check_call([hg, 'checkout', revno],
cwd=self.dirname)
def get_svn(self) -> None:
revno = self.wrap.get('revision')
- subprocess.check_call(['svn', 'checkout', '-r', revno, self.wrap.get('url'),
+ svn = shutil.which('svn')
+ if not svn:
+ raise WrapException('SVN program not found.')
+ subprocess.check_call([svn, 'checkout', '-r', revno, self.wrap.get('url'),
self.directory], cwd=self.subdir_root)
def get_data(self, url: str) -> typing.Tuple[str, str]: