diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-02-16 17:38:05 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-02-16 18:11:41 +0000 |
commit | 4efaa7431b29d5992bc8173e1671b657d27485a8 (patch) | |
tree | 9a5628d54b9cebf0faa7e4ca03b55cc72e8c2667 | |
parent | de9a3a22da70f3ae502fb5d50483954976e7ed68 (diff) | |
download | morph-4efaa7431b29d5992bc8173e1671b657d27485a8.tar.gz |
WIP: remove artifact serialisation from distbuild
Conflicts:
morphlib/plugins/distbuild_plugin.py
-rw-r--r-- | distbuild/build_controller.py | 3 | ||||
-rw-r--r-- | distbuild/worker_build_scheduler.py | 45 | ||||
-rw-r--r-- | morphlib/buildcommand.py | 6 | ||||
-rw-r--r-- | morphlib/plugins/distbuild_plugin.py | 44 |
4 files changed, 78 insertions, 20 deletions
diff --git a/distbuild/build_controller.py b/distbuild/build_controller.py index aa11ae8f..f363c31c 100644 --- a/distbuild/build_controller.py +++ b/distbuild/build_controller.py @@ -423,7 +423,8 @@ class BuildController(distbuild.StateMachine): logging.debug( 'Requesting worker-build of %s (%s)' % (artifact.name, artifact.source.cache_key)) - request = distbuild.WorkerBuildRequest(artifact, + request = distbuild.WorkerBuildRequest(self._artifact, + artifact, self._request['id']) self.mainloop.queue_event(distbuild.WorkerBuildQueuer, request) diff --git a/distbuild/worker_build_scheduler.py b/distbuild/worker_build_scheduler.py index ea676271..833d5587 100644 --- a/distbuild/worker_build_scheduler.py +++ b/distbuild/worker_build_scheduler.py @@ -28,7 +28,8 @@ import distbuild class WorkerBuildRequest(object): - def __init__(self, artifact, initiator_id): + def __init__(self, root_artifact, artifact, initiator_id): + self.root_artifact = root_artifact self.artifact = artifact self.initiator_id = initiator_id @@ -95,8 +96,10 @@ class _HaveAJob(object): class Job(object): - def __init__(self, job_id, artifact, initiator_id): + def __init__(self, job_id, root_artifact, artifact, initiator_id): self.id = job_id + + self.root_artifact = root_artifact self.artifact = artifact self.initiators = [initiator_id] self.who = None # we don't know who's going to do this yet @@ -114,8 +117,8 @@ class Jobs(object): return (self._jobs[artifact_basename] if artifact_basename in self._jobs else None) - def create(self, artifact, initiator_id): - job = Job(self._idgen.next(), artifact, initiator_id) + def create(self, root_artifact, artifact, initiator_id): + job = Job(self._idgen.next(), root_artifact, artifact, initiator_id) self._jobs[job.artifact.basename()] = job return job @@ -273,7 +276,7 @@ class WorkerBuildQueuer(distbuild.StateMachine): self.mainloop.queue_event(WorkerConnection, progress) else: logging.debug('WBQ: Creating job for: %s' % event.artifact.name) - job = self._jobs.create(event.artifact, event.initiator_id) + job = self._jobs.create(event.root_artifact, event.artifact, event.initiator_id) if self._available_workers: self._give_job(job) @@ -462,19 +465,45 @@ class WorkerConnection(distbuild.StateMachine): self._helper_id = None self._exec_response_msg = None + job = event.job + logging.debug('WC: starting build: %s for %s' % - (self._job.artifact.name, self._job.initiators)) + (job.artifact.name, job.initiators)) argv = [ self._morph_instance, 'worker-build', '--build-log-on-stdout', - self._job.artifact.name, ] + + repo = job.root_artifact.repo_name + original_ref = job.root_artifact.original_ref + sha1 = job.root_artifact.sha1 + system_morph = job.root_artifact.filename + + argv.extend([definitions_repo, repo, original_ref, sha1, system_morph]) + + def find_stratum_for_chunk_artifact(root_artifact, chunk): + # FIXME: This is horribly inefficient. + strata = {a.source for a in root_artifact.walk() + if a.source.kind == 'source'} + for stratum in strata: + for dep in stratum.dependencies: + if dep.source.kind == 'chunk' and dep.source == chunk: + return stratum + raise KeyError('Didn\'t find stratum for chunk %s' % chunk) + + if job.artifact.source.kind == 'stratum': + argv.append(job.artifact.source.name) + elif job.artifact.source.kind == 'chunk': + stratum = find_stratum_for_chunk_artifact(job.root_artifact, + job.artifact) + argv.append(stratum.name) + argv.append(job.artifact.source.name) + msg = distbuild.message('exec-request', id=self._job.id, argv=argv, - stdin_contents=distbuild.serialise_artifact(self._job.artifact), ) self._jm.send(msg) diff --git a/morphlib/buildcommand.py b/morphlib/buildcommand.py index 55716331..45101d2c 100644 --- a/morphlib/buildcommand.py +++ b/morphlib/buildcommand.py @@ -340,6 +340,12 @@ class BuildCommand(object): deps = morphlib.artifact.find_all_deps(source.artifacts.values()) + # TEMPORARY!!!!: stub out the build and return + for basename in source.files(): + with self.lac.put_file(basename) as f: + f.write('Nonsense data.\n') + return + use_chroot = False setup_mounts = False if source.morphology['kind'] == 'chunk': diff --git a/morphlib/plugins/distbuild_plugin.py b/morphlib/plugins/distbuild_plugin.py index 4ac80b17..c5dd3718 100644 --- a/morphlib/plugins/distbuild_plugin.py +++ b/morphlib/plugins/distbuild_plugin.py @@ -92,20 +92,41 @@ class WorkerBuild(cliapp.Plugin): and available in the local or remote artifact cache. ''' - + + if len(args) not in [4,5,6]: + raise cliapp.AppException( + 'worker-build command requires 4 to 6 arguments: REPO ' + 'ORIGINAL_REF SHA1 SYSTEM_MORPH [STRATUM_NAME [CHUNK_NAME]]') + distbuild.add_crash_conditions(self.app.settings['crash-condition']) - serialized = sys.stdin.readline() - artifact = distbuild.deserialise_artifact(serialized) + repo_name, original_ref, sha1, system_morph = args[0:4] - bc = morphlib.buildcommand.BuildCommand(self.app) + stratum_name = args[4] if len(args) >= 5 else None + chunk_name = args[5] if len(args) == 6 else None - # Just show the chunk name. - self.app.status(msg='NAME: %s' % artifact.source.name) + bc = morphlib.buildcommand.BuildCommand(self.app) - for basename in artifact.source.files(): - with bc.lac.put_file(basename) as f: - f.write('Nonsense data.\n') + # FIXME: this overlaps with BuildCommand.build() and should be merged + # with it somehow. + srcpool = bc.create_source_pool(repo_name, sha1, system_morph, + original_ref=original_ref) + bc.validate_sources(srcpool) + root_artifact = self.resolve_artifacts(srcpool) + + def find_source(tree, kind, name): + for a in tree.walk(): + if a.source.kind == kind and a.source.name == name: + return a + raise KeyError( + 'Didn\'t find %s name %s in build graph.' % (kind, name)) + + if chunk_name: + to_build = find_source(root_artifact, 'chunk', chunk_name) + elif stratum_name: + to_build = find_source(root_artifact, 'stratum', stratum_name) + else: + to_build = root_artifact.source # Now, before we start the build, we garbage collect the caches # to ensure we have room. First we remove all system artifacts @@ -118,8 +139,9 @@ class WorkerBuild(cliapp.Plugin): #self.app.subcommands['gc']([]) - #arch = artifact.arch - #bc.build_source(artifact.source, bc.new_build_env(arch)) + self.app.status(msg='NAME: %s' % to_build.source.name) + arch = artifact.arch + bc.cache_or_build_source(to_build, bc.new_build_env(arch)) def is_system_artifact(self, filename): return re.match(r'^[0-9a-fA-F]{64}\.system\.', filename) |