Search in sources :

Example 16 with UnflavoredBuildTarget

use of com.facebook.buck.model.UnflavoredBuildTarget in project buck by facebook.

the class Publisher method publish.

public ImmutableSet<DeployResult> publish(SourcePathResolver pathResolver, ImmutableSet<MavenPublishable> publishables) throws DeploymentException {
    ImmutableListMultimap<UnflavoredBuildTarget, UnflavoredBuildTarget> duplicateBuiltinBuileRules = checkForDuplicatePackagedDeps(publishables);
    if (duplicateBuiltinBuileRules.size() > 0) {
        StringBuilder sb = new StringBuilder();
        sb.append("Duplicate transitive dependencies for publishable libraries found!  This means");
        sb.append(StandardSystemProperty.LINE_SEPARATOR);
        sb.append("that the following libraries would have multiple copies if these libraries were");
        sb.append(StandardSystemProperty.LINE_SEPARATOR);
        sb.append("used together.  The can be resolved by adding a maven URL to each target listed");
        sb.append(StandardSystemProperty.LINE_SEPARATOR);
        sb.append("below:");
        for (UnflavoredBuildTarget unflavoredBuildTarget : duplicateBuiltinBuileRules.keySet()) {
            sb.append(StandardSystemProperty.LINE_SEPARATOR);
            sb.append(unflavoredBuildTarget.getFullyQualifiedName());
            sb.append(" (referenced by these build targets: ");
            Joiner.on(", ").appendTo(sb, duplicateBuiltinBuileRules.get(unflavoredBuildTarget));
            sb.append(")");
        }
        throw new DeploymentException(sb.toString());
    }
    ImmutableSet.Builder<DeployResult> deployResultBuilder = ImmutableSet.builder();
    for (MavenPublishable publishable : publishables) {
        DefaultArtifact coords = new DefaultArtifact(Preconditions.checkNotNull(publishable.getMavenCoords().get(), "No maven coordinates specified for published rule ", publishable));
        Path relativePathToOutput = pathResolver.getRelativePath(Preconditions.checkNotNull(publishable.getSourcePathToOutput(), "No path to output present in ", publishable));
        File mainItem = publishable.getProjectFilesystem().resolve(relativePathToOutput).toFile();
        if (!coords.getClassifier().isEmpty()) {
            deployResultBuilder.add(publish(coords, ImmutableList.of(mainItem)));
        }
        try {
            // If this is the "main" artifact (denoted by lack of classifier) generate and publish
            // pom alongside
            File pom = Pom.generatePomFile(pathResolver, publishable).toFile();
            deployResultBuilder.add(publish(coords, ImmutableList.of(mainItem, pom)));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    return deployResultBuilder.build();
}
Also used : Path(java.nio.file.Path) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) IOException(java.io.IOException) MavenPublishable(com.facebook.buck.jvm.java.MavenPublishable) ImmutableSet(com.google.common.collect.ImmutableSet) DeployResult(org.eclipse.aether.deployment.DeployResult) DeploymentException(org.eclipse.aether.deployment.DeploymentException) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 17 with UnflavoredBuildTarget

use of com.facebook.buck.model.UnflavoredBuildTarget in project buck by facebook.

the class Publisher method checkForDuplicatePackagedDeps.

/**
   * Checks for any packaged dependencies that exist between more than one of the targets that we
   * are trying to publish.
   * @return A multimap of dependency build targets and the publishable build targets that have them
   * included in the final package that will be uploaded.
   */
private ImmutableListMultimap<UnflavoredBuildTarget, UnflavoredBuildTarget> checkForDuplicatePackagedDeps(ImmutableSet<MavenPublishable> publishables) {
    // First build the multimap of the builtin dependencies and the publishable targets that use
    // them.
    Multimap<UnflavoredBuildTarget, UnflavoredBuildTarget> builtinDeps = HashMultimap.create();
    for (MavenPublishable publishable : publishables) {
        for (BuildRule buildRule : publishable.getPackagedDependencies()) {
            builtinDeps.put(buildRule.getBuildTarget().getUnflavoredBuildTarget(), publishable.getBuildTarget().getUnflavoredBuildTarget());
        }
    }
    // Now, check for any duplicate uses, and if found, return them.
    ImmutableListMultimap.Builder<UnflavoredBuildTarget, UnflavoredBuildTarget> builder = ImmutableListMultimap.builder();
    for (UnflavoredBuildTarget buildTarget : builtinDeps.keySet()) {
        Collection<UnflavoredBuildTarget> publishablesUsingBuildTarget = builtinDeps.get(buildTarget);
        if (publishablesUsingBuildTarget.size() > 1) {
            builder.putAll(buildTarget, publishablesUsingBuildTarget);
        }
    }
    return builder.build();
}
Also used : ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) BuildRule(com.facebook.buck.rules.BuildRule) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) MavenPublishable(com.facebook.buck.jvm.java.MavenPublishable)

