forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change adds a new `proto_toolchain` rule which we will use later to resolve tools and options required to compile Protocol Buffers, thus eventually replacing some of the command-line options from `ProtoConfiguration`. To preclude inconsistencies in the migration period, we will start with a `proto_toolchain` rule that doesn't have any arguments and populate its provider from the existing command-line options. After all consumers have been migrated to resolve the tools from the toolchain instead of reading the command-line, we will replace all proto-specific flags with attributes on `proto_toolchain` (or similar, language-specific toolchains for flags that only affect a specific language). Updates bazelbuild#10005
- Loading branch information
Showing
12 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/main/java/com/google/devtools/build/lib/bazel/rules/proto.WORKSPACE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
register_toolchains("@bazel_tools//tools/proto:toolchain") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/com/google/devtools/build/lib/rules/proto/ProtoToolchain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2020 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.devtools.build.lib.rules.proto; | ||
|
||
import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException; | ||
import com.google.devtools.build.lib.analysis.ConfiguredTarget; | ||
import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; | ||
import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory; | ||
import com.google.devtools.build.lib.analysis.RuleContext; | ||
import com.google.devtools.build.lib.analysis.Runfiles; | ||
import com.google.devtools.build.lib.analysis.RunfilesProvider; | ||
|
||
/** The implementation of the <code>proto_toolchain</code> rule. */ | ||
public class ProtoToolchain implements RuleConfiguredTargetFactory { | ||
@Override | ||
public ConfiguredTarget create(RuleContext ruleContext) | ||
throws ActionConflictException, RuleErrorException, InterruptedException { | ||
ProtoToolchainInfo toolchain = new ProtoToolchainInfo(); | ||
RuleConfiguredTargetBuilder builder = | ||
new RuleConfiguredTargetBuilder(ruleContext) | ||
.addNativeDeclaredProvider(toolchain) | ||
.addProvider(RunfilesProvider.class, RunfilesProvider.simple(Runfiles.EMPTY)); | ||
|
||
return builder.build(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/google/devtools/build/lib/rules/proto/ProtoToolchainInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2020 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.devtools.build.lib.rules.proto; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.devtools.build.lib.analysis.platform.ToolchainInfo; | ||
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; | ||
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; | ||
import com.google.devtools.build.lib.starlarkbuildapi.proto.ProtoToolchainInfoApi; | ||
|
||
/** | ||
* Information about the tools used by the <code>proto_*</code> and <code>LANG_proto_*</code> rules. | ||
*/ | ||
@Immutable | ||
@AutoCodec | ||
public class ProtoToolchainInfo extends ToolchainInfo implements ProtoToolchainInfoApi { | ||
@AutoCodec.Instantiator | ||
public ProtoToolchainInfo() { | ||
super(ImmutableMap.of()); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/google/devtools/build/lib/rules/proto/ProtoToolchainRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2020 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.devtools.build.lib.rules.proto; | ||
|
||
import com.google.devtools.build.lib.analysis.BaseRuleClasses; | ||
import com.google.devtools.build.lib.analysis.RuleDefinition; | ||
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; | ||
import com.google.devtools.build.lib.packages.RuleClass; | ||
|
||
/** Rule definition of the <code>proto_toolchain</code> rule. */ | ||
public class ProtoToolchainRule implements RuleDefinition { | ||
@Override | ||
public RuleClass build(RuleClass.Builder builder, final RuleDefinitionEnvironment env) { | ||
return builder | ||
.requiresConfigurationFragments(ProtoConfiguration.class) | ||
.advertiseProvider(ProtoToolchainInfo.class) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public Metadata getMetadata() { | ||
return RuleDefinition.Metadata.builder() | ||
.name("proto_toolchain") | ||
.ancestors(BaseRuleClasses.BaseRule.class) | ||
.factoryClass(ProtoToolchain.class) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...main/java/com/google/devtools/build/lib/starlarkbuildapi/proto/ProtoToolchainInfoApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2020 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.devtools.build.lib.starlarkbuildapi.proto; | ||
|
||
import com.google.devtools.build.docgen.annot.DocCategory; | ||
import com.google.devtools.build.lib.starlarkbuildapi.platform.ToolchainInfoApi; | ||
import net.starlark.java.annot.StarlarkBuiltin; | ||
|
||
/** Provides access to information about the Protobuf toolchain rule. */ | ||
@StarlarkBuiltin( | ||
name = "ProtoToolchainInfo", | ||
category = DocCategory.PROVIDER, | ||
doc = "Provides access to information about the Protobuf toolchain rule.") | ||
public interface ProtoToolchainInfoApi extends ToolchainInfoApi {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright 2020 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
licenses(["notice"]) # Apache 2.0 | ||
|
||
filegroup( | ||
name = "srcs", | ||
srcs = glob(["**"]), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright 2020 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
licenses(["notice"]) # Apache 2.0 | ||
|
||
# The toolchain type used to distinguish proto toolchains. | ||
toolchain_type( | ||
name = "toolchain_type", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
# buildifier: disable=native-proto | ||
proto_toolchain( | ||
name = "default_toolchain", | ||
) | ||
|
||
toolchain( | ||
name = "toolchain", | ||
toolchain = ":default_toolchain", | ||
toolchain_type = ":toolchain_type", | ||
) |