Java 类com.facebook.buck.rules.TargetGraph 实例源码

项目:buck-cutom    文件:Parser.java   
/**
 * @param toExplore BuildTargets whose dependencies need to be explored.
 */
@VisibleForTesting
private ActionGraph findAllTransitiveDependencies(
    Iterable<BuildTarget> toExplore,
    final Iterable<String> defaultIncludes,
    final ProjectBuildFileParser buildFileParser,
    final ImmutableMap<String, String> environment) throws IOException {

  final TargetGraph graph = buildTargetGraph(
      toExplore,
      defaultIncludes,
      buildFileParser,
      environment);

  return buildActionGraphFromTargetGraph(graph);
}
项目:buck    文件:PythonBinaryDescriptionTest.java   
@Test
public void executableCommandWithNoPathToPexExecutor() throws Exception {
  BuildTarget target = BuildTargetFactory.newInstance("//foo:bin");
  BuildRuleResolver resolver =
      new SingleThreadedBuildRuleResolver(
          TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
  SourcePathResolver pathResolver =
      DefaultSourcePathResolver.from(new SourcePathRuleFinder(resolver));
  PythonPackagedBinary binary =
      (PythonPackagedBinary)
          PythonBinaryBuilder.create(target).setMainModule("main").build(resolver);
  assertThat(
      binary.getExecutableCommand().getCommandPrefix(pathResolver),
      Matchers.contains(
          PythonTestUtils.PYTHON_PLATFORM.getEnvironment().getPythonPath().toString(),
          pathResolver.getAbsolutePath(binary.getSourcePathToOutput()).toString()));
}
项目:buck    文件:ModuleExoHelperTest.java   
@Before
public void setUp() throws InterruptedException, IOException {
  AssumeAndroidPlatform.assumeSdkIsAvailable();
  workspace =
      TestDataHelper.createProjectWorkspaceForScenario(
          new ModuleExoHelperTest(), "modular_exo", tmpFolder);
  workspace.setUp();
  filesystem = TestProjectFilesystems.createProjectFilesystem(workspace.getDestPath());
  moduleOutputPath = Paths.get("module_name");
  metadataOutputPath = moduleOutputPath.resolve("metadata");
  final DexInfo dexInfo =
      DexInfo.of(
          PathSourcePath.of(filesystem, metadataOutputPath),
          PathSourcePath.of(filesystem, moduleOutputPath));

  BuildRuleResolver resolver =
      new SingleThreadedBuildRuleResolver(
          TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
  SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
  SourcePathResolver pathResolver = DefaultSourcePathResolver.from(ruleFinder);

  moduleExoHelper = new ModuleExoHelper(pathResolver, filesystem, ImmutableList.of(dexInfo));
}
项目:buck    文件:CxxGenruleDescription.java   
@Override
public BuildRule createBuildRule(
    TargetGraph targetGraph,
    BuildTarget buildTarget,
    ProjectFilesystem projectFilesystem,
    BuildRuleParams params,
    BuildRuleResolver resolver,
    CellPathResolver cellRoots,
    CxxGenruleDescriptionArg args) {
  Optional<CxxPlatform> cxxPlatform = getCxxPlatforms().getValue(buildTarget);
  if (cxxPlatform.isPresent()) {
    return super.createBuildRule(
        targetGraph,
        buildTarget.withAppendedFlavors(cxxPlatform.get().getFlavor()),
        projectFilesystem,
        params,
        resolver,
        cellRoots,
        args);
  }
  return new CxxGenrule(buildTarget, projectFilesystem, params, resolver, args.getOut());
}
项目:buck    文件:JavaSourceJarTest.java   
@Test
public void outputNameShouldIndicateThatTheOutputIsASrcJar() {
  BuildRuleResolver resolver =
      new SingleThreadedBuildRuleResolver(
          TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
  BuildTarget buildTarget = BuildTargetFactory.newInstance("//example:target");

  JavaSourceJar rule =
      new JavaSourceJar(
          buildTarget,
          new FakeProjectFilesystem(),
          TestBuildRuleParams.create(),
          ImmutableSortedSet.of(),
          Optional.empty());
  resolver.addToIndex(rule);

  SourcePath output = rule.getSourcePathToOutput();

  assertNotNull(output);
  SourcePathResolver pathResolver =
      DefaultSourcePathResolver.from(new SourcePathRuleFinder(resolver));
  assertThat(pathResolver.getRelativePath(output).toString(), endsWith(Javac.SRC_JAR));
}
项目:buck    文件:WorkerToolTest.java   
@Test
public void testCreateWorkerTool() throws NoSuchBuildTargetException {
  BuildRuleResolver resolver =
      new SingleThreadedBuildRuleResolver(
          TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
  SourcePathResolver pathResolver =
      DefaultSourcePathResolver.from(new SourcePathRuleFinder(resolver));

  BuildRule shBinaryRule =
      new ShBinaryBuilder(BuildTargetFactory.newInstance("//:my_exe"))
          .setMain(FakeSourcePath.of("bin/exe"))
          .build(resolver);

  BuildRule workerRule =
      WorkerToolBuilder.newWorkerToolBuilder(BuildTargetFactory.newInstance("//:worker_rule"))
          .setExe(shBinaryRule.getBuildTarget())
          .setArgs("arg1", "arg2")
          .build(resolver);

  assertThat(
      "getArgs should return the args string supplied in the definition.",
      ImmutableList.of("arg1", "arg2"),
      Matchers.is(
          ((WorkerTool) workerRule).getTool().getCommandPrefix(pathResolver).subList(1, 3)));
}
项目:buck    文件:MacroArgTest.java   
@Test
public void getDeps() throws Exception {
  MacroHandler macroHandler =
      new MacroHandler(ImmutableMap.of("loc", new LocationMacroExpander()));
  BuildRuleResolver resolver =
      new SingleThreadedBuildRuleResolver(
          TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
  SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
  ProjectFilesystem filesystem = new FakeProjectFilesystem();
  Genrule rule =
      GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:rule"))
          .setOut("output")
          .build(resolver);
  MacroArg arg =
      new MacroArg(
          macroHandler,
          rule.getBuildTarget(),
          TestCellBuilder.createCellRoots(filesystem),
          resolver,
          "$(loc //:rule)");
  assertThat(BuildableSupport.getDepsCollection(arg, ruleFinder), Matchers.contains(rule));
}
项目:buck    文件:VersionedTargetGraphBuilderTest.java   
@Test
public void nodeWithTestParameterReferringToNonExistentTarget() throws Exception {
  TargetGraph graph =
      TargetGraphFactory.newInstanceExact(
          new VersionPropagatorBuilder("//:root2")
              .setTests(ImmutableSortedSet.of(BuildTargetFactory.newInstance("//:test")))
              .build(),
          new VersionRootBuilder("//:root1").setDeps("//:root2").build());
  VersionedTargetGraphBuilder builder =
      new VersionedTargetGraphBuilder(
          POOL,
          new NaiveVersionSelector(),
          TargetGraphAndBuildTargets.of(
              graph,
              ImmutableSet.of(
                  BuildTargetFactory.newInstance("//:root1"),
                  BuildTargetFactory.newInstance("//:root2"))),
          new DefaultTypeCoercerFactory());
  TargetGraph versionedGraph = builder.build();
  assertEquals(graph, versionedGraph);
}
项目:buck    文件:AppleBuildRules.java   
public static ImmutableSet<TargetNode<?, ?>> getSchemeBuildableTargetNodes(
    TargetGraph targetGraph,
    Optional<AppleDependenciesCache> cache,
    TargetNode<?, ?> targetNode) {
  Iterable<TargetNode<?, ?>> targetNodes =
      Iterables.concat(
          getRecursiveTargetNodeDependenciesOfTypes(
              targetGraph,
              cache,
              RecursiveDependenciesMode.BUILDING,
              targetNode,
              Optional.empty()),
          ImmutableSet.of(targetNode));

  return ImmutableSet.copyOf(
      Iterables.filter(targetNodes, input -> isXcodeTargetDescription(input.getDescription())));
}
项目:buck    文件:JavaLibraryDescriptionTest.java   
@Before
public void setUp() throws NoSuchBuildTargetException {
  javaBuckConfig = getJavaBuckConfigWithCompilationMode();

  TargetNode<?, ?> exportedNode =
      JavaLibraryBuilder.createBuilder(
              BuildTargetFactory.newInstance("//:exported_rule"), javaBuckConfig)
          .addSrc(Paths.get("java/src/com/exported_rule/foo.java"))
          .build();
  TargetNode<?, ?> exportingNode =
      JavaLibraryBuilder.createBuilder(
              BuildTargetFactory.newInstance("//:exporting_rule"), javaBuckConfig)
          .addSrc(Paths.get("java/src/com/exporting_rule/bar.java"))
          .addExportedDep(exportedNode.getBuildTarget())
          .build();

  TargetGraph targetGraph = TargetGraphFactory.newInstance(exportedNode, exportingNode);

  resolver =
      new SingleThreadedBuildRuleResolver(
          targetGraph, new DefaultTargetNodeToBuildRuleTransformer());

  exportedRule = resolver.requireRule(exportedNode.getBuildTarget());
  exportingRule = resolver.requireRule(exportingNode.getBuildTarget());
}
项目:buck    文件:DelegateAndGraphsInitializer.java   
private ActionGraphAndResolver createActionGraphAndResolver(TargetGraph targetGraph)
    throws IOException, InterruptedException {
  args.getTimingStatsTracker().startTimer(SlaveEvents.ACTION_GRAPH_CREATION_TIME);
  try {
    ActionGraphAndResolver actionGraphAndResolver =
        args.getActionGraphCache()
            .getActionGraph(
                args.getBuckEventBus(),
                /* checkActionGraphs */ false,
                /* skipActionGraphCache */ false,
                Preconditions.checkNotNull(targetGraph),
                args.getRuleKeyConfiguration(),
                ActionGraphParallelizationMode.DISABLED,
                Optional.empty(),
                args.getShouldInstrumentActionGraph());
    return actionGraphAndResolver;
  } finally {
    args.getTimingStatsTracker().stopTimer(SlaveEvents.ACTION_GRAPH_CREATION_TIME);
  }
}
项目:buck    文件:SanitizedArgTest.java   
private RuleKeyBuilder<HashCode> createRuleKeyBuilder() {
  FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
  FileHashCache fileHashCache =
      new StackedFileHashCache(
          ImmutableList.of(
              DefaultFileHashCache.createDefaultFileHashCache(
                  projectFilesystem, FileHashCacheMode.DEFAULT)));
  SourcePathRuleFinder ruleFinder =
      new SourcePathRuleFinder(
          new SingleThreadedBuildRuleResolver(
              TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
  SourcePathResolver resolver = DefaultSourcePathResolver.from(ruleFinder);
  return new UncachedRuleKeyBuilder(
      ruleFinder,
      resolver,
      fileHashCache,
      new TestDefaultRuleKeyFactory(fileHashCache, resolver, ruleFinder));
}
项目:buck    文件:PrebuiltCxxLibraryDescriptionTest.java   
@Test
public void locationMacroWithCxxGenrule() throws NoSuchBuildTargetException {
  CxxGenruleBuilder genruleBuilder =
      new CxxGenruleBuilder(BuildTargetFactory.newInstance("//other:gen_lib"))
          .setOut("libtest.a");
  PrebuiltCxxLibraryBuilder libraryBuilder =
      new PrebuiltCxxLibraryBuilder(TARGET)
          .setStaticLib(DefaultBuildTargetSourcePath.of(genruleBuilder.getTarget()));
  TargetGraph targetGraph =
      TargetGraphFactory.newInstance(genruleBuilder.build(), libraryBuilder.build());
  ProjectFilesystem filesystem = new FakeProjectFilesystem();
  BuildRuleResolver resolver =
      new SingleThreadedBuildRuleResolver(
          targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
  SourcePathResolver pathResolver =
      DefaultSourcePathResolver.from(new SourcePathRuleFinder(resolver));
  CxxGenrule genrule = (CxxGenrule) genruleBuilder.build(resolver, filesystem, targetGraph);
  PrebuiltCxxLibrary library =
      (PrebuiltCxxLibrary) libraryBuilder.build(resolver, filesystem, targetGraph);
  SourcePath staticLibraryPath =
      library.getStaticLibrary(CxxPlatformUtils.DEFAULT_PLATFORM).get();
  assertThat(
      pathResolver.getAbsolutePath(staticLibraryPath),
      Matchers.equalTo(
          pathResolver.getAbsolutePath(genrule.getGenrule(CxxPlatformUtils.DEFAULT_PLATFORM))));
}
项目:buck    文件:CxxLibraryDescriptionTest.java   
@Test
public void sharedLibraryShouldLinkOwnRequiredLibrariesForCxxLibrary() throws Exception {
  ProjectFilesystem filesystem = new FakeProjectFilesystem();
  CxxPlatform platform = CxxPlatformUtils.DEFAULT_PLATFORM;

  ImmutableSortedSet<FrameworkPath> libraries =
      ImmutableSortedSet.of(
          FrameworkPath.ofSourcePath(FakeSourcePath.of("/some/path/libs.dylib")),
          FrameworkPath.ofSourcePath(FakeSourcePath.of("/another/path/liba.dylib")));

  CxxLibraryBuilder libraryBuilder =
      new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:foo"), cxxBuckConfig);
  libraryBuilder
      .setLibraries(libraries)
      .setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(FakeSourcePath.of("foo.c"))));
  TargetGraph targetGraph = TargetGraphFactory.newInstance(libraryBuilder.build());
  BuildRuleResolver resolver =
      new SingleThreadedBuildRuleResolver(
          targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
  CxxLibrary library = (CxxLibrary) libraryBuilder.build(resolver, filesystem, targetGraph);
  assertThat(library.getNativeLinkTargetInput(platform).getLibraries(), equalTo(libraries));
}
项目:buck    文件:JavacPluginPropertiesTest.java   
@Test
public void transitiveAnnotationProcessorDepsInInputs() {
  BuildRuleResolver resolver =
      new SingleThreadedBuildRuleResolver(
          TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
  SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);

  FakeJavaLibrary dep =
      resolver.addToIndex(new FakeJavaLibrary(BuildTargetFactory.newInstance("//:dep")));
  FakeJavaLibrary processor =
      resolver.addToIndex(
          new FakeJavaLibrary(
              BuildTargetFactory.newInstance("//:processor"), ImmutableSortedSet.of(dep)));

  JavacPluginProperties props =
      JavacPluginProperties.builder()
          .setCanReuseClassLoader(false)
          .setDoesNotAffectAbi(false)
          .setSupportsAbiGenerationFromSource(false)
          .addDep(processor)
          .build();

  assertThat(
      ruleFinder.filterBuildRuleInputs(props.getInputs()),
      Matchers.containsInAnyOrder(processor, dep));
}
项目:buck    文件:RemoteFileDescriptionTest.java   
@Test
public void badSha1HasUseableException() throws Exception {
  BuildTarget target = BuildTargetFactory.newInstance("//cheese:cake");

  RemoteFileDescriptionArg arg =
      RemoteFileDescriptionArg.builder()
          .setName(target.getShortName())
          .setSha1("")
          .setUrl(new URI("https://example.com/cheeeeeese-cake"))
          .build();

  exception.expect(HumanReadableException.class);
  exception.expectMessage(Matchers.containsString(target.getFullyQualifiedName()));

  description.createBuildRule(
      TargetGraph.EMPTY,
      target,
      filesystem,
      RemoteFileBuilder.createBuilder(downloader, target)
          .from(arg)
          .createBuildRuleParams(ruleResolver),
      ruleResolver,
      TestCellBuilder.createCellRoots(filesystem),
      arg);
}
项目:buck    文件:AuditInputCommandTest.java   
@Test
public void testNonExistentInputFileThrows() throws IOException {
  thrown.expect(HumanReadableException.class);
  thrown.expectMessage(
      "Target //:test-java-library refers to non-existent input file: "
          + MorePaths.pathWithPlatformSeparators("src/com/facebook/NonExistentFile.java"));

  BuildTarget rootTarget = BuildTargetFactory.newInstance("//:test-java-library");
  TargetNode<?, ?> rootNode =
      JavaLibraryBuilder.createBuilder(rootTarget)
          .addSrc(Paths.get("src/com/facebook/NonExistentFile.java"))
          .build();

  ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(rootNode);
  TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes);
  auditInputCommand.printJsonInputs(params, targetGraph);
}
项目:buck    文件:PrebuiltCxxLibraryDescriptionTest.java   
@Test
public void includesDirs() throws Exception {
  ProjectFilesystem filesystem = new FakeProjectFilesystem();
  PrebuiltCxxLibraryBuilder prebuiltCxxLibraryBuilder =
      new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:r"))
          .setHeaderDirs(ImmutableList.of(FakeSourcePath.of("include")));
  TargetGraph targetGraph = TargetGraphFactory.newInstance(prebuiltCxxLibraryBuilder.build());
  BuildRuleResolver resolver =
      new SingleThreadedBuildRuleResolver(
          targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
  PrebuiltCxxLibrary rule =
      (PrebuiltCxxLibrary) prebuiltCxxLibraryBuilder.build(resolver, filesystem, targetGraph);
  assertThat(
      rule.getCxxPreprocessorInput(CxxPlatformUtils.DEFAULT_PLATFORM).getIncludes(),
      contains(
          CxxHeadersDir.of(
              CxxPreprocessables.IncludeType.SYSTEM,
              PathSourcePath.of(
                  filesystem,
                  rule.getBuildTarget().getBasePath().getFileSystem().getPath("include")))));
}
项目:buck    文件:GenAidlDescription.java   
@Override
public GenAidl createBuildRule(
    TargetGraph targetGraph,
    BuildTarget buildTarget,
    ProjectFilesystem projectFilesystem,
    BuildRuleParams params,
    BuildRuleResolver resolver,
    CellPathResolver cellRoots,
    GenAidlDescriptionArg args) {
  return new GenAidl(
      buildTarget,
      projectFilesystem,
      toolchainProvider,
      params,
      args.getAidl(),
      args.getImportPath());
}
项目:buck    文件:AppleDescriptionsTest.java   
@Test
public void parseAppleHeadersForUseFromTheSameTargetFromMap() {
  ImmutableSortedMap<String, SourcePath> headerMap =
      ImmutableSortedMap.of(
          "virtual/path.h", FakeSourcePath.of("path/to/some_file.h"),
          "another/path.h", FakeSourcePath.of("path/to/another_file.h"),
          "another/file.h", FakeSourcePath.of("different/path/to/a_file.h"),
          "file.h", FakeSourcePath.of("file.h"));
  SourcePathResolver resolver =
      DefaultSourcePathResolver.from(
          new SourcePathRuleFinder(
              new SingleThreadedBuildRuleResolver(
                  TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
  assertEquals(
      ImmutableMap.of(),
      AppleDescriptions.parseAppleHeadersForUseFromTheSameTarget(
          BuildTargetFactory.newInstance("//:foobar"),
          resolver::getRelativePath,
          SourceList.ofNamedSources(headerMap)));
}
项目:buck    文件:APKModuleGraph.java   
/**
 * This walks through the target graph starting from the root target and adds all reachable
 * targets that are not seed targets to the root module
 *
 * @return The root APK Module
 */
private APKModule generateRootModule() {
  final Set<BuildTarget> rootTargets = new HashSet<>();
  if (targetGraph != TargetGraph.EMPTY) {
    new AbstractBreadthFirstTraversal<TargetNode<?, ?>>(targetGraph.get(target)) {
      @Override
      public Iterable<TargetNode<?, ?>> visit(TargetNode<?, ?> node) {

        ImmutableSet.Builder<TargetNode<?, ?>> depsBuilder = ImmutableSet.builder();
        for (BuildTarget depTarget : node.getBuildDeps()) {
          if (!isSeedTarget(depTarget)) {
            depsBuilder.add(targetGraph.get(depTarget));
            rootTargets.add(depTarget);
          }
        }
        return depsBuilder.build();
      }
    }.start();
  }
  APKModule rootModule = APKModule.of(ROOT_APKMODULE_NAME);
  buildTargetsMap.put(rootModule, ImmutableSet.copyOf(rootTargets));
  return rootModule;
}
项目:buck    文件:AbstractGenruleDescription.java   
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellPathResolver cellRoots,
    TargetGraph targetGraph,
    BuildRuleResolver resolver,
    SourcePathRuleFinder ruleFinder,
    ProjectFilesystem projectFilesystem,
    T constructorArg,
    ImmutableCollection.Builder<BuildTarget> extraDepsBuilder,
    ImmutableCollection.Builder<BuildTarget> nonBuildDepsBuilder) {
  Optional<MacroHandler> maybeMacroHandler =
      getMacroHandler(buildTarget, projectFilesystem, resolver, targetGraph, constructorArg);
  maybeMacroHandler.ifPresent(
      macroHandler -> {
        Stream.of(constructorArg.getCmd(), constructorArg.getCmd(), constructorArg.getCmdExe())
            .flatMap(Optionals::toStream)
            .forEach(
                s -> {
                  try {
                    macroHandler.extractParseTimeDeps(
                        buildTarget, cellRoots, s, extraDepsBuilder, nonBuildDepsBuilder);
                    ImmutableList<BuildRule> buildDeps =
                        macroHandler.extractBuildTimeDeps(buildTarget, cellRoots, resolver, s);
                    for (BuildRule dep : buildDeps) {
                      extraDepsBuilder.add(dep.getBuildTarget());
                    }
                  } catch (MacroException e) {
                    throw new HumanReadableException(e, "%s: %s", buildTarget, e.getMessage());
                  }
                });
      });
}
项目:buck    文件:AndroidPackageableCollector.java   
@VisibleForTesting
public AndroidPackageableCollector(BuildTarget collectionRoot) {
  this(
      collectionRoot,
      ImmutableSet.of(),
      ImmutableSet.of(),
      new APKModuleGraph(TargetGraph.EMPTY, collectionRoot, Optional.empty()));
}
项目:buck    文件:TestRunningTest.java   
/**
 * If the source paths specified are all for non-generated files then we should return the correct
 * source tmp corresponding to a non-generated source path.
 */
@Test
public void testNonGeneratedSourceFile() throws Exception {
  Path pathToNonGenFile = Paths.get("package/src/SourceFile1.java");

  BuildTarget javaLibraryTarget = BuildTargetFactory.newInstance("//foo:bar");
  TargetNode<JavaLibraryDescriptionArg, JavaLibraryDescription> javaLibraryNode =
      JavaLibraryBuilder.createBuilder(javaLibraryTarget).addSrc(pathToNonGenFile).build();

  TargetGraph targetGraph = TargetGraphFactory.newInstance(javaLibraryNode);

  BuildRuleResolver ruleResolver =
      new SingleThreadedBuildRuleResolver(
          targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
  SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
  SourcePathResolver resolver = DefaultSourcePathResolver.from(ruleFinder);
  JavaLibrary javaLibrary = (JavaLibrary) ruleResolver.requireRule(javaLibraryTarget);

  DefaultJavaPackageFinder defaultJavaPackageFinder = createMock(DefaultJavaPackageFinder.class);
  expect(defaultJavaPackageFinder.getPathsFromRoot()).andReturn(pathsFromRoot);
  expect(defaultJavaPackageFinder.getPathElements()).andReturn(pathElements);

  replay(defaultJavaPackageFinder);

  ImmutableSet<String> result =
      TestRunning.getPathToSourceFolders(
          javaLibrary, resolver, ruleFinder, defaultJavaPackageFinder);

  String expected = javaLibrary.getProjectFilesystem().getRootPath().resolve("package/src") + "/";
  assertEquals(
      "All non-generated source files are under one source tmp.",
      ImmutableSet.of(expected),
      result);

  verify(defaultJavaPackageFinder);
}
项目:buck    文件:JavaAnnotationProcessorDescription.java   
@Override
public BuildRule createBuildRule(
    TargetGraph targetGraph,
    BuildTarget buildTarget,
    ProjectFilesystem projectFilesystem,
    BuildRuleParams params,
    BuildRuleResolver resolver,
    CellPathResolver cellRoots,
    JavaAnnotationProcessorDescriptionArg args) {
  JavacPluginProperties.Builder propsBuilder = JavacPluginProperties.builder();
  propsBuilder.addProcessorNames(args.getProcessorClass());
  for (BuildRule dep : params.getBuildDeps()) {
    if (!(dep instanceof JavaLibrary)) {
      throw new HumanReadableException(
          String.format(
              "%s: dependencies must produce JVM libraries; %s is a %s",
              buildTarget, dep.getBuildTarget(), dep.getType()));
    }
    propsBuilder.addDep(dep);
  }

  boolean reuseClassLoader = !args.isIsolateClassLoader();
  propsBuilder.setCanReuseClassLoader(reuseClassLoader);
  propsBuilder.setDoesNotAffectAbi(args.isDoesNotAffectAbi());
  propsBuilder.setSupportsAbiGenerationFromSource(args.isSupportsAbiGenerationFromSource());
  JavacPluginProperties properties = propsBuilder.build();

  SourcePathResolver pathResolver =
      DefaultSourcePathResolver.from(new SourcePathRuleFinder(resolver));
  return new JavaAnnotationProcessor(
      buildTarget,
      projectFilesystem,
      params.copyAppendingExtraDeps(properties.getClasspathDeps()),
      pathResolver,
      properties);
}
项目:buck    文件:KeystoreDescription.java   
@Override
public Keystore createBuildRule(
    TargetGraph targetGraph,
    BuildTarget buildTarget,
    ProjectFilesystem projectFilesystem,
    BuildRuleParams params,
    BuildRuleResolver resolver,
    CellPathResolver cellRoots,
    KeystoreDescriptionArg args) {
  return new Keystore(
      buildTarget, projectFilesystem, params, args.getStore(), args.getProperties());
}
项目:buck    文件:JarShapeTest.java   
@Test
public void shouldBeAbleToCreateAMavenJar() throws NoSuchBuildTargetException {
  TargetNode<?, ?> depNode =
      JavaLibraryBuilder.createBuilder("//:dep")
          .addSrc(FakeSourcePath.of("SomeFile.java"))
          .build();

  TargetNode<?, ?> mavenDepNode =
      JavaLibraryBuilder.createBuilder("//:maven-dep")
          .addSrc(FakeSourcePath.of("SomeFile.java"))
          .setMavenCoords("com.example:somelib:1.0")
          .build();

  TargetNode<?, ?> libNode =
      JavaLibraryBuilder.createBuilder("//:lib")
          .addSrc(FakeSourcePath.of("Library.java"))
          .addDep(depNode.getBuildTarget())
          .addDep(mavenDepNode.getBuildTarget())
          .build();

  TargetGraph targetGraph = TargetGraphFactory.newInstance(depNode, mavenDepNode, libNode);
  BuildRuleResolver resolver =
      new SingleThreadedBuildRuleResolver(
          targetGraph, new DefaultTargetNodeToBuildRuleTransformer());

  BuildRule dep = resolver.requireRule(depNode.getBuildTarget());
  BuildRule mavenDep = resolver.requireRule(mavenDepNode.getBuildTarget());
  BuildRule lib = resolver.requireRule(libNode.getBuildTarget());

  JarShape.Summary deps = JarShape.MAVEN.gatherDeps(lib);

  assertEquals(ImmutableSortedSet.of(dep, lib), deps.getPackagedRules());
  assertEquals(ImmutableSet.of(dep, lib, mavenDep), deps.getClasspath());
  assertEquals(ImmutableSet.of(mavenDep), deps.getMavenDeps());
}
项目:buck    文件:AuditClasspathCommand.java   
@VisibleForTesting
ExitCode printDotOutput(CommandRunnerParams params, TargetGraph targetGraph) {
  try {
    Dot.builder(targetGraph, "target_graph")
        .setNodeToName(
            targetNode -> "\"" + targetNode.getBuildTarget().getFullyQualifiedName() + "\"")
        .setNodeToTypeName(
            targetNode -> Description.getBuildRuleType(targetNode.getDescription()).getName())
        .build()
        .writeOutput(params.getConsole().getStdOut());
  } catch (IOException e) {
    return ExitCode.FATAL_IO;
  }
  return ExitCode.SUCCESS;
}
项目:buck    文件:PrebuiltCxxLibraryDescriptionTest.java   
@Test
public void sharedLinkageIsNotANativeLinkTargetSoname() throws Exception {
  ProjectFilesystem filesystem = new FakeProjectFilesystem();
  PrebuiltCxxLibraryBuilder prebuiltCxxLibraryBuilder =
      new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:rule"))
          .setPreferredLinkage(NativeLinkable.Linkage.SHARED)
          .setSharedLib(FakeSourcePath.of("libfoo.so"));
  TargetGraph targetGraph = TargetGraphFactory.newInstance(prebuiltCxxLibraryBuilder.build());
  BuildRuleResolver resolver =
      new SingleThreadedBuildRuleResolver(
          targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
  PrebuiltCxxLibrary rule =
      (PrebuiltCxxLibrary) prebuiltCxxLibraryBuilder.build(resolver, filesystem, targetGraph);
  assertFalse(rule.getNativeLinkTarget(CXX_PLATFORM).isPresent());
}
项目:buck    文件:VersionedTargetGraphBuilderTest.java   
@Test
public void singleRootNode() throws Exception {
  TargetNode<?, ?> root = new VersionRootBuilder("//:root").build();
  TargetGraph graph = TargetGraphFactory.newInstanceExact(root);
  VersionedTargetGraphBuilder builder =
      new VersionedTargetGraphBuilder(
          POOL,
          new NaiveVersionSelector(),
          TargetGraphAndBuildTargets.of(graph, ImmutableSet.of(root.getBuildTarget())),
          new DefaultTypeCoercerFactory());
  TargetGraph versionedGraph = builder.build();
  assertEquals(graph, versionedGraph);
}
项目:buck    文件:InputBasedRuleKeyFactoryTest.java   
@Test
public void ruleKeyChangesIfInputContentsFromPathSourceChanges() throws Exception {
  BuildRuleResolver resolver =
      new SingleThreadedBuildRuleResolver(
          TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
  SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
  SourcePathResolver pathResolver = DefaultSourcePathResolver.from(ruleFinder);
  FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
  Path output = Paths.get("output");

  BuildRule rule =
      new ExportFileBuilder(BuildTargetFactory.newInstance("//:rule"))
          .setOut("out")
          .setSrc(PathSourcePath.of(filesystem, output))
          .build(resolver, filesystem);

  // Build a rule key with a particular hash set for the output for the above rule.
  FakeFileHashCache hashCache =
      new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(output), HashCode.fromInt(0)));

  RuleKey inputKey1 =
      new TestInputBasedRuleKeyFactory(hashCache, pathResolver, ruleFinder).build(rule);

  // Now, build a rule key with a different hash for the output for the above rule.
  hashCache =
      new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(output), HashCode.fromInt(1)));

  RuleKey inputKey2 =
      new TestInputBasedRuleKeyFactory(hashCache, pathResolver, ruleFinder).build(rule);

  assertThat(inputKey1, Matchers.not(Matchers.equalTo(inputKey2)));
}
项目:buck    文件:DefaultRuleKeyFactoryTest.java   
@Test
public void shouldAllowAFieldToBeStringified() {
  BuildTarget target = BuildTargetFactory.newInstance("//cheese:peas");
  SourcePathRuleFinder ruleFinder =
      new SourcePathRuleFinder(
          new SingleThreadedBuildRuleResolver(
              TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
  SourcePathResolver pathResolver = DefaultSourcePathResolver.from(ruleFinder);
  BuildRule rule = new EmptyRule(target);

  DefaultRuleKeyFactory factory =
      new TestDefaultRuleKeyFactory(new DummyFileHashCache(), pathResolver, ruleFinder);

  class Stringifiable {
    @Override
    public String toString() {
      return "sausages";
    }
  }

  class StringifiedField extends EmptyRule {
    @AddToRuleKey(stringify = true)
    private Stringifiable field = new Stringifiable();

    public StringifiedField() {
      super(target);
    }
  }

  Result<RuleKey, String> result =
      factory.buildForDiagnostics(new StringifiedField(), new StringRuleKeyHasher());
  assertThat(result.diagKey, Matchers.containsString("string(\"sausages\"):key(field)"));
}
项目:buck    文件:GraphqlLibraryDescription.java   
@Override
public BuildRule createBuildRule(
    TargetGraph targetGraph,
    BuildTarget buildTarget,
    final ProjectFilesystem projectFilesystem,
    BuildRuleParams params,
    final BuildRuleResolver resolver,
    CellPathResolver cellRoots,
    GraphqlLibraryDescriptionArg args) {

  return new GraphqlLibrary(buildTarget, projectFilesystem, params, args.getSrcs());
}
项目:buck    文件:PrebuiltDotnetLibraryDescription.java   
@Override
public BuildRule createBuildRule(
    TargetGraph targetGraph,
    BuildTarget buildTarget,
    ProjectFilesystem projectFilesystem,
    BuildRuleParams params,
    BuildRuleResolver resolver,
    CellPathResolver cellRoots,
    PrebuiltDotnetLibraryDescriptionArg args) {
  SourcePathResolver pathResolver =
      DefaultSourcePathResolver.from(new SourcePathRuleFinder(resolver));
  return new PrebuiltDotnetLibrary(
      buildTarget, projectFilesystem, params, pathResolver, args.getAssembly());
}
项目:buck    文件:DefaultRuleKeyFactoryTest.java   
@Test
public void fieldsFromParentClassesAreAlsoAdded() {
  BuildTarget target = BuildTargetFactory.newInstance("//cheese:peas");
  SourcePathRuleFinder ruleFinder =
      new SourcePathRuleFinder(
          new SingleThreadedBuildRuleResolver(
              TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
  SourcePathResolver pathResolver = DefaultSourcePathResolver.from(ruleFinder);
  BuildRule rule = new EmptyRule(target);

  DefaultRuleKeyFactory factory =
      new TestDefaultRuleKeyFactory(new DummyFileHashCache(), pathResolver, ruleFinder);
  DefaultRuleKeyFactory.Builder<HashCode> builder = factory.newBuilderForTesting(rule);

  builder.setReflectively("key", "child");
  builder.setReflectively("key", "parent");
  RuleKey expected = builder.build(RuleKey::new);

  class Parent extends EmptyRule {
    @AddToRuleKey private String key = "parent";

    public Parent() {
      super(target);
    }
  }

  class Child extends Parent {
    @AddToRuleKey private String key = "child";

    public Child() {
      super();
    }
  }

  Result<RuleKey, String> result =
      factory.buildForDiagnostics(new Child(), new StringRuleKeyHasher());
  assertThat(
      result.diagKey,
      Matchers.containsString(":string(\"child\"):key(key):string(\"parent\"):key(key):"));
}
项目:buck    文件:PythonTestDescriptionTest.java   
@Test
public void platformDeps() throws Exception {
  SourcePath libASrc = FakeSourcePath.of("libA.py");
  PythonLibraryBuilder libraryABuilder =
      PythonLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:libA"))
          .setSrcs(SourceList.ofUnnamedSources(ImmutableSortedSet.of(libASrc)));
  SourcePath libBSrc = FakeSourcePath.of("libB.py");
  PythonLibraryBuilder libraryBBuilder =
      PythonLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:libB"))
          .setSrcs(SourceList.ofUnnamedSources(ImmutableSortedSet.of(libBSrc)));
  PythonTestBuilder binaryBuilder =
      PythonTestBuilder.create(BuildTargetFactory.newInstance("//:bin"))
          .setPlatformDeps(
              PatternMatchedCollection.<ImmutableSortedSet<BuildTarget>>builder()
                  .add(
                      Pattern.compile(
                          CxxPlatformUtils.DEFAULT_PLATFORM.getFlavor().toString(),
                          Pattern.LITERAL),
                      ImmutableSortedSet.of(libraryABuilder.getTarget()))
                  .add(
                      Pattern.compile("matches nothing", Pattern.LITERAL),
                      ImmutableSortedSet.of(libraryBBuilder.getTarget()))
                  .build());
  TargetGraph targetGraph =
      TargetGraphFactory.newInstance(
          libraryABuilder.build(), libraryBBuilder.build(), binaryBuilder.build());
  BuildRuleResolver resolver =
      new SingleThreadedBuildRuleResolver(
          targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
  PythonTest test = (PythonTest) resolver.requireRule(binaryBuilder.getTarget());
  assertThat(
      test.getBinary().getComponents().getModules().values(),
      Matchers.allOf(Matchers.hasItem(libASrc), Matchers.not(Matchers.hasItem(libBSrc))));
}
项目:buck    文件:GoBinaryDescription.java   
@Override
public BuildRule createBuildRule(
    TargetGraph targetGraph,
    BuildTarget buildTarget,
    ProjectFilesystem projectFilesystem,
    BuildRuleParams params,
    BuildRuleResolver resolver,
    CellPathResolver cellRoots,
    GoBinaryDescriptionArg args) {
  GoToolchain goToolchain = getGoToolchain();
  GoPlatform platform =
      goToolchain
          .getPlatformFlavorDomain()
          .getValue(buildTarget)
          .orElse(goToolchain.getDefaultPlatform());

  return GoDescriptors.createGoBinaryRule(
      buildTarget,
      projectFilesystem,
      params,
      resolver,
      goBuckConfig,
      goToolchain,
      getCxxPlatform(!args.getCgoDeps().isEmpty()),
      args.getSrcs(),
      args.getCompilerFlags(),
      args.getAssemblerFlags(),
      args.getLinkerFlags(),
      platform,
      args.getCgoDeps());
}
项目:buck    文件:PrebuiltCxxLibraryDescriptionTest.java   
@Test
public void exportedPlatformHeaders() throws Exception {
  ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
  PrebuiltCxxLibraryBuilder libBuilder =
      new PrebuiltCxxLibraryBuilder(TARGET)
          .setExportedPlatformHeaders(
              PatternMatchedCollection.<SourceList>builder()
                  .add(
                      Pattern.compile(CXX_PLATFORM.getFlavor().toString()),
                      SourceList.ofNamedSources(
                          ImmutableSortedMap.of("foo.h", FakeSourcePath.of("foo.h"))))
                  .add(
                      Pattern.compile("DO NOT MATCH ANYTNING"),
                      SourceList.ofNamedSources(
                          ImmutableSortedMap.of("bar.h", FakeSourcePath.of("bar.h"))))
                  .build());
  TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build());
  BuildRuleResolver resolver =
      new SingleThreadedBuildRuleResolver(
          targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
  SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
  PrebuiltCxxLibrary lib =
      (PrebuiltCxxLibrary) libBuilder.build(resolver, filesystem, targetGraph);

  // Verify the preprocessable input is as expected.
  CxxPreprocessorInput input = lib.getCxxPreprocessorInput(CXX_PLATFORM);
  assertThat(getHeaderNames(input.getIncludes()), Matchers.hasItem(filesystem.getPath("foo.h")));
  assertThat(
      getHeaderNames(input.getIncludes()),
      Matchers.not(Matchers.hasItem(filesystem.getPath("bar.h"))));
  assertThat(
      ImmutableSortedSet.copyOf(input.getDeps(resolver, ruleFinder)),
      Matchers.equalTo(resolver.getAllRules(getInputRules(lib))));
}
项目:buck    文件:PythonLibraryDescription.java   
@Override
public PythonLibrary createBuildRule(
    TargetGraph targetGraph,
    BuildTarget buildTarget,
    ProjectFilesystem projectFilesystem,
    BuildRuleParams params,
    BuildRuleResolver resolver,
    CellPathResolver cellRoots,
    PythonLibraryDescriptionArg args) {
  return new PythonLibrary(buildTarget, projectFilesystem, params, resolver);
}
项目:buck    文件:SanitizedArgTest.java   
@Test
public void stringify() {
  SourcePathResolver pathResolver =
      DefaultSourcePathResolver.from(
          new SourcePathRuleFinder(
              new SingleThreadedBuildRuleResolver(
                  TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));

  SanitizedArg arg = SanitizedArg.create(Functions.constant("sanitized"), "unsanitized");
  assertThat(Arg.stringifyList(arg, pathResolver), Matchers.contains("unsanitized"));
}