Example 18 with UnflavoredBuildTarget

use of com.facebook.buck.model.UnflavoredBuildTarget in project buck by facebook.

the class BuildConfigsTest method testCustomGenerateBuildConfigDotJavaWithConstantExpressions.

@Test
public void testCustomGenerateBuildConfigDotJavaWithConstantExpressions() {
    BuildConfigFields customValues = BuildConfigFields.fromFieldDeclarations(ImmutableList.of("String KEYSTORE_TYPE = \"release\"", "int BUILD_NUMBER = 42", "long BUILD_DATE = 1404321113076000L", "float THREE = 3.0F", "boolean DEBUG = false", "int EXOPACKAGE_FLAGS = 0"));
    String expectedJavaCode = "// Generated by //java/com/example:build_config. DO NOT MODIFY.\n" + "package com.example;\n" + "public class BuildConfig {\n" + "  private BuildConfig() {}\n" + "  public static final String KEYSTORE_TYPE = \"release\";\n" + "  public static final int BUILD_NUMBER = 42;\n" + "  public static final long BUILD_DATE = 1404321113076000L;\n" + "  public static final float THREE = 3.0F;\n" + "  public static final boolean DEBUG = false;\n" + "  public static final int EXOPACKAGE_FLAGS = 0;\n" + "  public static final boolean IS_EXOPACKAGE = false;\n" + "}\n";
    UnflavoredBuildTarget source = BuildTargetFactory.newInstance("//java/com/example:build_config").getUnflavoredBuildTarget();
    String observedJavaCode = BuildConfigs.generateBuildConfigDotJava(source, "com.example", /* useConstantExpressions */
    true, customValues);
    assertEquals(expectedJavaCode, observedJavaCode);
}
Also used : UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildConfigFields(com.facebook.buck.rules.coercer.BuildConfigFields) Test(org.junit.Test)

Example 19 with UnflavoredBuildTarget

use of com.facebook.buck.model.UnflavoredBuildTarget in project buck by facebook.

the class ProjectGenerator method getSingleCopyFilesBuildPhase.

private PBXCopyFilesBuildPhase getSingleCopyFilesBuildPhase(CopyFilePhaseDestinationSpec destinationSpec, Iterable<TargetNode<?, ?>> targetNodes) {
    PBXCopyFilesBuildPhase copyFilesBuildPhase = new PBXCopyFilesBuildPhase(destinationSpec);
    HashSet<UnflavoredBuildTarget> frameworkTargets = new HashSet<UnflavoredBuildTarget>();
    for (TargetNode<?, ?> targetNode : targetNodes) {
        PBXFileReference fileReference = getLibraryFileReference(targetNode);
        PBXBuildFile buildFile = new PBXBuildFile(fileReference);
        if (fileReference.getExplicitFileType().equals(Optional.of("wrapper.framework"))) {
            UnflavoredBuildTarget buildTarget = targetNode.getBuildTarget().getUnflavoredBuildTarget();
            if (frameworkTargets.contains(buildTarget)) {
                continue;
            }
            frameworkTargets.add(buildTarget);
            NSDictionary settings = new NSDictionary();
            settings.put("ATTRIBUTES", new String[] { "CodeSignOnCopy", "RemoveHeadersOnCopy" });
            buildFile.setSettings(Optional.of(settings));
        }
        copyFilesBuildPhase.getFiles().add(buildFile);
    }
    return copyFilesBuildPhase;
}
Also used : NSDictionary(com.dd.plist.NSDictionary) PBXBuildFile(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) PBXCopyFilesBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXCopyFilesBuildPhase) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) HashSet(java.util.HashSet)

Aggregations

UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)19 BuildTarget (com.facebook.buck.model.BuildTarget)9 ImmutableSet (com.google.common.collect.ImmutableSet)7 HumanReadableException (com.facebook.buck.util.HumanReadableException)6 Path (java.nio.file.Path)6 BuildRule (com.facebook.buck.rules.BuildRule)4 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)4 SourcePath (com.facebook.buck.rules.SourcePath)4 Flavor (com.facebook.buck.model.Flavor)3 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 SimplePerfEvent (com.facebook.buck.event.SimplePerfEvent)2 MavenPublishable (com.facebook.buck.jvm.java.MavenPublishable)2 Flavored (com.facebook.buck.model.Flavored)2 BuildRuleType (com.facebook.buck.rules.BuildRuleType)2 Cell (com.facebook.buck.rules.Cell)2 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)2 ParamInfoException (com.facebook.buck.rules.ParamInfoException)2 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)2