Ejemplo n.º 1
0
  /**
   * @param buildFile the build file to execute to generate build rules if they are not cached.
   * @param defaultIncludes the files to include before executing the build file.
   * @return a list of raw build rules generated by executing the build file.
   */
  public List<Map<String, Object>> parseBuildFile(
      File buildFile, Iterable<String> defaultIncludes, ProjectBuildFileParser buildFileParser)
      throws BuildFileParseException, BuildTargetException, IOException {
    Preconditions.checkNotNull(buildFile);
    Preconditions.checkNotNull(defaultIncludes);
    Preconditions.checkNotNull(buildFileParser);
    if (!isCached(buildFile, defaultIncludes)) {
      if (console.getVerbosity().shouldPrintCommand()) {
        console
            .getStdErr()
            .printf("Parsing %s file: %s\n", BuckConstant.BUILD_RULES_FILE_NAME, buildFile);
      }

      parseRawRulesInternal(buildFileParser.getAllRulesAndMetaRules(buildFile.getPath()));
    }
    return parsedBuildFiles.get(normalize(buildFile.toPath()));
  }
Ejemplo n.º 2
0
 /**
  * Populates the collection of known build targets that this Parser will use to construct a
  * dependency graph using all build files inside the given project root and returns an optionally
  * filtered set of build targets.
  *
  * @param filesystem The project filesystem.
  * @param includes A list of files that should be included by each build file.
  * @param filter if specified, applied to each rule in rules. All matching rules will be included
  *     in the List returned by this method. If filter is null, then this method returns null.
  * @return The build targets in the project filtered by the given filter.
  */
 public synchronized List<BuildTarget> filterAllTargetsInProject(
     ProjectFilesystem filesystem, Iterable<String> includes, @Nullable RawRulePredicate filter)
     throws BuildFileParseException, BuildTargetException, IOException {
   Preconditions.checkNotNull(filesystem);
   Preconditions.checkNotNull(includes);
   if (!projectFilesystem.getProjectRoot().equals(filesystem.getProjectRoot())) {
     throw new HumanReadableException(
         String.format(
             "Unsupported root path change from %s to %s",
             projectFilesystem.getProjectRoot(), filesystem.getProjectRoot()));
   }
   if (!isCacheComplete(includes)) {
     knownBuildTargets.clear();
     parsedBuildFiles.clear();
     parseRawRulesInternal(
         ProjectBuildFileParser.getAllRulesInProject(buildFileParserFactory, includes));
     allBuildFilesParsed = true;
   }
   return filterTargets(filter);
 }