示例#1
0
 private FileLookupResult getASTFile(Environment env, PathFragment astFilePathFragment)
     throws ASTLookupFunctionException {
   for (Path packagePathEntry : pkgLocator.get().getPathEntries()) {
     RootedPath rootedPath = RootedPath.toRootedPath(packagePathEntry, astFilePathFragment);
     SkyKey fileSkyKey = FileValue.key(rootedPath);
     FileValue fileValue = null;
     try {
       fileValue =
           (FileValue)
               env.getValueOrThrow(
                   fileSkyKey,
                   IOException.class,
                   FileSymlinkCycleException.class,
                   InconsistentFilesystemException.class);
     } catch (IOException | FileSymlinkCycleException e) {
       throw new ASTLookupFunctionException(
           new ErrorReadingSkylarkExtensionException(e.getMessage()), Transience.PERSISTENT);
     } catch (InconsistentFilesystemException e) {
       throw new ASTLookupFunctionException(e, Transience.PERSISTENT);
     }
     if (fileValue == null) {
       return null;
     }
     if (fileValue.isFile()) {
       return FileLookupResult.file(rootedPath);
     }
   }
   return FileLookupResult.noFile();
 }
示例#2
0
  @Override
  public SkyValue compute(SkyKey skyKey, Environment env)
      throws SkyFunctionException, InterruptedException {
    PathFragment astFilePathFragment = (PathFragment) skyKey.argument();
    FileLookupResult lookupResult = getASTFile(env, astFilePathFragment);
    if (lookupResult == null) {
      return null;
    }

    BuildFileAST ast = null;
    if (!lookupResult.lookupSuccessful()) {
      return ASTFileLookupValue.noFile();
    } else {
      Path path = lookupResult.rootedPath().asPath();
      // Skylark files end with bzl.
      boolean parseAsSkylark = astFilePathFragment.getPathString().endsWith(".bzl");
      try {
        ast =
            parseAsSkylark
                ? BuildFileAST.parseSkylarkFile(
                    path,
                    env.getListener(),
                    packageManager,
                    ruleClassProvider.getSkylarkValidationEnvironment().clone())
                : BuildFileAST.parseBuildFile(path, env.getListener(), packageManager, false);
      } catch (IOException e) {
        throw new ASTLookupFunctionException(
            new ErrorReadingSkylarkExtensionException(e.getMessage()), Transience.TRANSIENT);
      }
    }

    return ASTFileLookupValue.withFile(ast);
  }