Skip to content

Commit

Permalink
Fix string representations for root objects
Browse files Browse the repository at this point in the history
Root objects should not expose their absolute paths as they break hermeticity.

PiperOrigin-RevId: 168363549
  • Loading branch information
vladmos authored and philwo committed Sep 12, 2017
1 parent 1a72fb7 commit 139543d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/google/devtools/build/lib/actions/Root.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ public String toString() {

@Override
public void repr(SkylarkPrinter printer) {
printer.append(isSourceRoot() ? "<source root>" : "<derived root>");
}

@Override
public void reprLegacy(SkylarkPrinter printer) {
printer.append(toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ private void generateFilesToTestStrings() throws Exception {
")",
"",
"def _check_impl(ctx):",
" source_file = ctx.attr.srcs[0].files.to_list()[0]",
" generated_file = ctx.attr.srcs[1].files.to_list()[0]",
" objects = {",
" 'target': ctx.attr.deps[0],",
" 'alias_target': ctx.attr.deps[1],",
Expand All @@ -188,8 +190,10 @@ private void generateFilesToTestStrings() throws Exception {
" 'rule_ctx': ctx,",
" 'aspect_ctx': ctx.attr.asp_deps[0][aspect_ctx_provider].ctx,",
" 'aspect_ctx.rule': ctx.attr.asp_deps[0][aspect_ctx_provider].rule,",
" 'source_file': ctx.attr.srcs[0].files.to_list()[0],",
" 'generated_file': ctx.attr.srcs[1].files.to_list()[0],",
" 'source_file': source_file,",
" 'generated_file': generated_file,",
" 'source_root': source_file.root,",
" 'generated_root': generated_file.root,",
" }",
" return struct(**prepare_params(objects))",
"check = rule(",
Expand Down Expand Up @@ -334,6 +338,19 @@ public void testStringRepresentations_Files() throws Exception {
}
}

@Test
public void testStringRepresentations_Root() throws Exception {
setSkylarkSemanticsOptions("--incompatible_descriptive_string_representations=true");

generateFilesToTestStrings();
ConfiguredTarget target = getConfiguredTarget("//test/skylark:check");

for (String suffix : SUFFIXES) {
assertThat(target.get("source_root" + suffix)).isEqualTo("<source root>");
assertThat(target.get("generated_root" + suffix)).isEqualTo("<derived root>");
}
}

@Test
public void testStringRepresentations_Glob() throws Exception {
setSkylarkSemanticsOptions("--incompatible_descriptive_string_representations=true");
Expand Down

0 comments on commit 139543d

Please sign in to comment.