From e80cccd667a658a62efb99655156956c0ed813f7 Mon Sep 17 00:00:00 2001 From: Carmi Grushko Date: Wed, 11 Nov 2015 19:12:31 +0000 Subject: -- MOS_MIGRATED_REVID=107604619 --- .../devtools/build/lib/packages/Attribute.java | 5 +++ .../rules/python/AspectPyCcLinkParamsProvider.java | 45 +++++++++++++++++++ .../rules/python/AspectPythonRunfilesProvider.java | 51 ++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 src/main/java/com/google/devtools/build/lib/rules/python/AspectPyCcLinkParamsProvider.java create mode 100644 src/main/java/com/google/devtools/build/lib/rules/python/AspectPythonRunfilesProvider.java (limited to 'src') 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 { private final Set allowedValues; + public 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 TO_LINK_PARAMS = + new Function() { + @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 TO_RUNFILES = + new Function() { + @Override + public Runfiles apply(TransitiveInfoCollection input) { + AspectPythonRunfilesProvider wrapper = + input.getProvider(AspectPythonRunfilesProvider.class); + return wrapper == null + ? Runfiles.EMPTY + : wrapper.provider.getPythonRunfiles(); + } + }; +} -- cgit v1.2.3