private <A extends Arg> BuildRule getFlavoredBinaryRule( TargetGraph targetGraph, final BuildRuleParams params, final BuildRuleResolver resolver, A args) { // Cxx targets must have one Platform Flavor set otherwise nothing gets compiled. ImmutableSet<Flavor> flavors = params .getBuildTarget() .withoutFlavors(ImmutableSet.of(ReactNativeFlavors.DO_NOT_BUNDLE)) .getFlavors(); if (!cxxPlatformFlavorDomain.containsAnyOf(flavors)) { flavors = new ImmutableSet.Builder<Flavor>() .addAll(flavors) .add(defaultCxxPlatform.getFlavor()) .build(); } final TargetNode<?> binaryTargetNode = Preconditions.checkNotNull(targetGraph.get(args.binary)); // If the binary target of the AppleBundle is an AppleLibrary then the build flavor // must be specified. if (binaryTargetNode.getDescription() instanceof AppleLibraryDescription && (Sets.intersection( SUPPORTED_LIBRARY_FLAVORS, binaryTargetNode.getBuildTarget().getFlavors()) .size() != 1)) { throw new HumanReadableException( "AppleExtension bundle [%s] must have exactly one of these flavors: [%s].", binaryTargetNode.getBuildTarget().toString(), Joiner.on(", ").join(SUPPORTED_LIBRARY_FLAVORS)); } BuildRuleParams binaryRuleParams = new BuildRuleParams( args.binary, Suppliers.ofInstance( BuildRules.toBuildRulesFor( params.getBuildTarget(), resolver, binaryTargetNode.getDeclaredDeps())), Suppliers.ofInstance( BuildRules.toBuildRulesFor( params.getBuildTarget(), resolver, binaryTargetNode.getExtraDeps())), params.getProjectFilesystem(), params.getCellRoots(), params.getRuleKeyBuilderFactory()); return CxxDescriptionEnhancer.requireBuildRule( targetGraph, binaryRuleParams, resolver, flavors.toArray(new Flavor[0])); }
@Test public void testImplicitDepsAreAddedCorrectly() throws NoSuchBuildTargetException { Description<GenruleDescription.Arg> genruleDescription = new GenruleDescription(); Map<String, Object> instance = ImmutableMap.<String, Object>of( "srcs", ImmutableList.of(":baz", "//biz:baz"), "out", "AndroidManifest.xml", "cmd", "$(exe //bin:executable) $(location :arg)"); ProjectFilesystem projectFilesystem = new AllExistingProjectFilesystem(); BuildRuleFactoryParams params = new BuildRuleFactoryParams(projectFilesystem, BuildTargetFactory.newInstance("//foo:bar")); ConstructorArgMarshaller marshaller = new ConstructorArgMarshaller( new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance())); ImmutableSet.Builder<BuildTarget> declaredDeps = ImmutableSet.builder(); ImmutableSet.Builder<VisibilityPattern> visibilityPatterns = ImmutableSet.builder(); GenruleDescription.Arg constructorArg = genruleDescription.createUnpopulatedConstructorArg(); try { marshaller.populate( createCellRoots(projectFilesystem), projectFilesystem, params, constructorArg, declaredDeps, visibilityPatterns, instance); } catch (ConstructorArgMarshalException e) { fail("Expected constructorArg to be correctly populated."); } TargetNode<GenruleDescription.Arg> targetNode = new TargetNodeFactory(new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance())) .create( Hashing.sha1().hashString(params.target.getFullyQualifiedName(), UTF_8), genruleDescription, constructorArg, params, declaredDeps.build(), visibilityPatterns.build(), createCellRoots(projectFilesystem)); assertEquals( "SourcePaths and targets from cmd string should be extracted as extra deps.", ImmutableSet.of("//foo:baz", "//biz:baz", "//bin:executable", "//foo:arg"), FluentIterable.from(targetNode.getExtraDeps()) .transform(Functions.toStringFunction()) .toSet()); }
@Test public void testImplicitDepsAreAddedCorrectly() throws NoSuchBuildTargetException, TargetNode.InvalidSourcePathInputException { Description<GenruleDescription.Arg> genruleDescription = new GenruleDescription(); Map<String, Object> instance = ImmutableMap.<String, Object>of( "srcs", ImmutableList.of(":baz", "//biz:baz"), "out", "AndroidManifest.xml", "cmd", "$(exe //bin:executable) $(location :arg)"); ProjectFilesystem projectFilesystem = new AllExistingProjectFilesystem(); BuildRuleFactoryParams params = new BuildRuleFactoryParams( projectFilesystem, BuildTargetFactory.newInstance("//foo:bar"), new InMemoryBuildFileTree(ImmutableList.<BuildTarget>of()), /* enforeBuckBoundaryCheck */ true); ConstructorArgMarshaller marshaller = new ConstructorArgMarshaller(); ImmutableSet.Builder<BuildTarget> declaredDeps = ImmutableSet.builder(); ImmutableSet.Builder<BuildTargetPattern> visibilityPatterns = ImmutableSet.builder(); GenruleDescription.Arg constructorArg = genruleDescription.createUnpopulatedConstructorArg(); try { marshaller.populate( projectFilesystem, params, constructorArg, declaredDeps, visibilityPatterns, instance); } catch (ConstructorArgMarshalException e) { fail("Expected constructorArg to be correctly populated."); } TargetNode<GenruleDescription.Arg> targetNode = new TargetNode<>( genruleDescription, constructorArg, params, declaredDeps.build(), visibilityPatterns.build()); assertEquals( "SourcePaths and targets from cmd string should be extracted as extra deps.", ImmutableSet.of("//foo:baz", "//biz:baz", "//bin:executable", "//foo:arg"), FluentIterable.from(targetNode.getExtraDeps()) .transform(Functions.toStringFunction()) .toSet()); }