aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar Carmi Grushko <carmi@google.com>2015-11-11 19:12:31 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2015-11-12 09:01:29 +0000
commite80cccd667a658a62efb99655156956c0ed813f7 (patch)
tree3cdbbc714b096e03c54631e55b032cf7f51de7d5 /src/main/java
parenta0512fea5e86352f7c18613ef656851654dbe764 (diff)
--
MOS_MIGRATED_REVID=107604619
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/Attribute.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/python/AspectPyCcLinkParamsProvider.java45
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/python/AspectPythonRunfilesProvider.java51
3 files changed, 101 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java
index 9e19e68c66..06dc3404ce 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java
@@ -36,6 +36,7 @@ import com.google.devtools.build.lib.util.FileType;
import com.google.devtools.build.lib.util.FileTypeSet;
import com.google.devtools.build.lib.util.StringUtil;
+import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
@@ -252,6 +253,10 @@ public final class Attribute implements Comparable<Attribute> {
private final Set<Object> allowedValues;
+ public <T> AllowedValueSet(T... values) {
+ this(Arrays.asList(values));
+ }
+
public AllowedValueSet(Iterable<?> values) {
Preconditions.checkNotNull(values);
Preconditions.checkArgument(!Iterables.isEmpty(values));
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/AspectPyCcLinkParamsProvider.java b/src/main/java/com/google/devtools/build/lib/rules/python/AspectPyCcLinkParamsProvider.java
new file mode 100644
index 0000000000..46c8a9cb4e
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/AspectPyCcLinkParamsProvider.java
@@ -0,0 +1,45 @@
+// Copyright 2015 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.python;
+
+import com.google.common.base.Function;
+import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
+import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
+import com.google.devtools.build.lib.concurrent.ThreadSafety;
+import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore;
+
+/**
+ * Wrapper around PyCcLinkParamsProvider, to allow PythonProtoAspect to add Providers to
+ * proto_library rules with py_api_version. If PythonProtoAspect provides PyCcLinkParamsProvider
+ * directly on such a proto_library rule, Bazel crashes with
+ *
+ * Provider class PyCcLinkParamsProvider provided twice
+ */
+@ThreadSafety.Immutable
+public final class AspectPyCcLinkParamsProvider implements TransitiveInfoProvider {
+ public final PyCcLinkParamsProvider provider;
+ public AspectPyCcLinkParamsProvider(PyCcLinkParamsProvider provider) {
+ this.provider = provider;
+ }
+
+ public static final Function<TransitiveInfoCollection, CcLinkParamsStore> TO_LINK_PARAMS =
+ new Function<TransitiveInfoCollection, CcLinkParamsStore>() {
+ @Override
+ public CcLinkParamsStore apply(TransitiveInfoCollection input) {
+ AspectPyCcLinkParamsProvider wrapper = input.getProvider(
+ AspectPyCcLinkParamsProvider.class);
+ return wrapper == null ? null : wrapper.provider.getLinkParams();
+ }
+ };
+}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/AspectPythonRunfilesProvider.java b/src/main/java/com/google/devtools/build/lib/rules/python/AspectPythonRunfilesProvider.java
new file mode 100644
index 0000000000..39baf18e43
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/AspectPythonRunfilesProvider.java
@@ -0,0 +1,51 @@
+// Copyright 2015 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.python;
+
+import com.google.common.base.Function;
+import com.google.devtools.build.lib.analysis.Runfiles;
+import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
+import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
+import com.google.devtools.build.lib.concurrent.ThreadSafety;
+
+/**
+ * Wrapper around PythonRunfilesProvider, to allow PythonProtoAspect to add Providers to
+ * proto_library rules with py_api_version. If PythonProtoAspect provides PythonRunfilesProvider
+ * directly on such a proto_library rule, Bazel crashes with
+ *
+ * Provider class PythonRunfilesProvider provided twice
+ */
+@ThreadSafety.Immutable
+public final class AspectPythonRunfilesProvider implements TransitiveInfoProvider {
+ public final PythonRunfilesProvider provider;
+ public AspectPythonRunfilesProvider(PythonRunfilesProvider provider) {
+ this.provider = provider;
+ }
+
+ /**
+ * A function that gets the Python runfiles from a {@link TransitiveInfoCollection} or
+ * the empty runfiles instance if it does not contain that provider.
+ */
+ public static final Function<TransitiveInfoCollection, Runfiles> TO_RUNFILES =
+ new Function<TransitiveInfoCollection, Runfiles>() {
+ @Override
+ public Runfiles apply(TransitiveInfoCollection input) {
+ AspectPythonRunfilesProvider wrapper =
+ input.getProvider(AspectPythonRunfilesProvider.class);
+ return wrapper == null
+ ? Runfiles.EMPTY
+ : wrapper.provider.getPythonRunfiles();
+ }
+ };
+}