Skip to content

Commit

Permalink
Return a quoted string for repr(repository_ctx.path(...))
Browse files Browse the repository at this point in the history
This makes it easier to use `repository_ctx.path(...)` in BUILD file templating as it no longer differs from a path string.
  • Loading branch information
fmeum committed Sep 25, 2024
1 parent 56af167 commit 520f2dd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,6 @@ public String toString() {

@Override
public void repr(Printer printer) {
printer.append(toString());
printer.repr(toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
import net.starlark.java.eval.Starlark;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -51,4 +52,9 @@ public void testStarlarkPathGetChild() throws Exception {
assertThat(ev.eval("wd.get_child('a','b/c','/d/')"))
.isEqualTo(makePath(wd.getRelative("a/b/c/d")));
}

@Test
public void testStarlarkPathRepr() throws Exception {
assertThat(ev.eval("repr(wd)")).isEqualTo(Starlark.repr(wd.toString()));
}
}

0 comments on commit 520f2dd

Please sign in to comment.