private Optional<RuleKey> calculateDepFileRuleKey( BuildRule rule, Optional<ImmutableList<String>> depFile, boolean allowMissingInputs) throws IOException { Preconditions.checkState(useDependencyFileRuleKey(rule)); // Extract the dep file from the last build. If we don't find one, abort. if (!depFile.isPresent()) { return Optional.absent(); } // Add in the inputs explicitly listed in the dep file. If any inputs are no longer on disk, // this means something changed and a dep-file based rule key can't be calculated. ImmutableList<Path> inputs = FluentIterable.from(depFile.get()).transform(MorePaths.TO_PATH).toList(); RuleKeyBuilder builder = depFileRuleKeyBuilderFactory.newInstance(rule); for (Path input : inputs) { try { builder.setPath(input); } catch (NoSuchFileException e) { if (!allowMissingInputs) { throw e; } return Optional.absent(); } } return Optional.of(builder.build()); }
@Test(expected = HumanReadableException.class) public void shouldNotAllowPathsInRuleKeysWhenSetReflectively() { SourcePathResolver resolver = new SourcePathResolver( new BuildRuleResolver(TargetGraph.EMPTY, new BuildTargetNodeToBuildRuleTransformer())); RuleKeyBuilder builder = createEmptyRuleKey(resolver); builder.setReflectively("path", Paths.get("some/path")); }
@Override public RuleKeyBuilder appendToRuleKey(RuleKeyBuilder builder) { return builder .setReflectively("value", value) .setReflectively("foo", "foo") .setReflectively("bar", "bar"); }
// Put the link map into the rule key, as if it changes at all, we need to // re-run it. @Override public RuleKeyBuilder appendToRuleKey(RuleKeyBuilder builder) { for (Map.Entry<Path, SourcePath> entry : links.entrySet()) { builder.setReflectively( "link(" + entry.getKey().toString() + ")", getResolver().deprecatedGetPath(entry.getValue()).toString()); } return builder; }
@Override public RuleKeyBuilder appendToRuleKey(RuleKeyBuilder builder) { return builder.setReflectively("foo", foo); }