Skip to content

Commit

Permalink
Move --incompatible_disable_proto_source_root to the option graveyard.
Browse files Browse the repository at this point in the history
And with it, the proto_library.proto_source_root attribute.

Good riddance.

Fixes #7153.

RELNOTES: None.
PiperOrigin-RevId: 262537130
  • Loading branch information
lberki authored and copybara-github committed Aug 9, 2019
1 parent 760e1dd commit 3e8364c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@
public class BazelRulesModule extends BlazeModule {
/** This is where deprecated options go to die. */
public static class GraveyardOptions extends OptionsBase {
@Option(
name = "incompatible_disable_proto_source_root",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.NO_OP},
metadataTags = {
OptionMetadataTag.INCOMPATIBLE_CHANGE,
OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES,
},
help = "Deprecated no-op.")
public boolean disableProtoSourceRoot;

@Option(
name = "incompatible_do_not_emit_buggy_external_repo_import",
defaultValue = "true",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ public RuleClass build(RuleClass.Builder builder, final RuleDefinitionEnvironmen
attr("srcs", LABEL_LIST)
.direct_compile_time_input()
.allowedFileTypes(FileType.of(".proto"), FileType.of(".protodevel")))
/* <!-- #BLAZE_RULE(proto_library).ATTRIBUTE(proto_source_root) -->
Directory containing .proto files. If set, it must be equal to the package name. If not set,
the source root will be the workspace directory (default).
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(attr("proto_source_root", STRING))
/* <!-- #BLAZE_RULE(proto_library).ATTRIBUTE(exports) -->
List of proto_library targets that can be referenced via "import public" in the proto
source.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,8 @@ public String getSourceRoot() {
/**
* Returns the {@link Library} representing this <code>proto_library</code> rule.
*
* <p>Assumes that <code>strip_import_prefix</code> and <code>import_prefix</code> are unset.
*
* <p>Build will fail if the {@code proto_source_root} of the current library is neither the
* package name nor the source root.
* <p>Assumes that <code>strip_import_prefix</code> and <code>import_prefix</code> are unset and
* that there are no generated .proto files that need to be compiled.
*/
// TODO(lberki): This should really be a PathFragment. Unfortunately, it's on the Starlark API of
// ProtoInfo so it's not an easy change :(
Expand Down Expand Up @@ -250,8 +248,6 @@ private static Library createLibraryWithVirtualSourceRootMaybe(
PathFragment importPrefixAttribute = getPathFragmentAttribute(ruleContext, "import_prefix");
PathFragment stripImportPrefixAttribute =
getPathFragmentAttribute(ruleContext, "strip_import_prefix");
PathFragment protoSourceRootAttribute =
getPathFragmentAttribute(ruleContext, "proto_source_root");
boolean hasGeneratedSources = false;

if (generatedProtosInVirtualImports) {
Expand All @@ -265,20 +261,11 @@ private static Library createLibraryWithVirtualSourceRootMaybe(

if (importPrefixAttribute == null
&& stripImportPrefixAttribute == null
&& protoSourceRootAttribute == null
&& !hasGeneratedSources) {
// Simple case, no magic required.
return null;
}

if (protoSourceRootAttribute != null
&& (importPrefixAttribute != null || stripImportPrefixAttribute != null)) {
ruleContext.ruleError(
"the 'proto_source_root' attribute is incompatible with "
+ "'strip_import_prefix' and 'import_prefix");
return null;
}

PathFragment stripImportPrefix;
PathFragment importPrefix;

Expand Down Expand Up @@ -308,30 +295,8 @@ private static Library createLibraryWithVirtualSourceRootMaybe(
ruleContext.attributeError("import_prefix", "should be a relative path");
return null;
}
} else if (protoSourceRootAttribute != null) {
if (!ruleContext.getFragment(ProtoConfiguration.class).enableProtoSourceroot()) {
ruleContext.attributeError("proto_source_root", "this attribute is not supported anymore");
return null;
}

if (!ruleContext.getLabel().getPackageFragment().equals(protoSourceRootAttribute)) {
ruleContext.attributeError(
"proto_source_root",
"proto_source_root must be the same as the package name ("
+ ruleContext.getLabel().getPackageName()
+ ")."
+ " not '"
+ protoSourceRootAttribute
+ "'.");

return null;
}

stripImportPrefix = ruleContext.getPackageDirectory();
importPrefix = PathFragment.EMPTY_FRAGMENT;
} else {
// Has generated sources, but neither strip_import_prefix nor import_prefix nor
// proto_source_root.
// Has generated sources, but neither strip_import_prefix nor import_prefix
stripImportPrefix =
ruleContext.getLabel().getPackageIdentifier().getRepository().getPathUnderExecRoot();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,6 @@ public static class Options extends FragmentOptions {
+ " 'dep.proto.' and it must be accessed by 'dep[ProtoInfo].")
public boolean disableLegacyProvider;

@Option(
name = "incompatible_disable_proto_source_root",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
metadataTags = {
OptionMetadataTag.INCOMPATIBLE_CHANGE,
OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
},
help =
"If true, proto_library will no longer allow the proto_source_root= attribute. It has "
+ "been superseded by the strip_import_prefix= and import_prefix= attributes")
public boolean disableProtoSourceRoot;

@Option(
name = "incompatible_load_proto_rules_from_bzl",
defaultValue = "false",
Expand All @@ -201,7 +187,6 @@ public static class Options extends FragmentOptions {
public FragmentOptions getHost() {
Options host = (Options) super.getHost();
host.disableLegacyProvider = disableLegacyProvider;
host.disableProtoSourceRoot = disableProtoSourceRoot;
host.loadProtoRulesFromBzl = loadProtoRulesFromBzl;
host.protoCompiler = protoCompiler;
host.protocOpts = protocOpts;
Expand Down Expand Up @@ -258,10 +243,6 @@ public boolean enableLegacyProvider() {
return !options.disableLegacyProvider;
}

public boolean enableProtoSourceroot() {
return !options.disableProtoSourceRoot;
}

public ImmutableList<String> protocOpts() {
return protocOpts;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,6 @@ public void testDescriptorSetOutput_strictDeps_disabled() throws Exception {
}
}

@Test
public void testDisableProtoSourceRoot() throws Exception {
useConfiguration(
"--proto_compiler=//proto:compiler", "--incompatible_disable_proto_source_root");
scratch.file(
"x/BUILD",
ProtoTestHelper.LOAD_PROTO_LIBRARY,
"proto_library(name='x', srcs=['x.proto'], proto_source_root='x')");
reporter.removeHandler(failFastHandler);
getConfiguredTarget("//x:x");
assertContainsEvent("this attribute is not supported anymore");
}

@Test
public void testStripImportPrefixWithoutDeps() throws Exception {
scratch.file(
Expand All @@ -290,7 +277,7 @@ public void testStripImportPrefixWithoutDeps() throws Exception {
}

@Test
public void testProtoSourceRootWithDepsDuplicate() throws Exception {
public void testStripImportPrefixWithDepsDuplicate() throws Exception {
scratch.file(
"third_party/x/foo/BUILD",
ProtoTestHelper.LOAD_PROTO_LIBRARY,
Expand Down

8 comments on commit 3e8364c

@meteorcloudy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw this error while testing another incompatible flag

(15:30:51) ERROR: /Users/buildkite/builds/bk-imacpro-13/bazel-downstream-projects/rules_rust/test/proto/BUILD:3:1: in @io_bazel_rules_rust//proto:proto.bzl%_rust_proto_aspect aspect on proto_library rule //test/proto:a_proto:
--
  | Traceback (most recent call last):
  | File "/Users/buildkite/builds/bk-imacpro-13/bazel-downstream-projects/rules_rust/test/proto/BUILD", line 3
  | @io_bazel_rules_rust//proto:proto.bzl%_rust_proto_aspect(...)
  | File "/private/var/tmp/_bazel_buildkite/6604506606cd2942fee5d9a993c2ff60/external/io_bazel_rules_rust/proto/proto.bzl", line 86, in _rust_proto_aspect_impl
  | ctx.rule.attr.proto_source_root
  | No attribute 'proto_source_root' in attr. Make sure you declared a rule attribute with this name.

https://buildkite.com/bazel/bazel-at-head-plus-downstream/builds/1133#a050a273-de3e-4c39-a6a8-6fe289474f7a

@lberki
Copy link
Contributor Author

@lberki lberki commented on 3e8364c Aug 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sigh. How come the "Bazelisk + incompatible flags" build didn't find this? /cc @philwo

I'll send out a pull request.

@philwo
Copy link
Member

@philwo philwo commented on 3e8364c Aug 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lberki Mhm. I don’t know for sure, but maybe you can only repro this failure when doing „bazel shutdown“ or „bazel clean“ between flipping it? Wouldn’t be the first flag where this is true (personally, I believe that it’s quite a bold strategy to rely on Bazel’s incremental correctness to test flag flips for implementation details...).

@lberki
Copy link
Contributor Author

@lberki lberki commented on 3e8364c Aug 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, that would be weird since this is just a vanilla analysis phase flag.

Anyhow, bazelbuild/rules_rust#246 sent out.

@lberki
Copy link
Contributor Author

@lberki lberki commented on 3e8364c Aug 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @aehlig @laurentlb

An incremental correctness bug would be quite terrible. I thought I saw a case where Bazel in fact did not notice my "add a statement to a .bzl file that makes the build fail changes, but I dismissed it as me editing the wrong file.

I tried reproducing the exact sequence of actions that led to this after a clean --expunge and it all worked, so I'll dismiss it as my own mistake for the time being.

@Yannic
Copy link
Contributor

@Yannic Yannic commented on 3e8364c Aug 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this flag already removed? Shouldn't we wait at least one (incompatible) release between flipping a flag and making it a no-op? Same for --incompatible_do_not_emit_buggy_external_repo_import.

@lberki
Copy link
Contributor Author

@lberki lberki commented on 3e8364c Aug 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that that's not the case: the policy is that if version N is designated as the migration period, the flag can be flipped and made a no-op. At least https://docs.bazel.build/versions/master/backward-compatibility.html does not promise anything to the contrary.

@laurentlb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, the flag can even be removed in the same commit as it's flipped. We can weigh the benefits of removing the code vs keeping the flag longer.

Yannic, do you think it's important to keep this flag longer?

Please sign in to comment.