diff options
Diffstat (limited to 'morphlib/builder.py')
-rw-r--r-- | morphlib/builder.py | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/morphlib/builder.py b/morphlib/builder.py index c980a276..166b790b 100644 --- a/morphlib/builder.py +++ b/morphlib/builder.py @@ -35,10 +35,11 @@ import morphlib.gitversion SYSTEM_INTEGRATION_PATH = os.path.join('baserock', 'system-integration') -def extract_sources(app, repo_cache, repo, sha1, srcdir): #pragma: no cover +def extract_sources(app, definitions_version, repo_cache, repo, sha1, + destdir, source): #pragma: no cover '''Get sources from git to a source directory, including submodules''' - def extract_repo(repo, sha1, destdir): + def extract_repo(repo, sha1, destdir, submodules_map=None): app.status(msg='Extracting %(source)s into %(target)s', source=repo.original_name, target=destdir) @@ -53,16 +54,27 @@ def extract_sources(app, repo_cache, repo, sha1, srcdir): #pragma: no cover else: tuples = [] for sub in submodules: - cached_repo = repo_cache.get_updated_repo(sub.url, sub.commit) + if submodules_map and sub.name in submodules_map: + url = submodules_map[sub.name]['url'] + else: + url = sub.url + cached_repo = repo_cache.get_updated_repo(url, sub.commit) sub_dir = os.path.join(destdir, sub.path) tuples.append((cached_repo, sub.commit, sub_dir)) return tuples - todo = [(repo, sha1, srcdir)] - while todo: - repo, sha1, srcdir = todo.pop() - todo += extract_repo(repo, sha1, srcdir) - set_mtime_recursively(srcdir) + if definitions_version >= 8: + todo = [(repo, sha1, destdir)] + while todo: + repo, sha1, destdir = todo.pop() + todo += extract_repo(repo, sha1, destdir, source.submodules) + else: + todo = [(repo, sha1, destdir)] + while todo: + repo, sha1, destdir = todo.pop() + todo += extract_repo(repo, sha1, destdir) + + set_mtime_recursively(destdir) def set_mtime_recursively(root): # pragma: no cover '''Set the mtime for every file in a directory tree to the same. @@ -147,7 +159,7 @@ class BuilderBase(object): def __init__(self, app, staging_area, local_artifact_cache, remote_artifact_cache, source, repo_cache, max_jobs, - setup_mounts): + setup_mounts, definitions_version): self.app = app self.staging_area = staging_area self.local_artifact_cache = local_artifact_cache @@ -157,6 +169,7 @@ class BuilderBase(object): self.max_jobs = max_jobs self.build_watch = morphlib.stopwatch.Stopwatch() self.setup_mounts = setup_mounts + self.definitions_version = definitions_version def save_build_times(self): '''Write the times captured by the stopwatch''' @@ -374,7 +387,6 @@ class ChunkBuilder(BuilderBase): stderr=subprocess.STDOUT, logfile=logfilepath, ccache_dir=ccache_dir) - if stdout: stdout.flush() @@ -490,7 +502,8 @@ class ChunkBuilder(BuilderBase): def get_sources(self, srcdir): # pragma: no cover s = self.source - extract_sources(self.app, self.repo_cache, s.repo, s.sha1, srcdir) + extract_sources(self.app, self.definitions_version, self.repo_cache, + s.repo, s.sha1, srcdir, s) class StratumBuilder(BuilderBase): @@ -725,7 +738,8 @@ class Builder(object): # pragma: no cover } def __init__(self, app, staging_area, local_artifact_cache, - remote_artifact_cache, repo_cache, max_jobs, setup_mounts): + remote_artifact_cache, repo_cache, max_jobs, setup_mounts, + definitions_version): self.app = app self.staging_area = staging_area self.local_artifact_cache = local_artifact_cache @@ -733,6 +747,7 @@ class Builder(object): # pragma: no cover self.repo_cache = repo_cache self.max_jobs = max_jobs self.setup_mounts = setup_mounts + self.definitions_version = definitions_version def build_and_cache(self, source): kind = source.morphology['kind'] @@ -740,7 +755,8 @@ class Builder(object): # pragma: no cover self.local_artifact_cache, self.remote_artifact_cache, source, self.repo_cache, self.max_jobs, - self.setup_mounts) + self.setup_mounts, + self.definitions_version) self.app.status(msg='Builder.build: artifact %s with %s' % (source.name, repr(o)), chatty=True) |