Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Fix BuildTargetToRawTargetNodeComputation to call factory properly
Browse files Browse the repository at this point in the history
Summary: In fact verifier accepts absolute paths only

Reviewed By: bobyangyf

fbshipit-source-id: c7775a4e4b
  • Loading branch information
sbalabanov-zz authored and facebook-github-bot committed May 14, 2019
1 parent 37838bd commit 166d433
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/com/facebook/buck/parser/BuiltTargetVerifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class BuiltTargetVerifier {

private static final Logger LOG = Logger.get(BuiltTargetVerifier.class);

/** @param buildFile Absolute path to build file that contains build target being verified */
void verifyBuildTarget(
Cell cell,
RuleType buildRuleType,
Expand Down
3 changes: 1 addition & 2 deletions src/com/facebook/buck/parser/RawTargetNodeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public interface RawTargetNodeFactory<T> {
* Create new {@link RawTargetNode}
*
* @param cell {@Cell} object that current build target belongs to
* @param buildFile A path to a build file that has the corresponding build target; can be either
* absolute or relative, only used for displaying errors
* @param buildFile An absolute path to a build file that has the corresponding build target
* @param buildTarget A build target that uniquely identifies created {@link RawTargetNode}
* @param rawNode Raw attributes that forms the node, usually a Map where a key is attribute name
* as string and value is attribute value as object.
Expand Down
10 changes: 5 additions & 5 deletions src/com/facebook/buck/parser/UnflavoredBuildTargetFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ public class UnflavoredBuildTargetFactory {
private UnflavoredBuildTargetFactory() {}

/**
* @param cellRoot root path to the cell the rule is defined in.
* @param cellRoot Absolute path to the root of the cell the rule is defined in.
* @param map the map of values that define the rule.
* @param rulePathForDebug path to the build file the rule is defined in, only used for debugging.
* @param buildFilePath Absolute path to the build file the rule is defined in
* @return the build target defined by the rule.
*/
public static UnflavoredBuildTargetView createFromRawNode(
Path cellRoot, Optional<String> cellName, Map<String, Object> map, Path rulePathForDebug) {
Path cellRoot, Optional<String> cellName, Map<String, Object> map, Path buildFilePath) {
@Nullable String basePath = (String) map.get(InternalTargetAttributeNames.BASE_PATH);
@Nullable String name = (String) map.get("name");
if (basePath == null || name == null) {
throw new IllegalStateException(
String.format(
"Attempting to parse build target from malformed raw data in %s: %s.",
rulePathForDebug, Joiner.on(",").withKeyValueSeparator("->").join(map)));
buildFilePath, Joiner.on(",").withKeyValueSeparator("->").join(map)));
}
Path otherBasePath = cellRoot.relativize(MorePaths.getParentOrEmpty(rulePathForDebug));
Path otherBasePath = cellRoot.relativize(MorePaths.getParentOrEmpty(buildFilePath));
if (!otherBasePath.equals(otherBasePath.getFileSystem().getPath(basePath))) {
throw new IllegalStateException(
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
import com.facebook.buck.core.model.UnconfiguredBuildTargetView;
import com.facebook.buck.core.model.impl.ImmutableUnconfiguredBuildTargetView;
import com.facebook.buck.core.model.targetgraph.raw.RawTargetNode;
import com.facebook.buck.parser.ParserConfig;
import com.facebook.buck.parser.RawTargetNodeFactory;
import com.facebook.buck.parser.api.BuildFileManifest;
import com.facebook.buck.parser.exceptions.NoSuchBuildTargetException;
import com.facebook.buck.parser.manifest.BuildPackagePathToBuildFileManifestKey;
import com.facebook.buck.parser.manifest.ImmutableBuildPackagePathToBuildFileManifestKey;
import com.google.common.collect.ImmutableSet;
import java.nio.file.Path;
import java.util.Map;
import javax.annotation.Nullable;

Expand All @@ -41,11 +43,16 @@ public class BuildTargetToRawTargetNodeComputation

private final RawTargetNodeFactory<Map<String, Object>> rawTargetNodeFactory;
private final Cell cell;
private final Path buildFileName;

private BuildTargetToRawTargetNodeComputation(
RawTargetNodeFactory<Map<String, Object>> rawTargetNodeFactory, Cell cell) {
this.rawTargetNodeFactory = rawTargetNodeFactory;
this.cell = cell;
buildFileName =
cell.getRoot()
.getFileSystem()
.getPath(cell.getBuckConfigView(ParserConfig.class).getBuildFileName());
}

/**
Expand Down Expand Up @@ -83,7 +90,7 @@ public RawTargetNode transform(BuildTargetToRawTargetNodeKey key, ComputationEnv

return rawTargetNodeFactory.create(
cell,
unconfiguredBuildTargetView.getBasePath(),
cell.getRoot().resolve(unconfiguredBuildTargetView.getBasePath()).resolve(buildFileName),
unconfiguredBuildTargetView,
rawAttributes);
}
Expand Down

0 comments on commit 166d433

Please sign in to comment.