aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skyframe/TargetMarkerFunction.java
diff options
context:
space:
mode:
authorGravatar Mark Schaller <mschaller@google.com>2015-10-23 01:00:28 +0000
committerGravatar John Field <jfield@google.com>2015-10-23 14:56:10 +0000
commit6b6d8a9ff4afa06fa7874945e6c700d944e09ea1 (patch)
tree0eda01475d29180d5d3570809f14d72f82ceb03c /src/main/java/com/google/devtools/build/lib/skyframe/TargetMarkerFunction.java
parent8cb6f7b8a046cbebf64137a5befdc41b8177305d (diff)
Inline TargetMarker in TransitiveTraversalFunction
Simplifies the runtime graph when TransitiveTraversalFunction is used. Also moves an error reporting method from the base function to the TransitiveTargetFunction, which is the only one that uses it. -- MOS_MIGRATED_REVID=106109745
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/TargetMarkerFunction.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/TargetMarkerFunction.java71
1 files changed, 35 insertions, 36 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TargetMarkerFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/TargetMarkerFunction.java
index 3e3fbd5fb5..74d78dcba8 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/TargetMarkerFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/TargetMarkerFunction.java
@@ -27,6 +27,8 @@ import com.google.devtools.build.skyframe.SkyFunctionException;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
+import javax.annotation.Nullable;
+
/**
* A SkyFunction for {@link TargetMarkerValue}s. Returns a {@link
* TargetMarkerValue#TARGET_MARKER_INSTANCE} if the {@link Label} in the {@link SkyKey}
@@ -35,11 +37,21 @@ import com.google.devtools.build.skyframe.SkyValue;
*/
public final class TargetMarkerFunction implements SkyFunction {
- public TargetMarkerFunction() {
- }
-
@Override
public SkyValue compute(SkyKey key, Environment env) throws TargetMarkerFunctionException {
+ try {
+ return computeTargetMarkerValue(key, env);
+ } catch (NoSuchTargetException e) {
+ throw new TargetMarkerFunctionException(e);
+ } catch (NoSuchPackageException e) {
+ // Re-throw this exception with our key because root causes should be targets, not packages.
+ throw new TargetMarkerFunctionException(e);
+ }
+ }
+
+ @Nullable
+ static TargetMarkerValue computeTargetMarkerValue(SkyKey key, Environment env)
+ throws NoSuchTargetException, NoSuchPackageException {
Label label = (Label) key.argument();
PathFragment pkgForLabel = label.getPackageFragment();
@@ -47,67 +59,54 @@ public final class TargetMarkerFunction implements SkyFunction {
// This target is in a subdirectory, therefore it could potentially be invalidated by
// a new BUILD file appearing in the hierarchy.
PathFragment containingDirectory = label.toPathFragment().getParentDirectory();
- ContainingPackageLookupValue containingPackageLookupValue = null;
+ ContainingPackageLookupValue containingPackageLookupValue;
try {
PackageIdentifier newPkgId = PackageIdentifier.create(
label.getPackageIdentifier().getRepository(), containingDirectory);
containingPackageLookupValue = (ContainingPackageLookupValue) env.getValueOrThrow(
ContainingPackageLookupValue.key(newPkgId),
BuildFileNotFoundException.class, InconsistentFilesystemException.class);
- } catch (BuildFileNotFoundException e) {
- // Thrown when there are IO errors looking for BUILD files.
- throw new TargetMarkerFunctionException(e);
} catch (InconsistentFilesystemException e) {
- throw new TargetMarkerFunctionException(new NoSuchTargetException(label,
- e.getMessage()));
+ throw new NoSuchTargetException(label, e.getMessage());
}
if (containingPackageLookupValue == null) {
return null;
}
+
if (!containingPackageLookupValue.hasContainingPackage()) {
// This means the label's package doesn't exist. E.g. there is no package 'a' and we are
// trying to build the target for label 'a:b/foo'.
- throw new TargetMarkerFunctionException(new BuildFileNotFoundException(
- label.getPackageIdentifier(), "BUILD file not found on package path for '"
- + pkgForLabel.getPathString() + "'"));
+ throw new BuildFileNotFoundException(
+ label.getPackageIdentifier(),
+ "BUILD file not found on package path for '" + pkgForLabel.getPathString() + "'");
}
if (!containingPackageLookupValue.getContainingPackageName().equals(
label.getPackageIdentifier())) {
- throw new TargetMarkerFunctionException(new NoSuchTargetException(label,
- String.format("Label '%s' crosses boundary of subpackage '%s'", label,
- containingPackageLookupValue.getContainingPackageName())));
+ throw new NoSuchTargetException(
+ label,
+ String.format(
+ "Label '%s' crosses boundary of subpackage '%s'",
+ label,
+ containingPackageLookupValue.getContainingPackageName()));
}
}
SkyKey pkgSkyKey = PackageValue.key(label.getPackageIdentifier());
- Package pkg;
- try {
- PackageValue value = (PackageValue)
- env.getValueOrThrow(pkgSkyKey, NoSuchPackageException.class);
- if (value == null) {
- return null;
- }
- pkg = value.getPackage();
- } catch (NoSuchPackageException e) {
- // Re-throw this exception with our key because root causes should be targets, not packages.
- throw new TargetMarkerFunctionException(e);
- }
-
- Target target;
- try {
- target = pkg.getTarget(label.getName());
- } catch (NoSuchTargetException e) {
- throw new TargetMarkerFunctionException(e);
+ PackageValue value =
+ (PackageValue) env.getValueOrThrow(pkgSkyKey, NoSuchPackageException.class);
+ if (value == null) {
+ return null;
}
+ Package pkg = value.getPackage();
+ Target target = pkg.getTarget(label.getName());
if (pkg.containsErrors()) {
// There is a target, but its package is in error. We rethrow so that the root cause is the
// target, not the package. Note that targets are only in error when their package is
// "in error" (because a package is in error if there was an error evaluating the package, or
// if one of its targets was in error).
- throw new TargetMarkerFunctionException(
- new NoSuchTargetException(
- target, new BuildFileContainsErrorsException(label.getPackageIdentifier())));
+ throw new NoSuchTargetException(
+ target, new BuildFileContainsErrorsException(label.getPackageIdentifier()));
}
return TargetMarkerValue.TARGET_MARKER_INSTANCE;
}