Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perfomance verify duplicate targets #286

Merged
merged 3 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions bobtask/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,41 +198,40 @@ func (tm Map) IgnoreChildTargets() (err error) {

// VerifyDuplicateTargets checks if multiple build tasks point to the same target.
func (tm Map) VerifyDuplicateTargets() error {

// mapping [target][]taskname
targetToTasks := make(map[string][]string)

for taskName, v := range tm {
target, _ := v.Target()
if target == nil {
if !v.TargetExists() {
continue
}
for _, t := range target.DockerImages() {
for _, t := range v.target.DockerImages() {
targetToTasks[t] = append(targetToTasks[t], taskName)

if len(targetToTasks[t]) > 1 {
return usererror.Wrap(CreateErrAmbiguousTargets(targetToTasks[t], t))
}
}
for _, t := range target.FilesystemEntriesRaw() {
for _, t := range v.target.FilesystemEntriesRaw() {
targetToTasks[t] = append(targetToTasks[t], taskName)

if len(targetToTasks[t]) > 1 {
return usererror.Wrap(CreateErrAmbiguousTargets(targetToTasks[t], t))
}
}
}

// FIXME: A filesystem target can still point to a file inside
// a directory target.
//
// Could be solved by beeing more strict with target definitions.
// Could be solved by being more strict with target definitions.
// E.g. a directory must be defined as "dir/" instead of "dir".
// This allows to catch that case without traversing the
// actual filesystem.

for k, v := range targetToTasks {
if len(targetToTasks[k]) > 1 {
return usererror.Wrap(CreateErrAmbigousTargets(v, k))
}
}

return nil
}

func CreateErrAmbigousTargets(tasks []string, target string) error {
func CreateErrAmbiguousTargets(tasks []string, target string) error {
sort.Strings(tasks)
return fmt.Errorf("%w,\nmultiple tasks [%s] pointing to the same target `%s`", ErrAmbigousTargets, strings.Join(tasks, " "), target)
}
4 changes: 2 additions & 2 deletions bobtask/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func (t *Task) Target() (empty target.Target, _ error) {
return empty, err
}

// This indicates the previous build did not contain any targets and therfore it
// can't be comparted againast.
// This indicates the previous build did not contain any targets and therefore it
// can't be compared against.
// FIXME: Is this necessary? Seems like it rather happens during development.
if len(buildInfo.Target.Filesystem.Files) == 0 && len(buildInfo.Target.Docker) == 0 {
return t.target, t.target.Resolve()
Expand Down
11 changes: 5 additions & 6 deletions test/e2e/target-name/name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var _ = Describe("Testing name of targets", func() {
_, err = b.Aggregate()
Expect(err).To(HaveOccurred())

expected := bobtask.CreateErrAmbigousTargets([]string{"another", "build"}, "hello").Error()
expected := bobtask.CreateErrAmbiguousTargets([]string{"another", "build"}, "hello").Error()
Expect(err.Error()).To(Equal(expected))
})
})
Expand All @@ -34,7 +34,7 @@ var _ = Describe("Testing name of targets", func() {
_, err = b.Aggregate()
Expect(err).To(HaveOccurred())

expected := bobtask.CreateErrAmbigousTargets([]string{"another", "build"}, "hello").Error()
expected := bobtask.CreateErrAmbiguousTargets([]string{"another", "build"}, "hello").Error()
Expect(err.Error()).To(Equal(expected))
})
})
Expand Down Expand Up @@ -66,7 +66,7 @@ var _ = Describe("Testing name of targets", func() {
_, err = b.Aggregate()
Expect(err).To(HaveOccurred())

expected := bobtask.CreateErrAmbigousTargets([]string{"another", "build"}, "my-image:latest").Error()
expected := bobtask.CreateErrAmbiguousTargets([]string{"another", "build"}, "my-image:latest").Error()
Expect(err.Error()).To(Equal(expected))
})
})
Expand All @@ -85,7 +85,7 @@ var _ = Describe("Testing name of targets", func() {
_, err = b.Aggregate()
Expect(err).To(HaveOccurred())

expected := bobtask.CreateErrAmbigousTargets([]string{"build", "second/build"}, "my-image:latest").Error()
expected := bobtask.CreateErrAmbiguousTargets([]string{"build", "second/build"}, "my-image:latest").Error()
Expect(err.Error()).To(Equal(expected))
})
})
Expand All @@ -104,9 +104,8 @@ var _ = Describe("Testing name of targets", func() {
_, err = b.Aggregate()
Expect(err).To(HaveOccurred())

expected := bobtask.CreateErrAmbigousTargets([]string{"build", "second/build"}, "second/hello").Error()
expected := bobtask.CreateErrAmbiguousTargets([]string{"build", "second/build"}, "second/hello").Error()
Expect(err.Error()).To(Equal(expected))

})
})
})