From 8ed31f05e664e925ad628ab47feeaaab30c26283 Mon Sep 17 00:00:00 2001 From: Ulf Adams Date: Fri, 22 Apr 2016 09:00:13 +0000 Subject: Remove all internal calls to FileProvider.getLabel. The method will be removed in a subsequent change to facilitate reverting the change in case it goes bad. -- MOS_MIGRATED_REVID=120526894 --- .../build/lib/analysis/LocationExpander.java | 7 ++++--- .../build/lib/rules/android/ApplicationManifest.java | 4 ++-- .../lib/rules/android/LocalResourceContainer.java | 7 ++++--- .../devtools/build/lib/rules/cpp/CcCommon.java | 20 ++++++++++---------- .../devtools/build/lib/rules/cpp/CppHelper.java | 6 +++--- .../devtools/build/lib/rules/python/PyCommon.java | 9 +++++---- 6 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java b/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java index d2b7e181f2..9761d6a2b9 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java @@ -281,9 +281,10 @@ public class LocationExpander { } if (ruleContext.getRule().isAttrDefined("srcs", BuildType.LABEL_LIST)) { - for (FileProvider src : ruleContext - .getPrerequisites("srcs", Mode.TARGET, FileProvider.class)) { - Iterables.addAll(mapGet(locationMap, src.getLabel()), src.getFilesToBuild()); + for (TransitiveInfoCollection src : ruleContext + .getPrerequisitesIf("srcs", Mode.TARGET, FileProvider.class)) { + Iterables.addAll(mapGet(locationMap, src.getLabel()), + src.getProvider(FileProvider.class).getFilesToBuild()); } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java b/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java index 0a66657ef0..6d40de3b00 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java @@ -200,7 +200,7 @@ public final class ApplicationManifest { LocalResourceContainer data = new LocalResourceContainer.Builder(ruleContext) .withAssets( AndroidCommon.getAssetDir(ruleContext), - ruleContext.getPrerequisites( + ruleContext.getPrerequisitesIf( // TODO(bazel-team): Remove the ResourceType construct. ResourceType.ASSETS.getAttribute(), Mode.TARGET, @@ -250,7 +250,7 @@ public final class ApplicationManifest { LocalResourceContainer data = new LocalResourceContainer.Builder(ruleContext) .withAssets( AndroidCommon.getAssetDir(ruleContext), - ruleContext.getPrerequisites( + ruleContext.getPrerequisitesIf( // TODO(bazel-team): Remove the ResourceType construct. ResourceType.ASSETS.getAttribute(), Mode.TARGET, diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/LocalResourceContainer.java b/src/main/java/com/google/devtools/build/lib/rules/android/LocalResourceContainer.java index 68ec8bd92a..3d5226cceb 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/LocalResourceContainer.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/LocalResourceContainer.java @@ -21,6 +21,7 @@ import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.FileProvider; import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.analysis.RuleContext; +import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.packages.AttributeMap; import com.google.devtools.build.lib.rules.android.AndroidResourcesProvider.ResourceType; @@ -160,9 +161,9 @@ public final class LocalResourceContainer { * @return The Builder. */ public LocalResourceContainer.Builder withAssets( - PathFragment assetsDir, Iterable targets) { - for (FileProvider target : targets) { - for (Artifact file : target.getFilesToBuild()) { + PathFragment assetsDir, Iterable targets) { + for (TransitiveInfoCollection target : targets) { + for (Artifact file : target.getProvider(FileProvider.class).getFilesToBuild()) { PathFragment packageFragment = file.getArtifactOwner().getLabel() .getPackageIdentifier().getPathFragment(); PathFragment packageRelativePath = diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java index 6190ad10a5..e1c13485cf 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java @@ -199,10 +199,10 @@ public final class CcCommon { */ List> getSources() { Map map = Maps.newLinkedHashMap(); - Iterable providers = - ruleContext.getPrerequisites("srcs", Mode.TARGET, FileProvider.class); - for (FileProvider provider : providers) { - for (Artifact artifact : provider.getFilesToBuild()) { + Iterable providers = + ruleContext.getPrerequisitesIf("srcs", Mode.TARGET, FileProvider.class); + for (TransitiveInfoCollection provider : providers) { + for (Artifact artifact : provider.getProvider(FileProvider.class).getFilesToBuild()) { // TODO(bazel-team): We currently do not produce an error for duplicate headers and other // non-source artifacts with different labels, as that would require cleaning up the code // base without significant benefit; we should eventually make this consistent one way or @@ -243,15 +243,15 @@ public final class CcCommon { + "' from target '" + target.getLabel() + "' is not allowed in hdrs"); continue; } - Label oldLabel = map.put(artifact, provider.getLabel()); - if (oldLabel != null && !oldLabel.equals(provider.getLabel())) { + Label oldLabel = map.put(artifact, target.getLabel()); + if (oldLabel != null && !oldLabel.equals(target.getLabel())) { ruleContext.attributeWarning( "hdrs", String.format( "Artifact '%s' is duplicated (through '%s' and '%s')", artifact.getExecPathString(), oldLabel, - provider.getLabel())); + target.getLabel())); } } } @@ -359,10 +359,10 @@ public final class CcCommon { // Gather up all the dirs from the rule's srcs as well as any of the srcs outputs. if (hasAttribute("srcs", BuildType.LABEL_LIST)) { - for (FileProvider src : - ruleContext.getPrerequisites("srcs", Mode.TARGET, FileProvider.class)) { + for (TransitiveInfoCollection src : + ruleContext.getPrerequisitesIf("srcs", Mode.TARGET, FileProvider.class)) { PathFragment packageDir = src.getLabel().getPackageIdentifier().getPathFragment(); - for (Artifact a : src.getFilesToBuild()) { + for (Artifact a : src.getProvider(FileProvider.class).getFilesToBuild()) { result.add(packageDir); // Attempt to gather subdirectories that might contain include files. result.add(a.getRootRelativePath().getParentDirectory()); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java index 300c87e122..de2c88f5f0 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java @@ -197,10 +197,10 @@ public class CppHelper { try { Label label = ruleContext.getLabel().getRelative(labelName); for (String prereqKind : LINKOPTS_PREREQUISITE_LABEL_KINDS) { - for (FileProvider target : ruleContext - .getPrerequisites(prereqKind, Mode.TARGET, FileProvider.class)) { + for (TransitiveInfoCollection target : ruleContext + .getPrerequisitesIf(prereqKind, Mode.TARGET, FileProvider.class)) { if (target.getLabel().equals(label)) { - for (Artifact artifact : target.getFilesToBuild()) { + for (Artifact artifact : target.getProvider(FileProvider.class).getFilesToBuild()) { linkopts.add(artifact.getExecPathString()); } return true; 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 50aebce23b..045c06ca4e 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 @@ -180,15 +180,16 @@ public final class PyCommon { List sourceFiles = new ArrayList<>(); // TODO(bazel-team): Need to get the transitive deps closure, not just the // sources of the rule. - for (FileProvider src : ruleContext - .getPrerequisites("srcs", Mode.TARGET, FileProvider.class)) { + for (TransitiveInfoCollection src : ruleContext + .getPrerequisitesIf("srcs", Mode.TARGET, FileProvider.class)) { // Make sure that none of the sources contain hyphens. if (Util.containsHyphen(src.getLabel().getPackageFragment())) { ruleContext.attributeError("srcs", src.getLabel() + ": paths to Python packages may not contain '-'"); } - Iterable pySrcs = FileType.filter(src.getFilesToBuild(), - PyRuleClasses.PYTHON_SOURCE); + Iterable pySrcs = + FileType.filter( + src.getProvider(FileProvider.class).getFilesToBuild(), PyRuleClasses.PYTHON_SOURCE); Iterables.addAll(sourceFiles, pySrcs); if (Iterables.isEmpty(pySrcs)) { ruleContext.attributeWarning("srcs", -- cgit v1.2.3