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

Commit 166d433

Browse files
sbalabanov-zzfacebook-github-bot
authored andcommitted
Fix BuildTargetToRawTargetNodeComputation to call factory properly
Summary: In fact verifier accepts absolute paths only Reviewed By: bobyangyf fbshipit-source-id: c7775a4e4b
1 parent 37838bd commit 166d433

4 files changed

+15
-8
lines changed

src/com/facebook/buck/parser/BuiltTargetVerifier.java

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class BuiltTargetVerifier {
3636

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

39+
/** @param buildFile Absolute path to build file that contains build target being verified */
3940
void verifyBuildTarget(
4041
Cell cell,
4142
RuleType buildRuleType,

src/com/facebook/buck/parser/RawTargetNodeFactory.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public interface RawTargetNodeFactory<T> {
2828
* Create new {@link RawTargetNode}
2929
*
3030
* @param cell {@Cell} object that current build target belongs to
31-
* @param buildFile A path to a build file that has the corresponding build target; can be either
32-
* absolute or relative, only used for displaying errors
31+
* @param buildFile An absolute path to a build file that has the corresponding build target
3332
* @param buildTarget A build target that uniquely identifies created {@link RawTargetNode}
3433
* @param rawNode Raw attributes that forms the node, usually a Map where a key is attribute name
3534
* as string and value is attribute value as object.

src/com/facebook/buck/parser/UnflavoredBuildTargetFactory.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ public class UnflavoredBuildTargetFactory {
2929
private UnflavoredBuildTargetFactory() {}
3030

3131
/**
32-
* @param cellRoot root path to the cell the rule is defined in.
32+
* @param cellRoot Absolute path to the root of the cell the rule is defined in.
3333
* @param map the map of values that define the rule.
34-
* @param rulePathForDebug path to the build file the rule is defined in, only used for debugging.
34+
* @param buildFilePath Absolute path to the build file the rule is defined in
3535
* @return the build target defined by the rule.
3636
*/
3737
public static UnflavoredBuildTargetView createFromRawNode(
38-
Path cellRoot, Optional<String> cellName, Map<String, Object> map, Path rulePathForDebug) {
38+
Path cellRoot, Optional<String> cellName, Map<String, Object> map, Path buildFilePath) {
3939
@Nullable String basePath = (String) map.get(InternalTargetAttributeNames.BASE_PATH);
4040
@Nullable String name = (String) map.get("name");
4141
if (basePath == null || name == null) {
4242
throw new IllegalStateException(
4343
String.format(
4444
"Attempting to parse build target from malformed raw data in %s: %s.",
45-
rulePathForDebug, Joiner.on(",").withKeyValueSeparator("->").join(map)));
45+
buildFilePath, Joiner.on(",").withKeyValueSeparator("->").join(map)));
4646
}
47-
Path otherBasePath = cellRoot.relativize(MorePaths.getParentOrEmpty(rulePathForDebug));
47+
Path otherBasePath = cellRoot.relativize(MorePaths.getParentOrEmpty(buildFilePath));
4848
if (!otherBasePath.equals(otherBasePath.getFileSystem().getPath(basePath))) {
4949
throw new IllegalStateException(
5050
String.format(

src/com/facebook/buck/parser/targetnode/BuildTargetToRawTargetNodeComputation.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@
2626
import com.facebook.buck.core.model.UnconfiguredBuildTargetView;
2727
import com.facebook.buck.core.model.impl.ImmutableUnconfiguredBuildTargetView;
2828
import com.facebook.buck.core.model.targetgraph.raw.RawTargetNode;
29+
import com.facebook.buck.parser.ParserConfig;
2930
import com.facebook.buck.parser.RawTargetNodeFactory;
3031
import com.facebook.buck.parser.api.BuildFileManifest;
3132
import com.facebook.buck.parser.exceptions.NoSuchBuildTargetException;
3233
import com.facebook.buck.parser.manifest.BuildPackagePathToBuildFileManifestKey;
3334
import com.facebook.buck.parser.manifest.ImmutableBuildPackagePathToBuildFileManifestKey;
3435
import com.google.common.collect.ImmutableSet;
36+
import java.nio.file.Path;
3537
import java.util.Map;
3638
import javax.annotation.Nullable;
3739

@@ -41,11 +43,16 @@ public class BuildTargetToRawTargetNodeComputation
4143

4244
private final RawTargetNodeFactory<Map<String, Object>> rawTargetNodeFactory;
4345
private final Cell cell;
46+
private final Path buildFileName;
4447

4548
private BuildTargetToRawTargetNodeComputation(
4649
RawTargetNodeFactory<Map<String, Object>> rawTargetNodeFactory, Cell cell) {
4750
this.rawTargetNodeFactory = rawTargetNodeFactory;
4851
this.cell = cell;
52+
buildFileName =
53+
cell.getRoot()
54+
.getFileSystem()
55+
.getPath(cell.getBuckConfigView(ParserConfig.class).getBuildFileName());
4956
}
5057

5158
/**
@@ -83,7 +90,7 @@ public RawTargetNode transform(BuildTargetToRawTargetNodeKey key, ComputationEnv
8390

8491
return rawTargetNodeFactory.create(
8592
cell,
86-
unconfiguredBuildTargetView.getBasePath(),
93+
cell.getRoot().resolve(unconfiguredBuildTargetView.getBasePath()).resolve(buildFileName),
8794
unconfiguredBuildTargetView,
8895
rawAttributes);
8996
}

0 commit comments

Comments
 (0)