Esempio n. 1
0
  private static boolean canMerge(
      IjFolder parent, IjFolder child, PackagePathCache packagePathCache) {
    Preconditions.checkArgument(child.getPath().startsWith(parent.getPath()));

    if (!child.canMergeWith(parent)) {
      return false;
    }

    if (parent.getWantsPackagePrefix() != child.getWantsPackagePrefix()) {
      return false;
    }

    if (parent.getWantsPackagePrefix()) {
      Optional<Path> parentPackage = packagePathCache.lookup(parent);
      if (!parentPackage.isPresent()) {
        return false;
      }
      Path childPackage = packagePathCache.lookup(child).get();

      int pathDifference = child.getPath().getNameCount() - parent.getPath().getNameCount();
      Preconditions.checkState(pathDifference == 1);
      if (childPackage.getNameCount() == 0) {
        return false;
      }
      if (!MorePaths.getParentOrEmpty(childPackage).equals(parentPackage.get())) {
        return false;
      }
    }
    return true;
  }
Esempio n. 2
0
 /**
  * @param cellRoot root path to the cell the rule is defined in.
  * @param map the map of values that define the rule.
  * @param rulePathForDebug path to the build file the rule is defined in, only used for debugging.
  * @return the build target defined by the rule.
  */
 public static UnflavoredBuildTarget parseBuildTargetFromRawRule(
     Path cellRoot, Map<String, Object> map, Path rulePathForDebug) {
   String basePath = (String) map.get("buck.base_path");
   String name = (String) map.get("name");
   if (basePath == null || name == null) {
     throw new IllegalStateException(
         String.format(
             "Attempting to parse build target from malformed raw data in %s: %s.",
             rulePathForDebug, Joiner.on(",").withKeyValueSeparator("->").join(map)));
   }
   Path otherBasePath = cellRoot.relativize(MorePaths.getParentOrEmpty(rulePathForDebug));
   if (!otherBasePath.equals(otherBasePath.getFileSystem().getPath(basePath))) {
     throw new IllegalStateException(
         String.format(
             "Raw data claims to come from [%s], but we tried rooting it at [%s].",
             basePath, otherBasePath));
   }
   return UnflavoredBuildTarget.builder(UnflavoredBuildTarget.BUILD_TARGET_PREFIX + basePath, name)
       .setCellPath(cellRoot)
       .build();
 }