diff options
author | 2015-05-29 12:37:47 +0000 | |
---|---|---|
committer | 2015-06-01 15:47:06 +0000 | |
commit | 578d055624b76101af5053b6447372d746248597 (patch) | |
tree | b99626b345d8dd04e59eea1a53447d697d5d07c7 /src/main/java/com/google/devtools/build/lib/rules/python | |
parent | a1c73f9e7c571da6db6fc14ea63ce0b50d36a3cb (diff) |
Expose Python provider to Skylark
It is now possible to access transitive sources from py_binary and py_library
rules with target.py.transitive_sources
--
MOS_MIGRATED_REVID=94751866
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/python')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java | 7 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/python/PythonSourcesProvider.java | 5 |
2 files changed, 8 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java b/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java index 5f3a3ad9c9..73deb8360f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java @@ -120,13 +120,15 @@ public final class PyCommon { public void addCommonTransitiveInfoProviders(RuleConfiguredTargetBuilder builder, PythonSemantics semantics, NestedSet<Artifact> filesToBuild) { + PythonSourcesProvider sourcesProvider = + new PythonSourcesProvider(transitivePythonSources, usesSharedLibraries()); builder .add(InstrumentedFilesProvider.class, new InstrumentedFilesProviderImpl( new InstrumentedFilesCollector(ruleContext, semantics.getCoverageInstrumentationSpec(), METADATA_COLLECTOR, filesToBuild))) - .add(PythonSourcesProvider.class, new PythonSourcesProvider( - transitivePythonSources, usesSharedLibraries())) + .add(PythonSourcesProvider.class, sourcesProvider) + .addSkylarkTransitiveInfo(PythonSourcesProvider.SKYLARK_NAME, sourcesProvider) // Python targets are not really compilable. The best we can do is make sure that all // generated source files are ready. .addOutputGroup(OutputGroupProvider.FILES_TO_COMPILE, transitivePythonSources) @@ -401,4 +403,3 @@ public final class PyCommon { } } } - diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PythonSourcesProvider.java b/src/main/java/com/google/devtools/build/lib/rules/python/PythonSourcesProvider.java index 7df4609db8..fcdb8cfb89 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/python/PythonSourcesProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/python/PythonSourcesProvider.java @@ -27,6 +27,8 @@ import com.google.devtools.build.lib.syntax.SkylarkModule; @Immutable @SkylarkModule(name = "PythonSourcesProvider", doc = "") public final class PythonSourcesProvider implements TransitiveInfoProvider { + /** The name of the field in Skylark used to access this class. */ + public static final String SKYLARK_NAME = "py"; private final NestedSet<Artifact> transitivePythonSources; private final boolean usesSharedLibraries; @@ -40,7 +42,8 @@ public final class PythonSourcesProvider implements TransitiveInfoProvider { /** * Returns the Python sources in the transitive closure of this target. */ - @SkylarkCallable(name = "transitive_srcs", doc = "", structField = true) + @SkylarkCallable( + name = "transitive_sources", doc = "The transitive set of Python sources", structField = true) public NestedSet<Artifact> getTransitivePythonSources() { return transitivePythonSources; } |