Java 类com.facebook.buck.model.BuildTarget 实例源码

项目:buck-cutom    文件:DexProducedFromJavaLibraryThatContainsClassFilesTest.java   
@Test
public void testObserverMethods() {
  JavaLibrary accumulateClassNames = createMock(JavaLibrary.class);
  expect(accumulateClassNames.getClassNamesToHashes())
      .andReturn(ImmutableSortedMap.of("com/example/Foo", HashCode.fromString("cafebabe")))
      .anyTimes();

  replayAll();

  BuildTarget buildTarget = BuildTarget.builder("//foo", "bar").build();
  BuildRuleParams params = new FakeBuildRuleParamsBuilder(buildTarget).build();
  DexProducedFromJavaLibrary preDexWithClasses =
      new DexProducedFromJavaLibrary(params, accumulateClassNames);
  assertNull(preDexWithClasses.getPathToOutputFile());
  assertTrue(Iterables.isEmpty(preDexWithClasses.getInputsToCompareToOutput()));
  assertEquals(Paths.get("buck-out/gen/foo/bar.dex.jar"), preDexWithClasses.getPathToDex());
  assertTrue(preDexWithClasses.hasOutput());

  verifyAll();
}
项目:buck-cutom    文件:ProjectCommand.java   
ImmutableList<String> getAnnotationProcessingTargets(ProjectCommandOptions options)
    throws BuildTargetException, BuildFileParseException, IOException, InterruptedException {
  return ImmutableList.copyOf(
      Iterables.transform(
          Iterables.getOnlyElement(
              createPartialGraphs(
                  Optional.of(ANNOTATION_PREDICATE),
                  Optional.<RuleJsonPredicate>absent(),
                  Optional.<AssociatedRulePredicate>absent(),
                  options))
              .getTargets(),
          new Function<BuildTarget, String>() {
            @Override
            public String apply(BuildTarget target) {
              return target.getFullyQualifiedName();
            }
          }));
}
项目:buck-cutom    文件:TestCommandTest.java   
/**
 * If the source paths specified are all generated files, then our path to source tmp
 * should be absent.
 */
@Test
public void testGeneratedSourceFile() {
  Path pathToGenFile = GEN_PATH.resolve("GeneratedFile.java");
  assertTrue(MorePaths.isGeneratedFile(pathToGenFile));

  ImmutableSortedSet<Path> javaSrcs = ImmutableSortedSet.of(pathToGenFile);
  JavaLibrary javaLibrary = new FakeJavaLibrary(BuildTarget.builder("//foo", "bar").build())
      .setJavaSrcs(javaSrcs);

  DefaultJavaPackageFinder defaultJavaPackageFinder =
      createMock(DefaultJavaPackageFinder.class);

  Object[] mocks = new Object[] {defaultJavaPackageFinder};
  replay(mocks);

  ImmutableSet<String> result = TestCommand.getPathToSourceFolders(
      javaLibrary, Optional.of(defaultJavaPackageFinder), new FakeProjectFilesystem());

  assertTrue("No path should be returned if the library contains only generated files.",
      result.isEmpty());

  verify(mocks);
}
项目:buck-cutom    文件:ProjectGeneratorTest.java   
@Test(expected = HumanReadableException.class)
public void shouldRejectUnknownBuildSettingsInFrameworkEntries() throws IOException {
  BuildRule rule = createBuildRuleWithDefaults(
      BuildTarget.builder("//foo", "rule")
          .setFlavor(AppleLibraryDescription.DYNAMIC_LIBRARY)
          .build(),
      ImmutableSortedSet.<BuildRule>of(),
      appleLibraryDescription,
      new Function<AppleNativeTargetDescriptionArg, AppleNativeTargetDescriptionArg>() {
        @Override
        public AppleNativeTargetDescriptionArg apply(AppleNativeTargetDescriptionArg input) {
          input.frameworks = ImmutableSortedSet.of("$FOOBAR/libfoo.a");
          return input;
        }
      }
  );

  ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(
      ImmutableSet.of(rule),
      ImmutableSet.of(rule.getBuildTarget()));
  projectGenerator.createXcodeProjects();
}
项目:buck-cutom    文件:RuleKeyTest.java   
@Test
public void ensureSetsAreHandledProperly() {
  BuildTarget target = BuildTargetFactory.newInstance("//foo/bar:baz");
  FakeBuildRule rule = new FakeBuildRule(new BuildRuleType("example"), target);
  rule.setRuleKey(RuleKey.TO_RULE_KEY.apply("cafebabe"));
  rule.setOutputFile("cheese.txt");

  ImmutableSortedSet<SourcePath> sourcePaths = ImmutableSortedSet.<SourcePath>of(
      new BuildRuleSourcePath(rule),
      new TestSourcePath("alpha/beta"));
  ImmutableSet<String> strings = ImmutableSet.of("one", "two");

  RuleKey.Builder.RuleKeyPair reflective = createEmptyRuleKey()
      .setReflectively("sourcePaths", sourcePaths)
      .setReflectively("strings", strings)
      .build();

  RuleKey.Builder.RuleKeyPair manual = createEmptyRuleKey()
      .setSourcePaths("sourcePaths", sourcePaths)
      .set("strings", strings)
      .build();

  assertEquals(manual.getTotalRuleKey(), reflective.getTotalRuleKey());
}
项目:buck-cutom    文件:ParserTest.java   
@Test
public void whenAllRulesThenSingleTargetRequestedThenRulesAreParsedOnce()
    throws BuildFileParseException, BuildTargetException, IOException, InterruptedException {
  TestProjectBuildFileParserFactory buildFileParserFactory =
      new TestProjectBuildFileParserFactory(filesystem, buildRuleTypes);
  Parser parser = createParser(emptyBuildTargets(), buildFileParserFactory);

  parser.filterAllTargetsInProject(
      filesystem,
      Lists.<String>newArrayList(),
      alwaysTrue(),
      new TestConsole(),
      ImmutableMap.<String, String>of());
  BuildTarget foo = BuildTarget.builder("//java/com/facebook", "foo").build();
  parser.parseBuildFilesForTargets(
      ImmutableList.of(foo),
      Lists.<String>newArrayList(),
      BuckEventBusFactory.newInstance(),
      new TestConsole(),
      ImmutableMap.<String, String>of());

  assertEquals("Should have cached build rules.", 1, buildFileParserFactory.calls);
}
项目:buck-cutom    文件:BuildRuleFactoryParamsTest.java   
@Test
public void testGetOptionalIntegerAttributeWithValue() {
  BuildTarget target = BuildTargetFactory.newInstance("//src/com/facebook:Main");

  Map<String, Object> instance = ImmutableMap.<String, Object>of(
      "some_value", 42);

  BuildRuleFactoryParams params = new BuildRuleFactoryParams(
      instance /* instance */,
      filesystem,
      parser,
      target,
      new FakeRuleKeyBuilderFactory());

  assertEquals(Optional.of(42), params.getOptionalIntegerAttribute("some_value"));
}
项目:buck-cutom    文件:DefaultOnDiskBuildInfoTest.java   
@Test
public void whenMetadataEmptyStringThenGetRuleKeyWithoutDepsReturnsAbsent() {
  ProjectFilesystem projectFilesystem = EasyMock.createMock(ProjectFilesystem.class);
  EasyMock.expect(
      projectFilesystem.readFileIfItExists(
          Paths.get("buck-out/bin/foo/bar/.baz/metadata/" +
                  BuildInfo.METADATA_KEY_FOR_RULE_KEY_WITHOUT_DEPS)))
      .andReturn(Optional.of(""));
  EasyMock.replay(projectFilesystem);

  BuildTarget buildTarget = BuildTarget.builder("//foo/bar", "baz").build();
  DefaultOnDiskBuildInfo onDiskBuildInfo = new DefaultOnDiskBuildInfo(
      buildTarget,
      projectFilesystem);
  assertEquals(Optional.absent(), onDiskBuildInfo.getRuleKeyWithoutDeps());

  EasyMock.verify(projectFilesystem);
}
项目:buck-cutom    文件:AuditOwnerCommandTest.java   
@Test
public void verifyMissingFilesAreCorrectlyReported() throws CmdLineException {
  // All files will be directories now
  FakeProjectFilesystem filesystem = new FakeProjectFilesystem() {
    @Override
    public File getFileForRelativePath(String pathRelativeToProjectRoot) {
      return new MissingFile(getRootPath(), pathRelativeToProjectRoot);
    }
  };

  // Inputs that should be treated as missing files
  ImmutableSet<String> inputs = ImmutableSet.of(
      "java/somefolder/badfolder/somefile.java",
      "java/somefolder/perfect.java",
      "com/test/subtest/random.java");

  BuildTarget target = BuildTarget.builder("//base", "name").build();
  TargetNode<?> targetNode = createTargetNode(target, ImmutableSet.<Path>of());

  AuditOwnerCommand command = createAuditOwnerCommand(filesystem);
  AuditOwnerCommand.OwnersReport report = command.generateOwnersReport(targetNode, inputs, false);
  assertTrue(report.owners.isEmpty());
  assertTrue(report.nonFileInputs.isEmpty());
  assertTrue(report.inputsWithNoOwners.isEmpty());
  assertEquals(inputs, report.nonExistentInputs);
}
项目:buck-cutom    文件:TestCommandTest.java   
/**
 * If the source paths specified are from the new unified source tmp then we should return
 * the correct source tmp corresponding to the unified source path.
 */
@Test
public void testUnifiedSourceFile() {
  Path pathToNonGenFile = Paths.get("java/package/SourceFile1.java");
  assertFalse(MorePaths.isGeneratedFile(pathToNonGenFile));

  ImmutableSortedSet<Path> javaSrcs = ImmutableSortedSet.of(pathToNonGenFile);
  JavaLibrary javaLibrary = new FakeJavaLibrary(BuildTarget.builder("//foo", "bar").build())
      .setJavaSrcs(javaSrcs);

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

  Object[] mocks = new Object[] {defaultJavaPackageFinder};
  replay(mocks);

  ImmutableSet<String> result = TestCommand.getPathToSourceFolders(
      javaLibrary, Optional.of(defaultJavaPackageFinder), new FakeProjectFilesystem());

  assertEquals("All non-generated source files are under one source tmp.",
      ImmutableSet.of("java/"), result);

  verify(mocks);
}
项目:buck-cutom    文件:ArchivesTest.java   
@Test
public void testThatOriginalBuildParamsDepsDoNotPropagateToArchive() {

  // Create an `Archive` rule using build params with an existing dependency,
  // as if coming from a `TargetNode` which had declared deps.  These should *not*
  // propagate to the `Archive` rule, since it only cares about dependencies generating
  // it's immediate inputs.
  BuildRule dep = new FakeBuildRule(
      BuildRuleParamsFactory.createTrivialBuildRuleParams(
          BuildTargetFactory.newInstance("//:fake")));
  BuildTarget target = BuildTargetFactory.newInstance("//:archive");
  BuildRuleParams params =
      new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//:dummy"))
          .setDeps(ImmutableSortedSet.of(dep))
          .build();
  Archive archive = Archives.createArchiveRule(
      target,
      params,
      DEFAULT_ARCHIVER,
      DEFAULT_OUTPUT,
      DEFAULT_INPUTS);

  // Verify that the archive rules dependencies are empty.
  assertEquals(archive.getDeps(), ImmutableSortedSet.<BuildRule>of());
}
项目:buck-cutom    文件:DefaultOnDiskBuildInfoTest.java   
@Test
   public void whenMetadataValidRuleKeyThenGetRuleKeyReturnsKey() {
  ProjectFilesystem projectFilesystem = EasyMock.createMock(ProjectFilesystem.class);
  String key = "fa";
  EasyMock.expect(
      projectFilesystem.readFileIfItExists(
          Paths.get("buck-out/bin/foo/bar/.baz/metadata/" + BuildInfo.METADATA_KEY_FOR_RULE_KEY)))
      .andReturn(Optional.of(key));
  EasyMock.replay(projectFilesystem);

  BuildTarget buildTarget = BuildTarget.builder("//foo/bar", "baz").build();
  DefaultOnDiskBuildInfo onDiskBuildInfo = new DefaultOnDiskBuildInfo(
      buildTarget,
      projectFilesystem);
  assertEquals(Optional.of(new RuleKey(key)), onDiskBuildInfo.getRuleKey());

  EasyMock.verify(projectFilesystem);
}
项目:buck-cutom    文件:ConstructorArgMarshallerTest.java   
@Test
public void upperBoundGenericTypesCauseValuesToBeSetToTheUpperBound()
    throws ConstructorArgMarshalException {

  class Dto implements ConstructorArg {
    public List<? extends SourcePath> yup;
  }

  BuildTarget target = BuildTargetFactory.newInstance("//will:happen");
  ruleResolver.addToIndex(target, new FakeBuildRule(new BuildRuleType("example"), target));
  Dto dto = new Dto();
  marshaller.populate(
      ruleResolver,
      filesystem,
      buildRuleFactoryParams(ImmutableMap.<String, Object>of(
          "yup", ImmutableList.of(target.getFullyQualifiedName()))),
      dto);

  BuildRuleSourcePath path = new BuildRuleSourcePath(new FakeBuildRule(ruleType, target));
  assertEquals(ImmutableList.of(path), dto.yup);
}
项目:buck-cutom    文件:PartialGraph.java   
private static PartialGraph parseAndCreateGraphFromTargets(
    ImmutableSet<BuildTarget> targets,
    Iterable<String> includes,
    Parser parser,
    BuckEventBus eventBus,
    Console console, ImmutableMap<String, String> environment)
    throws BuildTargetException, BuildFileParseException, IOException, InterruptedException {

  Preconditions.checkNotNull(parser);

  // Now that the Parser is loaded up with the set of all build rules, use it to create a
  // DependencyGraph of only the targets we want to build.
  ActionGraph graph = parser.parseBuildFilesForTargets(
      targets,
      includes,
      eventBus,
      console,
      environment);

  return new PartialGraph(graph, targets);
}
项目:buck-cutom    文件:GenruleTest.java   
@Test
public void testGetOutputNameMethod() {
  BuildTarget target = BuildTargetFactory.newInstance("//:test");

  // Sample data of output names to test with Genrule
  ImmutableList<String> names = ImmutableList.of(
      "out.txt",
      "out/file.txt");

  // Create genrules using the names above and verify the output name method returns
  // them.
  for (String name : names) {
    Genrule genrule = GenruleBuilder
        .createGenrule(target)
        .setOut(name)
        .build();
    assertEquals(name, genrule.getOutputName());
  }
}
项目:buck-cutom    文件:AppleBuildRulesTest.java   
@Test
public void testAppleLibraryIsNotXcodeTargetTestBuildRuleType() throws Exception {
  BuildRuleParams params =
      new FakeBuildRuleParamsBuilder(BuildTarget.builder("//foo", "lib").build())
          .setType(AppleLibraryDescription.TYPE)
          .build();
  AppleNativeTargetDescriptionArg arg =
      appleLibraryDescription.createUnpopulatedConstructorArg();
  arg.configs = ImmutableMap.of();
  arg.srcs = ImmutableList.of();
  arg.frameworks = ImmutableSortedSet.of();
  arg.deps = Optional.absent();
  arg.gid = Optional.absent();
  arg.headerPathPrefix = Optional.absent();
  arg.useBuckHeaderMaps = Optional.absent();
  AppleLibrary libraryRule =
      appleLibraryDescription.createBuildRule(params, new BuildRuleResolver(), arg);

  assertFalse(AppleBuildRules.isXcodeTargetTestBuildRule(libraryRule));
}
项目:buck-cutom    文件:ProjectTest.java   
@Test
public void testDoNotIgnoreAllOfBuckOut() {
  ProjectFilesystem projectFilesystem = EasyMock.createMock(ProjectFilesystem.class);
  ImmutableSet<Path> ignorePaths = ImmutableSet.of(Paths.get("buck-out"), Paths.get(".git"));
  EasyMock.expect(projectFilesystem.getIgnorePaths()).andReturn(ignorePaths);
  EasyMock.replay(projectFilesystem);

  BuildTarget buildTarget = BuildTarget.builder("//", "base").build();
  BuildRule buildRule = new FakeBuildRule(JavaLibraryDescription.TYPE, buildTarget);
  Module module = new Module(buildRule, buildTarget);

  Project.addRootExcludes(module, buildRule, projectFilesystem);

  ImmutableSortedSet<SourceFolder> expectedExcludeFolders =
      ImmutableSortedSet.orderedBy(Module.ALPHABETIZER)
      .add(new SourceFolder("file://$MODULE_DIR$/.git", /* isTestSource */ false))
      .add(new SourceFolder("file://$MODULE_DIR$/buck-out/bin", /* isTestSource */ false))
      .add(new SourceFolder("file://$MODULE_DIR$/buck-out/log", /* isTestSource */ false))
      .build();
  assertEquals("Specific subfolders of buck-out should be excluded rather than all of buck-out.",
      expectedExcludeFolders,
      module.excludeFolders);

  EasyMock.verify(projectFilesystem);
}
项目:buck-cutom    文件:TargetsCommand.java   
/**
 * @param referencedPaths All of these paths must be relative to the project root.
 */
public TargetsCommandPredicate(
    PartialGraph partialGraph,
    ImmutableSet<BuildRuleType> buildRuleTypes,
    ImmutableSet<String> referencedPaths,
    ImmutableSet<BuildTarget> matchingBuildRules) {
  this.graph = partialGraph.getActionGraph();
  this.buildRuleTypes = Preconditions.checkNotNull(buildRuleTypes);
  this.matchingBuildRules = Preconditions.checkNotNull(matchingBuildRules);

  Preconditions.checkNotNull(referencedPaths);
  if (!referencedPaths.isEmpty()) {
    this.referencedInputs = MorePaths.asPaths(referencedPaths);
    BuildFileTree tree = new InMemoryBuildFileTree(partialGraph.getTargets());
    basePathOfTargets = Sets.newHashSet();
    dependentTargets = Sets.newHashSet();
    for (Path input : referencedInputs) {
      basePathOfTargets.add(tree.getBasePathOfAncestorTarget(input));
    }
  } else {
    basePathOfTargets = ImmutableSet.of();
    dependentTargets = ImmutableSet.of();
  }
}
项目:buck-cutom    文件:ParserTest.java   
@Test
public void whenSingleTargetThenAllRulesRequestedThenRulesAreParsedTwice()
    throws BuildFileParseException, BuildTargetException, IOException, InterruptedException {
  TestProjectBuildFileParserFactory buildFileParserFactory =
      new TestProjectBuildFileParserFactory(filesystem, buildRuleTypes);
  Parser parser = createParser(emptyBuildTargets(), buildFileParserFactory);

  BuildTarget foo = BuildTarget.builder("//java/com/facebook", "foo").build();
  parser.parseBuildFilesForTargets(
      ImmutableList.of(foo),
      Lists.<String>newArrayList(),
      BuckEventBusFactory.newInstance(),
      new TestConsole(),
      ImmutableMap.<String, String>of());
  parser.filterAllTargetsInProject(
      filesystem,
      Lists.<String>newArrayList(),
      alwaysTrue(),
      new TestConsole(),
      ImmutableMap.<String, String>of());

  assertEquals("Should have replaced build rules", 2, buildFileParserFactory.calls);
}
项目:buck-cutom    文件:AuditOwnerCommandTest.java   
@Test
public void verifyInputsWithoutOwnersAreCorrectlyReported() throws CmdLineException {
  FakeProjectFilesystem filesystem = new FakeProjectFilesystem() {
    @Override
    public File getFileForRelativePath(String pathRelativeToProjectRoot) {
      return new ExistingFile(getRootPath(), pathRelativeToProjectRoot);
    }
  };

  // Inputs that should be treated as existing files
  ImmutableSet<String> inputs = ImmutableSet.of(
      "java/somefolder/badfolder/somefile.java",
      "java/somefolder/perfect.java",
      "com/test/subtest/random.java");
  ImmutableSet<Path> inputPaths = MorePaths.asPaths(inputs);

  BuildTarget target = BuildTarget.builder("//base", "name").build();
  TargetNode<?> targetNode = createTargetNode(target, ImmutableSet.<Path>of());

  AuditOwnerCommand command = createAuditOwnerCommand(filesystem);
  AuditOwnerCommand.OwnersReport report = command.generateOwnersReport(targetNode, inputs, false);
  assertTrue(report.owners.isEmpty());
  assertTrue(report.nonFileInputs.isEmpty());
  assertTrue(report.nonExistentInputs.isEmpty());
  assertEquals(inputPaths, report.inputsWithNoOwners);
}
项目:buck-cutom    文件:DefaultOnDiskBuildInfoTest.java   
@Test
public void whenMetadataValidRuleKeyThenGetRuleKeyWithoutDepsReturnsKey() {
  ProjectFilesystem projectFilesystem = EasyMock.createMock(ProjectFilesystem.class);
  String key = "fa";
  EasyMock.expect(
      projectFilesystem.readFileIfItExists(
          Paths.get("buck-out/bin/foo/bar/.baz/metadata/" +
                  BuildInfo.METADATA_KEY_FOR_RULE_KEY_WITHOUT_DEPS)))
      .andReturn(Optional.of(key));
  EasyMock.replay(projectFilesystem);

  BuildTarget buildTarget = BuildTarget.builder("//foo/bar", "baz").build();
  DefaultOnDiskBuildInfo onDiskBuildInfo = new DefaultOnDiskBuildInfo(
      buildTarget,
      projectFilesystem);
  assertEquals(Optional.of(new RuleKey(key)), onDiskBuildInfo.getRuleKeyWithoutDeps());

  EasyMock.verify(projectFilesystem);
}
项目:buck-cutom    文件:ExportFile.java   
@VisibleForTesting
ExportFile(BuildRuleParams params, ExportFileDescription.Arg args) {
  super(params);
  BuildTarget target = params.getBuildTarget();
  if (args.src.isPresent()) {
    this.src = args.src.get();
  } else {
    this.src = new PathSourcePath(target.getBasePath().resolve(target.getShortName()));
  }

  final String outName = args.out.or(target.getShortName());
  this.out = BuckConstant.GEN_PATH.resolve(target.getBasePath()).resolve(outName);
}
项目:buck-cutom    文件:CxxDescriptionEnhancer.java   
/**
 * @return a map of header locations to input {@link SourcePath} objects formed by parsing the
 *    input {@link SourcePath} objects for the "headers" parameter.
 */
public static ImmutableMap<Path, SourcePath> parseHeaders(
    BuildTarget target,
    Iterable<SourcePath> inputs) {

  return CxxPreprocessables.resolveHeaderMap(
      target,
      SourcePaths.getSourcePathNames(
          target,
          "headers",
          inputs));
}
项目:buck-cutom    文件:CxxDescriptionEnhancer.java   
/**
 * @return a list {@link CxxSource} objects formed by parsing the input {@link SourcePath}
 *    objects for the "srcs" parameter.
 */
public static ImmutableList<CxxSource> parseCxxSources(
    BuildTarget target,
    Iterable<SourcePath> inputs) {

  return CxxCompilableEnhancer.resolveCxxSources(
      target,
      SourcePaths.getSourcePathNames(
          target,
          "srcs",
          inputs));
}
项目:buck-cutom    文件:AndroidLibraryGraphEnhancerTest.java   
@Test
public void testEmptyResources() {
  BuildTarget buildTarget = BuildTarget.builder("//java/com/example", "library").build();
  AndroidLibraryGraphEnhancer graphEnhancer = new AndroidLibraryGraphEnhancer(
      buildTarget,
      new FakeBuildRuleParamsBuilder(buildTarget).build(),
      JavacOptions.DEFAULTS);
  Optional<DummyRDotJava> result = graphEnhancer.createBuildableForAndroidResources(
      new BuildRuleResolver(),
      /* createdBuildableIfEmptyDeps */ false);
  assertFalse(result.isPresent());
}
项目:buck-cutom    文件:GenruleTest.java   
@Test
public void ensureFilesInSubdirectoriesAreKeptInSubDirectories() throws IOException {
  BuildTarget target = BuildTargetFactory.newInstance("//:example");
  BuildRule rule = GenruleBuilder.createGenrule(target)
      .setRelativeToAbsolutePathFunctionForTesting(ABSOLUTIFIER)
      .setBash("ignored")
      .addSrc(Paths.get("in-dir.txt"))
      .addSrc(Paths.get("foo/bar.html"))
      .addSrc(Paths.get("other/place.txt"))
      .setOut("example-file")
      .build();

  ImmutableList.Builder<Step> builder = ImmutableList.builder();
  ((Genrule) rule).addSymlinkCommands(builder);
  ImmutableList<Step> commands = builder.build();

  String baseTmpPath = GEN_DIR + "/example__srcs/";

  assertEquals(3, commands.size());
  MkdirAndSymlinkFileStep linkCmd = (MkdirAndSymlinkFileStep) commands.get(0);
  assertEquals(Paths.get("in-dir.txt"), linkCmd.getSource());
  assertEquals(Paths.get(baseTmpPath + "in-dir.txt"), linkCmd.getTarget());

  linkCmd = (MkdirAndSymlinkFileStep) commands.get(1);
  assertEquals(Paths.get("foo/bar.html"), linkCmd.getSource());
  assertEquals(Paths.get(baseTmpPath + "foo/bar.html"), linkCmd.getTarget());

  linkCmd = (MkdirAndSymlinkFileStep) commands.get(2);
  assertEquals(Paths.get("other/place.txt"), linkCmd.getSource());
  assertEquals(Paths.get(baseTmpPath + "other/place.txt"), linkCmd.getTarget());
}
项目:buck-cutom    文件:ProjectGenerator.java   
private ConfigInXcodeLayout(
    BuildTarget buildTarget,
    Optional<Path> projectLevelConfigFile,
    ImmutableMap<String, String> projectLevelInlineSettings,
    Optional<Path> targetLevelConfigFile,
    ImmutableMap<String, String> targetLevelInlineSettings) {
  this.buildTarget = Preconditions.checkNotNull(buildTarget);
  this.projectLevelConfigFile =
      Preconditions.checkNotNull(projectLevelConfigFile);
  this.projectLevelInlineSettings = Preconditions.checkNotNull(projectLevelInlineSettings);
  this.targetLevelConfigFile = Preconditions.checkNotNull(targetLevelConfigFile);
  this.targetLevelInlineSettings = Preconditions.checkNotNull(targetLevelInlineSettings);
}
项目:buck-cutom    文件:CxxPreprocessablesTest.java   
@Test
public void getTransitiveCxxPreprocessorInput() {

  // Setup a simple CxxPreprocessorDep which contributes components to preprocessing.
  BuildTarget cppDepTarget1 = BuildTargetFactory.newInstance("//:cpp1");
  CxxPreprocessorInput input1 = new CxxPreprocessorInput(
      ImmutableSet.of(cppDepTarget1),
      ImmutableList.of("-Dtest=yes"),
      ImmutableList.of("-Dtest=yes"),
      ImmutableList.of(Paths.get("foo/bar"), Paths.get("hello")),
      ImmutableList.of(Paths.get("/usr/include")));
  BuildTarget depTarget1 = BuildTargetFactory.newInstance("//:dep1");
  FakeCxxPreprocessorDep dep1 = createFakeCxxPreprocessorDep(depTarget1, input1);

  // Setup another simple CxxPreprocessorDep which contributes components to preprocessing.
  BuildTarget cppDepTarget2 = BuildTargetFactory.newInstance("//:cpp2");
  CxxPreprocessorInput input2 = new CxxPreprocessorInput(
      ImmutableSet.of(cppDepTarget2),
      ImmutableList.of("-DBLAH"),
      ImmutableList.of("-DBLAH"),
      ImmutableList.of(Paths.get("goodbye")),
      ImmutableList.of(Paths.get("test")));
  BuildTarget depTarget2 = BuildTargetFactory.newInstance("//:dep2");
  FakeCxxPreprocessorDep dep2 = createFakeCxxPreprocessorDep(depTarget2, input2);

  // Create a normal dep which depends on the two CxxPreprocessorDep rules above.
  BuildTarget depTarget3 = BuildTargetFactory.newInstance("//:dep3");
  FakeBuildRule dep3 = createFakeBuildRule(depTarget3, dep1, dep2);

  // Verify that getTransitiveCxxPreprocessorInput gets all CxxPreprocessorInput objects
  // from the relevant rules above.
  CxxPreprocessorInput expected = CxxPreprocessorInput.concat(
      ImmutableList.of(input1, input2));
  CxxPreprocessorInput actual = CxxPreprocessables.getTransitiveCxxPreprocessorInput(
      ImmutableList.<BuildRule>of(dep3));
  assertEquals(expected, actual);
}
项目:buck-cutom    文件:ProjectGeneratorTest.java   
@Test
public void testCoreDataModelRuleAddsReference() throws IOException {
  BuildRule modelRule = createBuildRuleWithDefaults(
      BuildTarget.builder("//foo", "model").build(),
      ImmutableSortedSet.<BuildRule>of(),
      coreDataModelDescription,
      new Function<CoreDataModelDescription.Arg, CoreDataModelDescription.Arg>() {
        @Override
        public CoreDataModelDescription.Arg apply(CoreDataModelDescription.Arg args) {
          args.path = new TestSourcePath("foo.xcdatamodel").asReference();
          return args;
        }
      });

  BuildRule libraryRule = createBuildRuleWithDefaults(
      BuildTarget.builder("//foo", "lib").build(),
      ImmutableSortedSet.of(modelRule),
      appleLibraryDescription);


  ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(
      ImmutableSet.of(libraryRule),
      ImmutableSet.of(libraryRule.getBuildTarget()));

  projectGenerator.createXcodeProjects();

  PBXProject project = projectGenerator.getGeneratedProject();
  PBXGroup targetGroup =
      project.getMainGroup().getOrCreateChildGroupByName(libraryRule.getFullyQualifiedName());
  PBXGroup resourcesGroup = targetGroup.getOrCreateChildGroupByName("Resources");

  assertThat(resourcesGroup.getChildren(), hasSize(1));

  PBXFileReference modelReference = (PBXFileReference) Iterables.get(
      resourcesGroup.getChildren(),
      0);
  assertEquals("foo.xcdatamodel", modelReference.getName());
}
项目:buck-cutom    文件:AuditOwnerCommandTest.java   
/**
 * Verify that owners are correctly detected:
 *  - one owner, multiple inputs
 */
@Test
public void verifyInputsWithOneOwnerAreCorrectlyReported() throws CmdLineException {
  FakeProjectFilesystem filesystem = new FakeProjectFilesystem() {
    @Override
    public File getFileForRelativePath(String pathRelativeToProjectRoot) {
      return new ExistingFile(getRootPath(), pathRelativeToProjectRoot);
    }
  };

  ImmutableSet<String> inputs = ImmutableSet.of(
      "java/somefolder/badfolder/somefile.java",
      "java/somefolder/perfect.java",
      "com/test/subtest/random.java");
  ImmutableSet<Path> inputPaths = MorePaths.asPaths(inputs);

  BuildTarget target = BuildTarget.builder("//base", "name").build();
  TargetNode<?> targetNode = createTargetNode(target, inputPaths);

  AuditOwnerCommand command = createAuditOwnerCommand(filesystem);
  AuditOwnerCommand.OwnersReport report = command.generateOwnersReport(targetNode, inputs, false);
  assertTrue(report.nonFileInputs.isEmpty());
  assertTrue(report.nonExistentInputs.isEmpty());
  assertTrue(report.inputsWithNoOwners.isEmpty());

  assertEquals(inputs.size(), report.owners.size());
  assertTrue(report.owners.containsKey(targetNode));
  assertEquals(targetNode.getInputs(), report.owners.get(targetNode));
}
项目:buck-cutom    文件:NativeLinkableInput.java   
public NativeLinkableInput(
    ImmutableSet<BuildTarget> targets,
    ImmutableList<Path> inputs,
    ImmutableList<String> args) {

  this.targets = Preconditions.checkNotNull(targets);
  this.inputs = Preconditions.checkNotNull(inputs);
  this.args = Preconditions.checkNotNull(args);
}
项目:buck-cutom    文件:CxxCompilableEnhancerTest.java   
@Test
public void createCompileBuildRulePropagatesBuilRuleSourcePathDeps() {
  BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
  BuildRuleParams params = BuildRuleParamsFactory.createTrivialBuildRuleParams(target);
  BuildRuleResolver resolver = new BuildRuleResolver();

  CxxPreprocessorInput cxxPreprocessorInput = new CxxPreprocessorInput(
      ImmutableSet.<BuildTarget>of(),
      ImmutableList.<String>of(),
      ImmutableList.<String>of(),
      ImmutableList.<Path>of(),
      ImmutableList.<Path>of());


  String name = "foo/bar.cpp";
  FakeBuildRule dep = createFakeBuildRule("//:test");
  SourcePath input = new BuildRuleSourcePath(dep);
  Path output = CxxCompilableEnhancer.getCompileOutputPath(target, name);
  CxxSource cxxSource = new CxxSource(name, input, output);

  CxxCompile cxxCompile = CxxCompilableEnhancer.createCompileBuildRule(
      params,
      resolver,
      CxxCompilables.DEFAULT_CXX_COMPILER,
      cxxPreprocessorInput,
      ImmutableList.<String>of(),
      cxxSource);

  assertEquals(ImmutableSortedSet.<BuildRule>of(dep), cxxCompile.getDeps());
}
项目:buck-cutom    文件:FakeJavaLibrary.java   
public FakeJavaLibrary(
    BuildRuleType type,
    BuildTarget target,
    ImmutableSortedSet<BuildRule> deps,
    ImmutableSet<BuildTargetPattern> visibilityPatterns) {
  super(type, target, deps, visibilityPatterns);
  this.visibilityPatterns = visibilityPatterns;
}
项目:buck-cutom    文件:DefaultJavaLibraryTest.java   
@Override
public BuildRule createRule(BuildTarget target) {
  return JavaLibraryBuilder.createBuilder(target)
      .addSrc(Paths.get("MyClass.java"))
      .setProguardConfig(Paths.get("MyProguardConfig"))
      .build(new BuildRuleResolver());
}
项目:buck-cutom    文件:EventSerializationTest.java   
private BuildRule generateFakeBuildRule() {
  BuildTarget buildTarget = BuildTargetFactory.newInstance("//fake:rule");
  FakeBuildRule result = new FakeBuildRule(
      JavaLibraryDescription.TYPE,
      buildTarget,
      ImmutableSortedSet.<BuildRule>of(),
      ImmutableSet.<BuildTargetPattern>of());
  result.setRuleKey(new RuleKey("aaaa"));
  return result;
}
项目:buck-cutom    文件:GwtBinary.java   
/**
 * @param modules The GWT modules to build with the GWT compiler.
 * @param moduleDeps The rules passed to the {@code module_deps} argument in the build file.
 */
