ostbuild: Unify mirrordir lookup code
This commit is contained in:
parent
1d93adc925
commit
df92b8d46f
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import urlparse
|
||||||
|
|
||||||
from .subprocess_helpers import run_sync_get_output
|
from .subprocess_helpers import run_sync_get_output
|
||||||
|
|
||||||
|
|
@ -31,6 +32,11 @@ BUILD_ENV = {
|
||||||
'TZ': 'EST5EDT'
|
'TZ': 'EST5EDT'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def get_mirrordir(mirrordir, keytype, uri, prefix=''):
|
||||||
|
assert keytype == 'git'
|
||||||
|
parsed = urlparse.urlsplit(uri)
|
||||||
|
return os.path.join(mirrordir, prefix, keytype, parsed.scheme, parsed.netloc, parsed.path[1:])
|
||||||
|
|
||||||
def find_user_chroot_path():
|
def find_user_chroot_path():
|
||||||
# We need to search PATH here manually so we correctly pick up an
|
# We need to search PATH here manually so we correctly pick up an
|
||||||
# ostree install in e.g. ~/bin even though we're going to set PATH
|
# ostree install in e.g. ~/bin even though we're going to set PATH
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,6 @@ class OstbuildBuild(builtins.Builtin):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
builtins.Builtin.__init__(self)
|
builtins.Builtin.__init__(self)
|
||||||
|
|
||||||
def _mirror_for_url(self, url):
|
|
||||||
parsed = urlparse.urlsplit(url)
|
|
||||||
return os.path.join(self.mirrordir, 'git', parsed.scheme, parsed.netloc, parsed.path[1:])
|
|
||||||
|
|
||||||
def _fixup_submodule_references(self, cwd):
|
def _fixup_submodule_references(self, cwd):
|
||||||
submodules_status_text = run_sync_get_output(['git', 'submodule', 'status'], cwd=cwd)
|
submodules_status_text = run_sync_get_output(['git', 'submodule', 'status'], cwd=cwd)
|
||||||
submodule_status_lines = submodules_status_text.split('\n')
|
submodule_status_lines = submodules_status_text.split('\n')
|
||||||
|
|
@ -56,7 +52,7 @@ class OstbuildBuild(builtins.Builtin):
|
||||||
(sub_checksum, sub_name) = line.split(' ', 1)
|
(sub_checksum, sub_name) = line.split(' ', 1)
|
||||||
sub_url = run_sync_get_output(['git', 'config', '-f', '.gitmodules',
|
sub_url = run_sync_get_output(['git', 'config', '-f', '.gitmodules',
|
||||||
'submodule.%s.url' % (sub_name, )], cwd=cwd)
|
'submodule.%s.url' % (sub_name, )], cwd=cwd)
|
||||||
mirrordir = self._mirror_for_url(sub_url)
|
mirrordir = buildutil.get_mirrordir(self.mirrordir, 'git', sub_url)
|
||||||
run_sync(['git', 'config', 'submodule.%s.url' % (sub_name, ), 'file://' + mirrordir], cwd=cwd)
|
run_sync(['git', 'config', 'submodule.%s.url' % (sub_name, ), 'file://' + mirrordir], cwd=cwd)
|
||||||
return have_submodules
|
return have_submodules
|
||||||
|
|
||||||
|
|
@ -185,7 +181,7 @@ class OstbuildBuild(builtins.Builtin):
|
||||||
|
|
||||||
(keytype, uri) = self._parse_src_key(meta['src'])
|
(keytype, uri) = self._parse_src_key(meta['src'])
|
||||||
|
|
||||||
mirror = self._mirror_for_url(uri)
|
mirror = buildutil.get_mirrordir(self.mirrordir, keytype, uri)
|
||||||
component_src = self._get_vcs_checkout(name, keytype, mirror, branch,
|
component_src = self._get_vcs_checkout(name, keytype, mirror, branch,
|
||||||
overwrite=not self.args.debug_shell)
|
overwrite=not self.args.debug_shell)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,13 +36,8 @@ class OstbuildResolve(builtins.Builtin):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
builtins.Builtin.__init__(self)
|
builtins.Builtin.__init__(self)
|
||||||
|
|
||||||
def _get_mirrordir(self, keytype, uri, prefix=''):
|
|
||||||
assert keytype == 'git'
|
|
||||||
parsed = urlparse.urlsplit(uri)
|
|
||||||
return os.path.join(self.mirrordir, prefix, keytype, parsed.scheme, parsed.netloc, parsed.path[1:])
|
|
||||||
|
|
||||||
def _ensure_vcs_mirror(self, name, keytype, uri, branch):
|
def _ensure_vcs_mirror(self, name, keytype, uri, branch):
|
||||||
mirror = self._get_mirrordir(keytype, uri)
|
mirror = buildutil.get_mirrordir(self.mirrordir, keytype, uri)
|
||||||
tmp_mirror = mirror + '.tmp'
|
tmp_mirror = mirror + '.tmp'
|
||||||
if os.path.isdir(tmp_mirror):
|
if os.path.isdir(tmp_mirror):
|
||||||
shutil.rmtree(tmp_mirror)
|
shutil.rmtree(tmp_mirror)
|
||||||
|
|
@ -62,7 +57,7 @@ class OstbuildResolve(builtins.Builtin):
|
||||||
current_vcs_version = current_vcs_version.strip()
|
current_vcs_version = current_vcs_version.strip()
|
||||||
if current_vcs_version != last_fetch_contents:
|
if current_vcs_version != last_fetch_contents:
|
||||||
log("last fetch %r differs from branch %r" % (last_fetch_contents, current_vcs_version))
|
log("last fetch %r differs from branch %r" % (last_fetch_contents, current_vcs_version))
|
||||||
tmp_checkout = self._get_mirrordir(keytype, uri, prefix='_tmp-checkouts')
|
tmp_checkout = buildutil.get_mirrordir(self.mirrordir, keytype, uri, prefix='_tmp-checkouts')
|
||||||
if os.path.isdir(tmp_checkout):
|
if os.path.isdir(tmp_checkout):
|
||||||
shutil.rmtree(tmp_checkout)
|
shutil.rmtree(tmp_checkout)
|
||||||
parent = os.path.dirname(tmp_checkout)
|
parent = os.path.dirname(tmp_checkout)
|
||||||
|
|
@ -168,7 +163,7 @@ class OstbuildResolve(builtins.Builtin):
|
||||||
name = component['name']
|
name = component['name']
|
||||||
try:
|
try:
|
||||||
fetch_components.index(name)
|
fetch_components.index(name)
|
||||||
mirrordir = self._get_mirrordir(keytype, uri)
|
mirrordir = buildutil.get_mirrordir(self.mirrordir, keytype, uri)
|
||||||
except ValueError, e:
|
except ValueError, e:
|
||||||
mirrordir = self._ensure_vcs_mirror(name, keytype, uri, component['branch'])
|
mirrordir = self._ensure_vcs_mirror(name, keytype, uri, component['branch'])
|
||||||
revision = buildutil.get_git_version_describe(mirrordir,
|
revision = buildutil.get_git_version_describe(mirrordir,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue