Exemplo n.º 1
0
  /** @param rules the raw rule objects to parse. */
  @VisibleForTesting
  synchronized void parseRawRulesInternal(Iterable<Map<String, Object>> rules)
      throws BuildTargetException, IOException {
    for (Map<String, Object> map : rules) {

      if (isMetaRule(map)) {
        parseMetaRule(map);
        continue;
      }

      BuildRuleType buildRuleType = parseBuildRuleTypeFromRawRule(map);
      BuildTarget target = parseBuildTargetFromRawRule(map);
      BuildRuleFactory<?> factory = buildRuleTypes.getFactory(buildRuleType);
      if (factory == null) {
        throw new HumanReadableException(
            "Unrecognized rule %s while parsing %s.",
            buildRuleType, target.getBuildFile(projectFilesystem));
      }

      BuildFileTree buildFileTree;
      buildFileTree = buildFileTreeCache.getInput();

      BuildRuleBuilder<?> buildRuleBuilder =
          factory.newInstance(
              new BuildRuleFactoryParams(
                  map,
                  projectFilesystem,
                  buildFileTree,
                  buildTargetParser,
                  target,
                  ruleKeyBuilderFactory));
      Object existingRule = knownBuildTargets.put(target, buildRuleBuilder);
      if (existingRule != null) {
        throw new RuntimeException("Duplicate definition for " + target.getFullyQualifiedName());
      }
      parsedBuildFiles.put(normalize(target.getBuildFile(projectFilesystem).toPath()), map);
    }
  }
Exemplo n.º 2
0
 /**
  * @param map the map of values that define the rule.
  * @return the type of rule defined by the map.
  */
 private BuildRuleType parseBuildRuleTypeFromRawRule(Map<String, Object> map) {
   String type = (String) map.get("type");
   return buildRuleTypes.getBuildRuleType(type);
 }