Search in sources :

Example 6 with TargetNodeTranslator

use of com.facebook.buck.versions.TargetNodeTranslator in project buck by facebook.

the class PatternMatchedCollectionTest method translatedTargets.

@Test
public void translatedTargets() {
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    BuildTarget newTarget = BuildTargetFactory.newInstance("//something:else");
    TargetNodeTranslator translator = new FixedTargetNodeTranslator(ImmutableMap.of(target, newTarget));
    PatternMatchedCollection<BuildTarget> collection = PatternMatchedCollection.<BuildTarget>builder().add(Pattern.compile("something"), target).build();
    assertThat(translator.translate(CELL_PATH_RESOLVER, PATTERN, collection).map(PatternMatchedCollection::getValues), Matchers.equalTo(Optional.of(ImmutableList.of(newTarget))));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) FixedTargetNodeTranslator(com.facebook.buck.versions.FixedTargetNodeTranslator) TargetNodeTranslator(com.facebook.buck.versions.TargetNodeTranslator) FixedTargetNodeTranslator(com.facebook.buck.versions.FixedTargetNodeTranslator) Test(org.junit.Test)

Example 7 with TargetNodeTranslator

use of com.facebook.buck.versions.TargetNodeTranslator in project buck by facebook.

the class LocationMacroTest method translateTargets.

@Test
public void translateTargets() {
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    BuildTarget otherTarget = BuildTargetFactory.newInstance("//:other");
    BuildTarget newTarget = BuildTargetFactory.newInstance("//something:else");
    TargetNodeTranslator translator = new FixedTargetNodeTranslator(ImmutableMap.of(target, newTarget));
    assertThat(translator.translate(CELL_PATH_RESOLVER, PATTERN, LocationMacro.of(otherTarget)), Matchers.equalTo(Optional.empty()));
    assertThat(translator.translate(CELL_PATH_RESOLVER, PATTERN, LocationMacro.of(target)), Matchers.equalTo(Optional.of(LocationMacro.of(newTarget))));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) FixedTargetNodeTranslator(com.facebook.buck.versions.FixedTargetNodeTranslator) TargetNodeTranslator(com.facebook.buck.versions.TargetNodeTranslator) FixedTargetNodeTranslator(com.facebook.buck.versions.FixedTargetNodeTranslator) Test(org.junit.Test)

Example 8 with TargetNodeTranslator

use of com.facebook.buck.versions.TargetNodeTranslator in project buck by facebook.

the class PatternMatchedCollectionTest method untranslatedTargets.

@Test
public void untranslatedTargets() {
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    TargetNodeTranslator translator = new FixedTargetNodeTranslator(ImmutableMap.of());
    PatternMatchedCollection<BuildTarget> collection = PatternMatchedCollection.<BuildTarget>builder().add(Pattern.compile("something"), target).build();
    assertThat(translator.translate(CELL_PATH_RESOLVER, PATTERN, collection), Matchers.equalTo(Optional.empty()));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) FixedTargetNodeTranslator(com.facebook.buck.versions.FixedTargetNodeTranslator) TargetNodeTranslator(com.facebook.buck.versions.TargetNodeTranslator) FixedTargetNodeTranslator(com.facebook.buck.versions.FixedTargetNodeTranslator) Test(org.junit.Test)

Example 9 with TargetNodeTranslator

use of com.facebook.buck.versions.TargetNodeTranslator in project buck by facebook.

the class CxxGenruleDescriptionTest method targetTranslateConstructorArg.

@Test
public void targetTranslateConstructorArg() throws NoSuchBuildTargetException {
    BuildTarget target = BuildTargetFactory.newInstance("//foo:lib");
    BuildTarget original = BuildTargetFactory.newInstance("//hello:world");
    BuildTarget translated = BuildTargetFactory.newInstance("//something:else");
    CxxGenruleBuilder builder = new CxxGenruleBuilder(target).setCmd(String.format("$(cppflags %s)", original));
    TargetNode<CxxGenruleDescription.Arg, CxxGenruleDescription> node = builder.build();
    TargetNodeTranslator translator = new FixedTargetNodeTranslator(ImmutableMap.of(original, translated));
    Optional<CxxGenruleDescription.Arg> translatedArg = node.getDescription().translateConstructorArg(target, node.getCellNames(), translator, node.getConstructorArg());
    assertThat(translatedArg.get().cmd.get(), Matchers.equalTo("$(cppflags //something:else)"));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) Arg(com.facebook.buck.rules.args.Arg) FixedTargetNodeTranslator(com.facebook.buck.versions.FixedTargetNodeTranslator) TargetNodeTranslator(com.facebook.buck.versions.TargetNodeTranslator) FixedTargetNodeTranslator(com.facebook.buck.versions.FixedTargetNodeTranslator) Test(org.junit.Test)

Example 10 with TargetNodeTranslator

use of com.facebook.buck.versions.TargetNodeTranslator in project buck by facebook.

the class StringWithMacrosTest method translateTargets.

@Test
public void translateTargets() {
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    BuildTarget newTarget = BuildTargetFactory.newInstance("//something:else");
    TargetNodeTranslator translator = new FixedTargetNodeTranslator(ImmutableMap.of(target, newTarget));
    assertThat(translator.translate(CELL_PATH_RESOLVER, PATTERN, StringWithMacrosUtils.format("--flag")), Matchers.equalTo(Optional.empty()));
    assertThat(translator.translate(CELL_PATH_RESOLVER, PATTERN, StringWithMacrosUtils.format("--flag=%s", LocationMacro.of(target))), Matchers.equalTo(Optional.of(StringWithMacrosUtils.format("--flag=%s", LocationMacro.of(newTarget)))));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) FixedTargetNodeTranslator(com.facebook.buck.versions.FixedTargetNodeTranslator) TargetNodeTranslator(com.facebook.buck.versions.TargetNodeTranslator) FixedTargetNodeTranslator(com.facebook.buck.versions.FixedTargetNodeTranslator) Test(org.junit.Test)

Aggregations

BuildTarget (com.facebook.buck.model.BuildTarget)12 TargetNodeTranslator (com.facebook.buck.versions.TargetNodeTranslator)12 FixedTargetNodeTranslator (com.facebook.buck.versions.FixedTargetNodeTranslator)11 Test (org.junit.Test)11 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)5 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 BuildTargetPattern (com.facebook.buck.model.BuildTargetPattern)1 BuildTargets (com.facebook.buck.model.BuildTargets)1 Flavor (com.facebook.buck.model.Flavor)1 FlavorDomain (com.facebook.buck.model.FlavorDomain)1 Flavored (com.facebook.buck.model.Flavored)1 MacroException (com.facebook.buck.model.MacroException)1 MacroFinder (com.facebook.buck.model.MacroFinder)1 MacroReplacer (com.facebook.buck.model.MacroReplacer)1 BuildTargetParseException (com.facebook.buck.parser.BuildTargetParseException)1 BuildTargetParser (com.facebook.buck.parser.BuildTargetParser)1 BuildTargetPatternParser (com.facebook.buck.parser.BuildTargetPatternParser)1 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)1 BuildRule (com.facebook.buck.rules.BuildRule)1 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)1