Skip to content

Commit

Permalink
Handle aliases to source files (#67)
Browse files Browse the repository at this point in the history
Previously an alias to a source file ended up not hashing the source
file because the file didn't exist in the same configuration as the
depender.
  • Loading branch information
illicitonion authored Jun 19, 2023
1 parent a47ada9 commit 20243af
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
21 changes: 17 additions & 4 deletions pkg/hash_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,24 @@ func hashRule(thc *TargetHashCache, rule *build.Rule, configuration *analysis.Co
return nil, fmt.Errorf("failed to parse ruleInput label %s: %w", ruleInputLabelString, err)
}
var depConfigurations []Configuration
// Aliases don't transition, and we've seen aliases expanding across configurations cause dependency cycles for nogo targets.
if rule.GetRuleClass() == "alias" {
// Aliases don't transition, and we've seen aliases expanding across configurations cause dependency cycles for nogo targets.
// Narrow just to the current configuration in this case.
depConfiguration := NormalizeConfiguration(configuration.GetChecksum())
depConfigurations = []Configuration{depConfiguration}
knownDepConfigurations := thc.context[ruleInputLabel]
isSourceFile := true
for _, ct := range knownDepConfigurations {
if ct.GetTarget().GetType() != build.Target_SOURCE_FILE {
isSourceFile = false
}
}

if isSourceFile {
// If it's a source file, it doesn't exist in the current configuration, but does exist in the empty configuration.
// Accordingly, we need to explicitly transition to the empty configuration.
depConfigurations = []Configuration{NormalizeConfiguration("")}
} else {
// If it's not a source file, narrow just to the current configuration - we know there was no transition, so we must be in the same configuration.
depConfigurations = []Configuration{NormalizeConfiguration(configuration.GetChecksum())}
}
} else {
depConfigurations = thc.KnownConfigurations(ruleInputLabel).SortedSlice()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,12 @@ public void aliasTargetIsDetectedIfActualTargetChanged() throws Exception {
Set.of("//java/example:ExampleTest", "//java/example:example_test"));
}

@Test
public void aliasTargetIsDetectedIfActualFileChanged() throws Exception {
doTest(Commits.ALIAS_ADD_TARGET_TO_FILE, Commits.ALIAS_CHANGE_TARGET_THROUGH_ALIAS_TO_FILE,
Set.of("//java/example:ExampleTest", "//java/example:ExampleTestSource"));
}

@Test
public void aliasTargetIsDetectedIfActualLabelChanged() throws Exception {
doTest(Commits.ALIAS_ADD_TARGET, Commits.ALIAS_CHANGE_ACTUAL,
Expand Down Expand Up @@ -692,4 +698,8 @@ class Commits {
public static final String ALIAS_CHANGE_ACTUAL = "ec19104291a3ea7cb61fb54ecdeaee73127bf284";

public static final String ALIAS_CHANGE_TARGET_THROUGH_ALIAS = "3d9788053a2eed1a2f3beb05070872526ebdf76e";

public static final String ALIAS_ADD_TARGET_TO_FILE = "7be0f96f26742daec661c2ebfbb08b88b6355a3b";

public static final String ALIAS_CHANGE_TARGET_THROUGH_ALIAS_TO_FILE = "68fbd3661f3626e2df6a55b079444adbf76b5a3b";
}

0 comments on commit 20243af

Please sign in to comment.