aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java28
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java18
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/ParserInputSource.java11
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java6
6 files changed, 54 insertions, 13 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
index fe44617e02..9bc6bf226c 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
@@ -52,19 +52,24 @@ public class ASTFileLookupFunction implements SkyFunction {
/** If {@code lookupSuccessful()}, returns the {@link RootedPath} to the file. */
public abstract RootedPath rootedPath();
+ /** If {@code lookupSuccessful()}, returns the file's size, in bytes. */
+ public abstract long fileSize();
+
static FileLookupResult noFile() {
return UnsuccessfulFileResult.INSTANCE;
}
- static FileLookupResult file(RootedPath rootedPath) {
- return new SuccessfulFileResult(rootedPath);
+ static FileLookupResult file(RootedPath rootedPath, long fileSize) {
+ return new SuccessfulFileResult(rootedPath, fileSize);
}
private static class SuccessfulFileResult extends FileLookupResult {
private final RootedPath rootedPath;
+ private final long fileSize;
- private SuccessfulFileResult(RootedPath rootedPath) {
+ private SuccessfulFileResult(RootedPath rootedPath, long fileSize) {
this.rootedPath = rootedPath;
+ this.fileSize = fileSize;
}
@Override
@@ -76,6 +81,11 @@ public class ASTFileLookupFunction implements SkyFunction {
public RootedPath rootedPath() {
return rootedPath;
}
+
+ @Override
+ public long fileSize() {
+ return fileSize;
+ }
}
private static class UnsuccessfulFileResult extends FileLookupResult {
@@ -92,6 +102,11 @@ public class ASTFileLookupFunction implements SkyFunction {
public RootedPath rootedPath() {
throw new IllegalStateException("unsuccessful lookup");
}
+
+ @Override
+ public long fileSize() {
+ throw new IllegalStateException("unsuccessful lookup");
+ }
}
}
@@ -121,12 +136,13 @@ public class ASTFileLookupFunction implements SkyFunction {
}
BuildFileAST ast = null;
Path path = lookupResult.rootedPath().asPath();
+ long fileSize = lookupResult.fileSize();
// Skylark files end with bzl.
boolean parseAsSkylark = astFilePathFragment.getPathString().endsWith(".bzl");
try {
if (parseAsSkylark) {
try (Mutability mutability = Mutability.create("validate")) {
- ast = BuildFileAST.parseSkylarkFile(path, env.getListener(),
+ ast = BuildFileAST.parseSkylarkFile(path, fileSize, env.getListener(),
packageManager, new ValidationEnvironment(
ruleClassProvider.createSkylarkRuleClassEnvironment(
mutability,
@@ -137,7 +153,7 @@ public class ASTFileLookupFunction implements SkyFunction {
.setupDynamic(Runtime.PKG_NAME, Runtime.NONE)));
}
} else {
- ast = BuildFileAST.parseBuildFile(path, env.getListener(), packageManager, false);
+ ast = BuildFileAST.parseBuildFile(path, fileSize, env.getListener(), packageManager, false);
}
} catch (IOException e) {
throw new ASTLookupFunctionException(new ErrorReadingSkylarkExtensionException(
@@ -177,7 +193,7 @@ public class ASTFileLookupFunction implements SkyFunction {
return null;
}
if (fileValue.isFile()) {
- return FileLookupResult.file(rootedPath);
+ return FileLookupResult.file(rootedPath, fileValue.getSize());
}
}
return FileLookupResult.noFile();
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java
index 12eea02a7d..cf0bf4ebc7 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java
@@ -446,7 +446,7 @@ public class PackageFunction implements SkyFunction {
// Skylark dependencies.
reporter.handle(Event.progress("Loading package: " + packageName));
}
- inputSource = ParserInputSource.create(buildFilePath);
+ inputSource = ParserInputSource.create(buildFilePath, buildFileValue.getSize());
} catch (IOException e) {
env.getListener().handle(Event.error(Location.fromFile(buildFilePath), e.getMessage()));
// Note that we did this work, so we should conservatively report this error as transient.
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java
index ce45ca2155..14a40da427 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java
@@ -78,7 +78,7 @@ public class WorkspaceFileFunction implements SkyFunction {
}
try {
- parser.parse(ParserInputSource.create(repoWorkspace));
+ parser.parse(ParserInputSource.create(repoWorkspace, workspaceFileValue.getSize()));
} catch (IOException e) {
throw new WorkspaceFileFunctionException(e, Transience.TRANSIENT);
}
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java b/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java
index 8dac01edcf..cdd75d3d23 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java
@@ -218,7 +218,14 @@ public class BuildFileAST extends ASTNode {
public static BuildFileAST parseBuildFile(Path buildFile, EventHandler eventHandler,
CachingPackageLocator locator, boolean parsePython)
throws IOException {
- ParserInputSource inputSource = ParserInputSource.create(buildFile);
+ return parseBuildFile(buildFile, buildFile.getFileSize(), eventHandler, locator, parsePython);
+ }
+
+ public static BuildFileAST parseBuildFile(Path buildFile, long fileSize,
+ EventHandler eventHandler,
+ CachingPackageLocator locator, boolean parsePython)
+ throws IOException {
+ ParserInputSource inputSource = ParserInputSource.create(buildFile, fileSize);
return parseBuildFile(inputSource, eventHandler, locator, parsePython);
}
@@ -261,7 +268,14 @@ public class BuildFileAST extends ASTNode {
public static BuildFileAST parseSkylarkFile(Path file, EventHandler eventHandler,
CachingPackageLocator locator, ValidationEnvironment validationEnvironment)
throws IOException {
- ParserInputSource input = ParserInputSource.create(file);
+ return parseSkylarkFile(file, file.getFileSize(), eventHandler, locator,
+ validationEnvironment);
+ }
+
+ public static BuildFileAST parseSkylarkFile(Path file, long fileSize, EventHandler eventHandler,
+ CachingPackageLocator locator, ValidationEnvironment validationEnvironment)
+ throws IOException {
+ ParserInputSource input = ParserInputSource.create(file, fileSize);
Lexer lexer = new Lexer(input, eventHandler, false);
Parser.ParseResult result =
Parser.parseFileForSkylark(lexer, eventHandler, locator, validationEnvironment);
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/ParserInputSource.java b/src/main/java/com/google/devtools/build/lib/syntax/ParserInputSource.java
index 82b2a442e0..0877baa485 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/ParserInputSource.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/ParserInputSource.java
@@ -45,12 +45,19 @@ public abstract class ParserInputSource {
* all we care about here.
*/
public static ParserInputSource create(Path path) throws IOException {
+ return create(path, path.getFileSize());
+ }
+
+ public static ParserInputSource create(Path path, long fileSize) throws IOException {
+ if (fileSize > Integer.MAX_VALUE) {
+ throw new IOException("Cannot parse file with size larger than 2GB");
+ }
char[] content = FileSystemUtils.readContentAsLatin1(path);
- if (path.getFileSize() > content.length) {
+ if (fileSize > content.length) {
// This assertion is to help diagnose problems arising from the
// filesystem; see bugs and #859334 and #920195.
throw new IOException("Unexpected short read from file '" + path
- + "' (expected " + path.getFileSize() + ", got " + content.length + " bytes)");
+ + "' (expected " + fileSize + ", got " + content.length + " bytes)");
}
return create(content, path.asFragment());
}
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
index 7068278951..02e1f8b2ce 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
@@ -664,7 +664,11 @@ public abstract class BuildViewTestCase extends FoundationTestCase {
*/
protected Rule scratchRule(String packageName, String ruleName, String... lines)
throws Exception {
- scratch.file(packageName + "/BUILD", lines);
+ String buildFilePathString = packageName + "/BUILD";
+ scratch.file(buildFilePathString, lines);
+ skyframeExecutor.invalidateFilesUnderPathForTesting(
+ new ModifiedFileSet.Builder().modify(new PathFragment(buildFilePathString)).build(),
+ rootDirectory);
return (Rule) getTarget("//" + packageName + ":" + ruleName);
}