Skip to content

Commit

Permalink
Use MockProtoSupport.setup where protos are used
Browse files Browse the repository at this point in the history
Update MockProtoSupport.setup to always create rules_proto (setupWorskpace call)

PiperOrigin-RevId: 566643341
Change-Id: I755044233652597296ddcfd0c8a9ceae2e079efc
  • Loading branch information
comius committed Jan 17, 2024
1 parent b47d436 commit 2053317
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ private MockProtoSupport() {
*/
public static void setup(MockToolsConfig config) throws IOException {
createNetProto2(config);
setupWorkspace(config);
config.append("tools/proto/toolchains/BUILD");
}

/**
Expand Down Expand Up @@ -198,17 +200,19 @@ private static void createNetProto2(MockToolsConfig config) throws IOException {
" srcs = [ 'metadata.go' ])");
}

public static void setupWorkspace(Scratch scratch) throws Exception {
scratch.appendFile(
"WORKSPACE",
"local_repository(",
" name = 'rules_proto',",
" path = 'third_party/rules_proto',",
")");
scratch.file("third_party/rules_proto/WORKSPACE");
scratch.file("third_party/rules_proto/proto/BUILD", "licenses(['notice'])");
scratch.file(
"third_party/rules_proto/proto/defs.bzl",
public static void setupWorkspace(MockToolsConfig config) throws IOException {
if (TestConstants.PRODUCT_NAME.equals("bazel")) {
config.append(
"WORKSPACE",
"local_repository(",
" name = 'rules_proto',",
" path = 'third_party/bazel_rules/rules_proto',",
")");
}
config.create("third_party/bazel_rules/rules_proto/WORKSPACE");
config.create("third_party/bazel_rules/rules_proto/proto/BUILD", "licenses(['notice'])");
config.create(
"third_party/bazel_rules/rules_proto/proto/defs.bzl",
"def _add_tags(kargs):",
" if 'tags' in kargs:",
" kargs['tags'] += ['__PROTO_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__']",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private CcStarlarkApiInfo getApiForBuiltin(String label) throws Exception {

@Before
public void setUp() throws Exception {
MockProtoSupport.setupWorkspace(scratch);
MockProtoSupport.setupWorkspace(mockToolsConfig);
invalidatePackages();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class CcProtoLibraryTest extends BuildViewTestCase {

@Before
public void setUp() throws Exception {
MockProtoSupport.setup(mockToolsConfig);
scratch.file("protobuf/WORKSPACE");
scratch.overwriteFile(
"protobuf/BUILD",
Expand All @@ -78,7 +79,6 @@ public void setUp() throws Exception {
" name = 'com_google_protobuf',",
" path = 'protobuf',",
")");
MockProtoSupport.setupWorkspace(scratch);
invalidatePackages(); // A dash of magic to re-evaluate the WORKSPACE file.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ java_test(
"//src/main/java/com/google/devtools/build/lib/rules/java:java-rules",
"//src/test/java/com/google/devtools/build/lib/actions/util",
"//src/test/java/com/google/devtools/build/lib/analysis/util",
"//src/test/java/com/google/devtools/build/lib/packages:testutil",
"//src/test/java/com/google/devtools/build/lib/rules/java:java_compile_action_test_helper",
"//src/test/java/com/google/devtools/build/lib/testutil:JunitUtils",
"//third_party:guava",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.google.devtools.build.lib.packages.Provider;
import com.google.devtools.build.lib.packages.StarlarkProvider;
import com.google.devtools.build.lib.packages.StructImpl;
import com.google.devtools.build.lib.packages.util.MockProtoSupport;
import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider;
import com.google.devtools.build.lib.rules.java.JavaCompileAction;
import com.google.devtools.build.lib.rules.java.JavaInfo;
Expand All @@ -59,6 +60,7 @@ public final void setUpMocks() throws Exception {
useConfiguration(
"--proto_compiler=//proto:compiler",
"--proto_toolchain_for_javalite=//tools/proto/toolchains:javalite");
MockProtoSupport.setup(mockToolsConfig);

scratch.file("proto/BUILD", "licenses(['notice'])", "exports_files(['compiler'])");

Expand All @@ -67,17 +69,10 @@ public final void setUpMocks() throws Exception {
actionsTestUtil = actionsTestUtil();
}

@Before
public final void setupStarlarkRule() throws Exception {
setBuildLanguageOptions(
"--experimental_builtins_injection_override=+java_lite_proto_library",
"--experimental_google_legacy_api");
}

private void mockToolchains() throws IOException {
mockRuntimes();

scratch.file(
scratch.appendFile(
"tools/proto/toolchains/BUILD",
"package(default_visibility=['//visibility:public'])",
"proto_lang_toolchain(",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public final void setup() throws Exception {

useConfiguration("--proto_toolchain_for_java=//tools/proto/toolchains:java");

mockToolsConfig.create(
mockToolsConfig.append(
"tools/proto/toolchains/BUILD",
TestConstants.LOAD_PROTO_LANG_TOOLCHAIN,
"package(default_visibility=['//visibility:public'])",
Expand All @@ -86,7 +86,6 @@ public final void setup() throws Exception {
"proto_lang_toolchain(name='java_stubby_compatible13_immutable', "
+ "command_line = 'dont_care')");

MockProtoSupport.setupWorkspace(scratch);
invalidatePackages();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ public class BazelProtoCommonTest extends BuildViewTestCase {

@Before
public final void setup() throws Exception {
MockProtoSupport.setupWorkspace(scratch);
invalidatePackages();

MockProtoSupport.setup(mockToolsConfig);
invalidatePackages();

scratch.file(
"third_party/x/BUILD",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ private boolean isThisBazel() {
@Before
public void setUp() throws Exception {
useConfiguration("--proto_compiler=//proto:compiler");
MockProtoSupport.setup(mockToolsConfig);
scratch.file("proto/BUILD", "licenses(['notice'])", "exports_files(['compiler'])");

MockProtoSupport.setupWorkspace(scratch);
invalidatePackages();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public void setUp() throws Exception {
scratch.file("myinfo/myinfo.bzl", "MyInfo = provider()");
scratch.file("myinfo/BUILD");
MockProtoSupport.setup(mockToolsConfig);

MockProtoSupport.setupWorkspace(scratch);
invalidatePackages();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
public class ProtoLangToolchainTest extends BuildViewTestCase {
@Before
public void setUp() throws Exception {
MockProtoSupport.setupWorkspace(scratch);
MockProtoSupport.setup(mockToolsConfig);
useConfiguration("--protocopt=--myflag");
invalidatePackages();
Expand Down

0 comments on commit 2053317

Please sign in to comment.