diff options
author | 2015-06-15 07:12:46 +0000 | |
---|---|---|
committer | 2015-06-15 10:52:01 +0000 | |
commit | e753ecf58281ad33dcf827462fce4f16596666e7 (patch) | |
tree | 49ab951ae9abcd92efc7df4dea0aadb98164ba0b /src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java | |
parent | 833acc8a1a41511d80651767af02736c61b8a81b (diff) |
Get jdk.WORKSPACE into the default WORKSPACE file by reading it as a Java resource, then passing it to the parser as a string instead of putting it into embedded_binaries then passing a Path to it to the parser.
This makes the upcoming default WORKSPACE rules for Android much more palatable. In particular, Android rules won't need to be special cased when building the Bazel binary because the contents are self-contained in BazelRuleClassProvider (and the jdk.WORKSPACE file, which is a simple Java resource)
Even better would be not to use a string, but some kind of structured data, but that's probably more effort than it's worth.
--
MOS_MIGRATED_REVID=95983199
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java | 42 |
1 files changed, 20 insertions, 22 deletions
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 ea54ef0e46..cab94da5a7 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 @@ -27,6 +27,7 @@ import com.google.devtools.build.lib.packages.ExternalPackage.Builder.NoSuchBind import com.google.devtools.build.lib.packages.Package.NameConflictException; import com.google.devtools.build.lib.packages.PackageFactory; import com.google.devtools.build.lib.packages.RuleClass; +import com.google.devtools.build.lib.packages.RuleClassProvider; import com.google.devtools.build.lib.packages.RuleFactory; import com.google.devtools.build.lib.packages.Type.ConversionException; import com.google.devtools.build.lib.syntax.BaseFunction; @@ -49,7 +50,6 @@ import com.google.devtools.build.skyframe.SkyValue; import java.io.File; import java.io.IOException; -import java.util.List; import java.util.Map; /** @@ -61,10 +61,15 @@ public class WorkspaceFileFunction implements SkyFunction { private final PackageFactory packageFactory; private final Path installDir; + private final RuleClassProvider ruleClassProvider; - WorkspaceFileFunction(PackageFactory packageFactory, BlazeDirectories directories) { + WorkspaceFileFunction( + RuleClassProvider ruleClassProvider, + PackageFactory packageFactory, + BlazeDirectories directories) { this.packageFactory = packageFactory; this.installDir = directories.getEmbeddedBinariesRoot(); + this.ruleClassProvider = ruleClassProvider; } @Override @@ -78,18 +83,19 @@ public class WorkspaceFileFunction implements SkyFunction { Path repoWorkspace = workspaceRoot.getRoot().getRelative(workspaceRoot.getRelativePath()); Builder builder = new Builder(repoWorkspace); - List<PathFragment> workspaceFiles = packageFactory.getRuleClassProvider().getWorkspaceFiles(); - for (PathFragment workspaceFile : workspaceFiles) { - workspaceRoot = RootedPath.toRootedPath(installDir, workspaceFile); - if (env.getValue(FileValue.key(workspaceRoot)) == null) { - return null; - } - parseWorkspaceFile(installDir.getRelative(workspaceFile), builder); - } + parseWorkspaceFile( + ParserInputSource.create( + ruleClassProvider.getDefaultWorkspaceFile(), new PathFragment("DEFAULT.WORKSPACE")), + builder); if (!workspaceFileValue.exists()) { return new PackageValue(builder.build()); } - parseWorkspaceFile(repoWorkspace, builder); + try { + ParserInputSource repoWorkspaceSource = ParserInputSource.create(repoWorkspace); + parseWorkspaceFile(repoWorkspaceSource, builder); + } catch (IOException e) { + throw new WorkspaceFileFunctionException(e, Transience.TRANSIENT); + } try { builder.resolveBindTargets(packageFactory.getRuleClass(BIND)); } catch (NoSuchBindingException e) { @@ -102,24 +108,16 @@ public class WorkspaceFileFunction implements SkyFunction { return new PackageValue(builder.build()); } - private void parseWorkspaceFile(Path workspaceFilePath, Builder builder) + private void parseWorkspaceFile(ParserInputSource source, Builder builder) throws WorkspaceFileFunctionException, InterruptedException { StoredEventHandler localReporter = new StoredEventHandler(); BuildFileAST buildFileAST; - ParserInputSource inputSource = null; - - try { - inputSource = ParserInputSource.create(workspaceFilePath); - } catch (IOException e) { - throw new WorkspaceFileFunctionException(e, Transience.TRANSIENT); - } - buildFileAST = BuildFileAST.parseBuildFile(inputSource, localReporter, null, false); + buildFileAST = BuildFileAST.parseBuildFile(source, localReporter, null, false); if (buildFileAST.containsErrors()) { localReporter.handle(Event.error("WORKSPACE file could not be parsed")); } else { if (!evaluateWorkspaceFile(buildFileAST, builder, localReporter)) { - localReporter.handle( - Event.error("Error evaluating WORKSPACE file " + workspaceFilePath)); + localReporter.handle(Event.error("Error evaluating WORKSPACE file " + source.getPath())); } } |