Skylark: path in load statement either has to be absolute or has to have exactly one segment.
--
MOS_MIGRATED_REVID=87234901
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupValue.java
index 37ad743..c9b7a88 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupValue.java
@@ -62,7 +62,7 @@
}
static final class ASTLookupInputException extends Exception {
- private ASTLookupInputException(String msg) {
+ ASTLookupInputException(String msg) {
super(msg);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupValue.java
index fc46f78..20579cc 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupValue.java
@@ -18,6 +18,7 @@
import com.google.devtools.build.lib.packages.PackageIdentifier;
import com.google.devtools.build.lib.packages.PackageIdentifier.RepositoryName;
import com.google.devtools.build.lib.skyframe.ASTFileLookupValue.ASTLookupInputException;
+import com.google.devtools.build.lib.syntax.LoadStatement;
import com.google.devtools.build.lib.syntax.SkylarkEnvironment;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.skyframe.SkyKey;
@@ -67,12 +68,10 @@
PathFragment computedPath;
if (fileToImport.isAbsolute()) {
computedPath = fileToImport.toRelative();
- } else if (fileToImport.segmentCount() > 1) {
- // TODO(bazel-team): we treat paths with more then 1 segments as absolute paths
- // for a transition period. Remove this after the transition is over.
- computedPath = fileToImport;
- } else {
+ } else if (fileToImport.segmentCount() == 1) {
computedPath = fromFile.getParentDirectory().getRelative(fileToImport);
+ } else {
+ throw new ASTLookupInputException(String.format(LoadStatement.PATH_ERROR_MSG, fileToImport));
}
return key(repo, computedPath);
}
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/LoadStatement.java b/src/main/java/com/google/devtools/build/lib/syntax/LoadStatement.java
index 6873995..9c59989 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/LoadStatement.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/LoadStatement.java
@@ -24,6 +24,8 @@
*/
public final class LoadStatement extends Statement {
+ public static final String PATH_ERROR_MSG = "Path '%s' is not valid. "
+ + "It should either start with a slash or refer to a file in the current directory.";
private final ImmutableList<Ident> symbols;
private final PathFragment importPath;
@@ -70,6 +72,9 @@
@Override
void validate(ValidationEnvironment env) throws EvalException {
+ if (!importPath.isAbsolute() && importPath.segmentCount() > 1) {
+ throw new EvalException(getLocation(), String.format(PATH_ERROR_MSG, importPath));
+ }
// TODO(bazel-team): implement semantical check.
for (Ident symbol : symbols) {
env.update(symbol.getName(), SkylarkType.UNKNOWN, getLocation());