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 authored and copybara-github committed Sep 19, 2023
1 parent 62386d9 commit 108ef55
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package com.google.devtools.build.lib.packages.util;

import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.testutil.TestConstants;
import java.io.IOException;

Expand All @@ -34,6 +33,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 @@ -193,17 +194,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 @@ -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 @@ -20,14 +20,14 @@ java_test(
"//src/main/java/com/google/devtools/build/lib/actions:artifacts",
"//src/main/java/com/google/devtools/build/lib/analysis:configured_target",
"//src/main/java/com/google/devtools/build/lib/analysis:extra_action_artifacts_provider",
"//src/main/java/com/google/devtools/build/lib/analysis:transitive_info_provider",
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/collect/nestedset",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/rules/java:java-compilation",
"//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 @@ -34,6 +34,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 @@ -58,6 +59,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 @@ -66,17 +68,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 @@ -78,7 +78,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 @@ -88,7 +88,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 @@ -39,7 +39,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 108ef55

Please sign in to comment.