GwtBinary(
    BuildRuleParams buildRuleParams,
    ImmutableSortedSet<String> modules,
    List<String> vmArgs,
    Style style,
    boolean draftCompile,
    int optimize,
    int localWorkers,
    boolean strict,
    List<String> experimentalArgs,
    ImmutableSortedSet<BuildRule> moduleDeps,
    ImmutableSortedSet<Path> gwtModuleJars) {
  super(buildRuleParams);
  BuildTarget buildTarget = buildRuleParams.getBuildTarget();
  this.outputFile = BuildTargets.getGenPath(
      buildTarget,
      "__gwt_binary_%s__/" + buildTarget.getShortName() + ".zip");
  this.modules = Preconditions.checkNotNull(modules);
  Preconditions.checkArgument(
      !modules.isEmpty(),
      "Must specify at least one module for %s.",
      buildTarget);
  this.vmArgs = ImmutableList.copyOf(vmArgs);
  this.style = Preconditions.checkNotNull(style);
  this.draftCompile = draftCompile;

  // No need for bounds-checking this int because GWT does it internally: http://bit.ly/1kFN5M7.
  this.optimize = optimize;

  Preconditions.checkArgument(localWorkers > 0,
      "localWorkers must be greater than zero: %d",
      localWorkers);
  this.localWorkers = localWorkers;

  this.strict = strict;
  this.experimentalArgs = ImmutableList.copyOf(experimentalArgs);
  this.moduleDeps = Preconditions.checkNotNull(moduleDeps);
  this.gwtModuleJars = Preconditions.checkNotNull(gwtModuleJars);
}
项目:buck-cutom    文件:JavaLibraryDescription.java   
@Override
public <A extends Arg> BuildRule createBuildRule(
    BuildRuleParams params,
    BuildRuleResolver resolver,
    A args) {
  BuildTarget target = params.getBuildTarget();

  // We know that the flavour we're being asked to create is valid, since the check is done when
  // creating the action graph from the target graph.

  if (JavaLibrary.SRC_JAR.equals(target.getFlavor())) {
    return new JavaSourceJar(params, args.srcs.get());
  }

  JavacOptions.Builder javacOptions = JavaLibraryDescription.getJavacOptions(args, javacEnv);

  AnnotationProcessingParams annotationParams =
      args.buildAnnotationProcessingParams(target, params.getProjectFilesystem());
  javacOptions.setAnnotationProcessingData(annotationParams);

  return new DefaultJavaLibrary(
      params,
      args.srcs.get(),
      validateResources(args, params.getProjectFilesystem()),
      args.proguardConfig,
      args.postprocessClassesCommands.get(),
      args.exportedDeps.get(),
      args.providedDeps.get(),
      /* additionalClasspathEntries */ ImmutableSet.<Path>of(),
      javacOptions.build(),
      args.resourcesRoot);
}
项目:buck-cutom    文件:GwtModule.java   
GwtModule(
    BuildRuleParams params,
    ImmutableSortedSet<SourcePath> filesForGwtModule) {
  super(params);
  BuildTarget target = params.getBuildTarget();
  this.outputFile = BuildTargets.getGenPath(
      target,
      "__gwt_module_%s__/" + target.getShortName() + ".jar");
  this.filesForGwtModule = Preconditions.checkNotNull(filesForGwtModule);
}
项目:buck-cutom    文件:CxxPreprocessablesTest.java   
@Test
public void resolveHeaderMap() {
  BuildTarget target = BuildTargetFactory.newInstance("//hello/world:test");
  ImmutableMap<String, SourcePath> headerMap = ImmutableMap.<String, SourcePath>of(
      "foo/bar.h", new TestSourcePath("header1.h"),
      "foo/hello.h", new TestSourcePath("header2.h"));

  // Verify that the resolveHeaderMap returns sane results.
  ImmutableMap<Path, SourcePath> expected = ImmutableMap.<Path, SourcePath>of(
      target.getBasePath().resolve("foo/bar.h"), new TestSourcePath("header1.h"),
      target.getBasePath().resolve("foo/hello.h"), new TestSourcePath("header2.h"));
  ImmutableMap<Path, SourcePath> actual = CxxPreprocessables.resolveHeaderMap(
      target, headerMap);
  assertEquals(expected, actual);
}
项目:buck-cutom    文件:ParserTest.java   
@Test
public void testGeneratedDeps()
    throws IOException, BuildFileParseException, BuildTargetException, InterruptedException {
  // Execute parseBuildFilesForTargets() with a target in a valid file but a bad rule name.
  tempDir.newFolder("java", "com", "facebook", "generateddeps");

  File testGeneratedDepsBuckFile = tempDir.newFile(
      "java/com/facebook/generateddeps/" + BuckConstant.BUILD_RULES_FILE_NAME);
  Files.write(
      "java_library(name = 'foo')\n" +
          "java_library(name = 'bar')\n" +
          "add_deps(name = 'foo', deps = [':bar'])\n",
      testGeneratedDepsBuckFile,
      Charsets.UTF_8);

  BuildTarget fooTarget = BuildTarget.builder("//java/com/facebook/generateddeps", "foo").build();

  BuildTarget barTarget = BuildTarget.builder("//java/com/facebook/generateddeps", "bar").build();
  Iterable<BuildTarget> buildTargets = ImmutableList.of(fooTarget, barTarget);
  Iterable<String> defaultIncludes = ImmutableList.of();

  ActionGraph graph = testParser.parseBuildFilesForTargets(
      buildTargets,
      defaultIncludes,
      BuckEventBusFactory.newInstance(),
      new TestConsole(),
      ImmutableMap.<String, String>of());

  BuildRule fooRule = graph.findBuildRuleByTarget(fooTarget);
  assertNotNull(fooRule);
  BuildRule barRule = graph.findBuildRuleByTarget(barTarget);
  assertNotNull(barRule);

  assertEquals(ImmutableSet.of(barRule), fooRule.getDeps());
}