Skip to content

Commit bc4a03f

Browse files
fmeumrules_java Copybara
authored andcommitted
Add runfiles library to release archive
Copybara Import from #242 BEGIN_PUBLIC Add runfiles library to release archive (#242) Closes #242 END_PUBLIC COPYBARA_INTEGRATE_REVIEW=#242 from fmeum:fix-runfiles dcc8004 PiperOrigin-RevId: 698035007 Change-Id: I069b7f289a40550ac1c8024d013863e3d384d5a6
1 parent a156fe9 commit bc4a03f

8 files changed

Lines changed: 38 additions & 3 deletions

File tree

java/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ filegroup(
1313
"//java/common:srcs",
1414
"//java/private:srcs",
1515
"//java/proto:srcs",
16+
"//java/runfiles:srcs",
1617
"//java/toolchains:srcs",
1718
],
1819
visibility = ["//:__pkg__"],

java/runfiles/BUILD.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@ alias(
33
actual = "//java/runfiles/src/main/java/com/google/devtools/build/runfiles",
44
visibility = ["//visibility:public"],
55
)
6+
7+
filegroup(
8+
name = "srcs",
9+
srcs = glob(["**"]) + [
10+
"//java/runfiles/src/main/java/com/google/devtools/build/runfiles:srcs",
11+
],
12+
visibility = ["//java:__pkg__"],
13+
)

java/runfiles/src/main/java/com/google/devtools/build/runfiles/BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ java_plugin(
2121
srcs = ["AutoBazelRepositoryProcessor.java"],
2222
processor_class = "com.google.devtools.build.runfiles.AutoBazelRepositoryProcessor",
2323
)
24+
25+
filegroup(
26+
name = "srcs",
27+
srcs = glob(["**"]),
28+
visibility = ["//java/runfiles:__pkg__"],
29+
)

test/repo/BUILD.bazel

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ java_binary(
1515
java_test(
1616
name = "MyTest",
1717
srcs = ["src/MyTest.java"],
18-
deps = ["@my_jar//jar"],
18+
data = [
19+
"src/data.txt",
20+
],
21+
deps = [
22+
"@my_jar//jar",
23+
"@rules_java//java/runfiles",
24+
],
1925
)
2026

2127
default_java_toolchain(

test/repo/MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module(name = "fake_repo_for_testing")
1+
module(name = "integration_test_repo")
22

33
bazel_dep(name = "rules_java", version = "7.5.0")
44
archive_override(

test/repo/setup.sh

100644100755
File mode changed.

test/repo/src/MyTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
import static org.junit.Assert.assertEquals;
2+
import static org.junit.Assert.assertTrue;
23

4+
import com.google.devtools.build.runfiles.AutoBazelRepository;
5+
import com.google.devtools.build.runfiles.Runfiles;
6+
import java.io.IOException;
7+
import java.nio.file.Files;
8+
import java.nio.file.Path;
9+
import java.nio.file.Paths;
310
import mypackage.MyLib;
411
import org.junit.Test;
512
import org.junit.runner.RunWith;
613
import org.junit.runners.JUnit4;
714

815
@RunWith(JUnit4.class)
16+
@AutoBazelRepository
917
public class MyTest {
1018
@Test
1119
public void main() {
1220
assertEquals(MyLib.myStr(), "my_string");
1321
}
14-
}
1522

23+
@Test
24+
public void runfiles() throws IOException {
25+
Runfiles runfiles = Runfiles.preload().withSourceRepository(AutoBazelRepository_MyTest.NAME);
26+
Path path = Paths.get(runfiles.rlocation("integration_test_repo/src/data.txt"));
27+
assertTrue(Files.exists(path));
28+
}
29+
}

test/repo/src/data.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)