Ejemplo n.º 1
0
  @Override
  public SkyValue compute(SkyKey skyKey, Environment env)
      throws WorkspaceFileFunctionException, InterruptedException {
    RootedPath workspaceRoot = (RootedPath) skyKey.argument();
    FileValue workspaceFileValue = (FileValue) env.getValue(FileValue.key(workspaceRoot));
    if (workspaceFileValue == null) {
      return null;
    }

    Path repoWorkspace = workspaceRoot.getRoot().getRelative(workspaceRoot.getRelativePath());
    Builder builder =
        new Builder(repoWorkspace, packageFactory.getRuleClassProvider().getRunfilesPrefix());
    WorkspaceFactory parser =
        new WorkspaceFactory(
            builder, packageFactory.getRuleClassProvider(), installDir.getPathString());
    parser.parse(
        ParserInputSource.create(
            ruleClassProvider.getDefaultWorkspaceFile(), new PathFragment("DEFAULT.WORKSPACE")));
    if (!workspaceFileValue.exists()) {
      return new PackageValue(builder.build());
    }

    try {
      parser.parse(ParserInputSource.create(repoWorkspace));
    } catch (IOException e) {
      throw new WorkspaceFileFunctionException(e, Transience.TRANSIENT);
    }

    return new PackageValue(builder.build());
  }
Ejemplo n.º 2
0
 public WorkspaceFactoryHelper(boolean allowOverride, String... args) {
   Path root = null;
   Path workspaceFilePath = null;
   try {
     Scratch scratch = new Scratch("/");
     root = scratch.dir("/workspace");
     workspaceFilePath = scratch.file("/workspace/WORKSPACE", args);
   } catch (IOException e) {
     fail("Shouldn't happen: " + e.getMessage());
   }
   StoredEventHandler eventHandler = new StoredEventHandler();
   builder =
       Package.newExternalPackageBuilder(
           Package.Builder.DefaultHelper.INSTANCE, workspaceFilePath, "");
   this.factory =
       new WorkspaceFactory(
           builder,
           TestRuleClassProvider.getRuleClassProvider(),
           ImmutableList.<PackageFactory.EnvironmentExtension>of(),
           Mutability.create("test"),
           allowOverride,
           root,
           root);
   Exception exception = null;
   try {
     factory.parse(ParserInputSource.create(workspaceFilePath), eventHandler);
   } catch (BuildFileContainsErrorsException e) {
     exception = e;
   } catch (IOException | InterruptedException e) {
     fail("Shouldn't happen: " + e.getMessage());
   }
   this.events = eventHandler.getEvents();
   this.exception = exception;
 }