diff options
Diffstat (limited to 'bitbake/lib/toaster/orm/models.py')
-rw-r--r-- | bitbake/lib/toaster/orm/models.py | 112 |
1 files changed, 70 insertions, 42 deletions
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py index 9edbef33967..61f6a2072ea 100644 --- a/bitbake/lib/toaster/orm/models.py +++ b/bitbake/lib/toaster/orm/models.py @@ -581,28 +581,6 @@ class Build(models.Model): def __str__(self): return "%d %s %s" % (self.id, self.project, ",".join([t.target for t in self.target_set.all()])) - -# an Artifact is anything that results from a Build, and may be of interest to the user, and is not stored elsewhere -class BuildArtifact(models.Model): - build = models.ForeignKey(Build) - file_name = models.FilePathField() - file_size = models.IntegerField() - - def get_local_file_name(self): - try: - deploydir = Variable.objects.get(build = self.build, variable_name="DEPLOY_DIR").variable_value - return self.file_name[len(deploydir)+1:] - except: - raise - - return self.file_name - - def get_basename(self): - return os.path.basename(self.file_name) - - def is_available(self): - return self.build.buildrequest.environment.has_artifact(self.file_name) - class ProjectTarget(models.Model): project = models.ForeignKey(Project) target = models.CharField(max_length=100) @@ -625,13 +603,19 @@ class Target(models.Model): def get_similar_targets(self): """ - Get targets for the same machine, task and target name + Get target sfor the same machine, task and target name (e.g. 'core-image-minimal') from a successful build for this project (but excluding this target). - Note that we look for targets built by this project because projects - can have different configurations from each other, and put their - artifacts in different directories. + Note that we only look for targets built by this project because + projects can have different configurations from each other, and put + their artifacts in different directories. + + The possibility of error when retrieving candidate targets + is minimised by the fact that bitbake will rebuild artifacts if MACHINE + (or various other variables) change. In this case, there is no need to + clone artifacts from another target, as those artifacts will have + been re-generated for this target anyway. """ query = ~Q(pk=self.pk) & \ Q(target=self.target) & \ @@ -649,29 +633,54 @@ class Target(models.Model): similar_target = None candidates = self.get_similar_targets() - if candidates.count() < 1: + if candidates.count() == 0: return similar_target task_subquery = Q(task=self.task) # we can look for a 'build' task if this task is a 'populate_sdk_ext' - # task, as it will have created images; and vice versa; note that + # task, as the latter also creates images; and vice versa; note that # 'build' targets can have their task set to ''; # also note that 'populate_sdk' does not produce image files image_tasks = [ '', # aka 'build' 'build', + 'image', 'populate_sdk_ext' ] if self.task in image_tasks: task_subquery = Q(task__in=image_tasks) + # annotate with the count of files, to exclude any targets which + # don't have associated files + candidates = candidates.annotate(num_files=Count('target_image_file')) + query = task_subquery & Q(num_files__gt=0) + candidates = candidates.filter(query) + + if candidates.count() > 0: + candidates.order_by('build__completed_on') + similar_target = candidates.last() + + return similar_target + + def get_similar_target_with_sdk_files(self): + """ + Get the most recent similar target with TargetSDKFiles associated + with it, for the purpose of cloning those files onto this target. + """ + similar_target = None + + candidates = self.get_similar_targets() + if candidates.count() == 0: + return similar_target + # annotate with the count of files, to exclude any targets which # don't have associated files - candidates = candidates.annotate( - num_files=Count('target_image_file')) + candidates = candidates.annotate(num_files=Count('targetsdkfile')) + + query = Q(task=self.task) & Q(num_files__gt=0) candidates = candidates.filter(query) @@ -681,11 +690,10 @@ class Target(models.Model): return similar_target - def clone_artifacts_from(self, target): + def clone_image_artifacts_from(self, target): """ - Make clones of the BuildArtifacts, Target_Image_Files and - TargetArtifactFile objects associated with Target target, then - associate them with this target. + Make clones of the Target_Image_Files and TargetKernelFile objects + associated with Target target, then associate them with this target. Note that for Target_Image_Files, we only want files from the previous build whose suffix matches one of the suffixes defined in this @@ -711,18 +719,38 @@ class Target(models.Model): image_file.target = self image_file.save() - artifact_files = target.targetartifactfile_set.all() - for artifact_file in artifact_files: - artifact_file.pk = None - artifact_file.target = self - artifact_file.save() + kernel_files = target.targetkernelfile_set.all() + for kernel_file in kernel_files: + kernel_file.pk = None + kernel_file.target = self + kernel_file.save() self.license_manifest_path = target.license_manifest_path self.save() -# an Artifact is anything that results from a target being built, and may -# be of interest to the user, and is not an image file -class TargetArtifactFile(models.Model): + def clone_sdk_artifacts_from(self, target): + """ + Clone TargetSDKFile objects from target and associate them with this + target. + """ + sdk_files = target.targetsdkfile_set.all() + for sdk_file in sdk_files: + sdk_file.pk = None + sdk_file.target = self + sdk_file.save() + +# kernel artifacts for a target: bzImage and modules* +class TargetKernelFile(models.Model): + target = models.ForeignKey(Target) + file_name = models.FilePathField() + file_size = models.IntegerField() + + @property + def basename(self): + return os.path.basename(self.file_name) + +# SDK artifacts for a target: sh and manifest files +class TargetSDKFile(models.Model): target = models.ForeignKey(Target) file_name = models.FilePathField() file_size = models.IntegerField() |