wrap: Make 'directory' key optional

wrap files can now omit the 'directory' key, in that case it will
default to the packagename.
pull/4327/head
Xavier Claessens 6 years ago
parent d9ea7b16a8
commit 76ac4f5689
  1. 43
      mesonbuild/wrap/wrap.py

@ -114,18 +114,18 @@ class Resolver:
self.wrap = self.load_wrap() self.wrap = self.load_wrap()
if self.wrap and 'directory' in self.wrap.values: if self.wrap and 'directory' in self.wrap.values:
self.directory = self.wrap.get('directory') self.directory = self.wrap.get('directory')
dirname = os.path.join(self.subdir_root, self.directory) self.dirname = os.path.join(self.subdir_root, self.directory)
meson_file = os.path.join(dirname, 'meson.build') meson_file = os.path.join(self.dirname, 'meson.build')
# The directory is there and has meson.build? Great, use it. # The directory is there and has meson.build? Great, use it.
if os.path.exists(meson_file): if os.path.exists(meson_file):
return self.directory return self.directory
# Check if the subproject is a git submodule # Check if the subproject is a git submodule
self.resolve_git_submodule(dirname) self.resolve_git_submodule()
if os.path.exists(dirname): if os.path.exists(self.dirname):
if not os.path.isdir(dirname): if not os.path.isdir(self.dirname):
raise WrapException('Path already exists but is not a directory') raise WrapException('Path already exists but is not a directory')
else: else:
# A wrap file is required to download # A wrap file is required to download
@ -165,13 +165,13 @@ class Resolver:
m = 'Automatic wrap-based subproject downloading is disabled' m = 'Automatic wrap-based subproject downloading is disabled'
raise WrapException(m) raise WrapException(m)
def resolve_git_submodule(self, dirname): def resolve_git_submodule(self):
# Are we in a git repository? # Are we in a git repository?
ret, out = quiet_git(['rev-parse'], self.subdir_root) ret, out = quiet_git(['rev-parse'], self.subdir_root)
if not ret: if not ret:
return False return False
# Is `dirname` a submodule? # Is `dirname` a submodule?
ret, out = quiet_git(['submodule', 'status', dirname], self.subdir_root) ret, out = quiet_git(['submodule', 'status', self.dirname], self.subdir_root)
if not ret: if not ret:
return False return False
# Submodule has not been added, add it # Submodule has not been added, add it
@ -182,12 +182,12 @@ class Resolver:
raise WrapException('git submodule has merge conflicts') raise WrapException('git submodule has merge conflicts')
# Submodule exists, but is deinitialized or wasn't initialized # Submodule exists, but is deinitialized or wasn't initialized
elif out.startswith(b'-'): elif out.startswith(b'-'):
if subprocess.call(['git', '-C', self.subdir_root, 'submodule', 'update', '--init', dirname]) == 0: if subprocess.call(['git', '-C', self.subdir_root, 'submodule', 'update', '--init', self.dirname]) == 0:
return True return True
raise WrapException('git submodule failed to init') raise WrapException('git submodule failed to init')
# Submodule looks fine, but maybe it wasn't populated properly. Do a checkout. # Submodule looks fine, but maybe it wasn't populated properly. Do a checkout.
elif out.startswith(b' '): elif out.startswith(b' '):
subprocess.call(['git', 'checkout', '.'], cwd=dirname) subprocess.call(['git', 'checkout', '.'], cwd=self.dirname)
# Even if checkout failed, try building it anyway and let the user # Even if checkout failed, try building it anyway and let the user
# handle any problems manually. # handle any problems manually.
return True return True
@ -199,50 +199,47 @@ class Resolver:
def get_file(self): def get_file(self):
path = self.get_file_internal(self.wrap, 'source') path = self.get_file_internal(self.wrap, 'source')
target_dir = os.path.join(self.subdir_root, self.wrap.get('directory'))
extract_dir = self.subdir_root extract_dir = self.subdir_root
# Some upstreams ship packages that do not have a leading directory. # Some upstreams ship packages that do not have a leading directory.
# Create one for them. # Create one for them.
if 'lead_directory_missing' in self.wrap.values: if 'lead_directory_missing' in self.wrap.values:
os.mkdir(target_dir) os.mkdir(self.dirname)
extract_dir = target_dir extract_dir = self.dirname
shutil.unpack_archive(path, extract_dir) shutil.unpack_archive(path, extract_dir)
if self.wrap.has_patch(): if self.wrap.has_patch():
self.apply_patch() self.apply_patch()
def get_git(self): def get_git(self):
checkoutdir = os.path.join(self.subdir_root, self.wrap.get('directory'))
revno = self.wrap.get('revision') revno = self.wrap.get('revision')
if self.wrap.values.get('clone-recursive', '').lower() == 'true': if self.wrap.values.get('clone-recursive', '').lower() == 'true':
subprocess.check_call(['git', 'clone', '--recursive', self.wrap.get('url'), subprocess.check_call(['git', 'clone', '--recursive', self.wrap.get('url'),
self.wrap.get('directory')], cwd=self.subdir_root) self.directory], cwd=self.subdir_root)
else: else:
subprocess.check_call(['git', 'clone', self.wrap.get('url'), subprocess.check_call(['git', 'clone', self.wrap.get('url'),
self.wrap.get('directory')], cwd=self.subdir_root) self.directory], cwd=self.subdir_root)
if revno.lower() != 'head': if revno.lower() != 'head':
if subprocess.call(['git', 'checkout', revno], cwd=checkoutdir) != 0: if subprocess.call(['git', 'checkout', revno], cwd=self.dirname) != 0:
subprocess.check_call(['git', 'fetch', self.wrap.get('url'), revno], cwd=checkoutdir) subprocess.check_call(['git', 'fetch', self.wrap.get('url'), revno], cwd=self.dirname)
subprocess.check_call(['git', 'checkout', revno], subprocess.check_call(['git', 'checkout', revno],
cwd=checkoutdir) cwd=self.dirname)
push_url = self.wrap.values.get('push-url') push_url = self.wrap.values.get('push-url')
if push_url: if push_url:
subprocess.check_call(['git', 'remote', 'set-url', subprocess.check_call(['git', 'remote', 'set-url',
'--push', 'origin', push_url], '--push', 'origin', push_url],
cwd=checkoutdir) cwd=self.dirname)
def get_hg(self): def get_hg(self):
checkoutdir = os.path.join(self.subdir_root, self.wrap.get('directory'))
revno = self.wrap.get('revision') revno = self.wrap.get('revision')
subprocess.check_call(['hg', 'clone', self.wrap.get('url'), subprocess.check_call(['hg', 'clone', self.wrap.get('url'),
self.wrap.get('directory')], cwd=self.subdir_root) self.directory], cwd=self.subdir_root)
if revno.lower() != 'tip': if revno.lower() != 'tip':
subprocess.check_call(['hg', 'checkout', revno], subprocess.check_call(['hg', 'checkout', revno],
cwd=checkoutdir) cwd=self.dirname)
def get_svn(self): def get_svn(self):
revno = self.wrap.get('revision') revno = self.wrap.get('revision')
subprocess.check_call(['svn', 'checkout', '-r', revno, self.wrap.get('url'), subprocess.check_call(['svn', 'checkout', '-r', revno, self.wrap.get('url'),
self.wrap.get('directory')], cwd=self.subdir_root) self.directory], cwd=self.subdir_root)
def get_data(self, url): def get_data(self, url):
blocksize = 10 * 1024 blocksize = 10 * 1024

Loading…
Cancel
Save