Java 类com.facebook.buck.step.fs.CopyStep 实例源码

项目:buck-cutom    文件:AppleResource.java   
@Override
public ImmutableList<Step> getBuildSteps(
    BuildContext context,
    BuildableContext buildableContext) {

  ImmutableList.Builder<Step> steps = ImmutableList.builder();

  for (Path dir : dirs) {
    steps.add(
        CopyStep.forDirectory(
            dir,
            outputDirectory,
            CopyStep.DirectoryMode.DIRECTORY_AND_CONTENTS));
  }

  for (SourcePath file : files) {
    steps.add(CopyStep.forFile(file.resolve(), outputDirectory));
  }

  // TODO(grp): Support copying variant resources like Xcode.

  return steps.build();
}
项目:buck-cutom    文件:NdkLibrary.java   
@Override
public ImmutableList<Step> getBuildSteps(
    BuildContext context,
    BuildableContext buildableContext) {

  // .so files are written to the libs/ subdirectory of the output directory.
  // All of them should be recorded via the BuildableContext.
  Path binDirectory = buildArtifactsDirectory.resolve("libs");
  Step nkdBuildStep = new NdkBuildStep(makefileDirectory,
      buildArtifactsDirectory,
      binDirectory,
      flags);

  Step mkDirStep = new MakeCleanDirectoryStep(genDirectory);
  Step copyStep = CopyStep.forDirectory(
      binDirectory,
      genDirectory,
      CopyStep.DirectoryMode.CONTENTS_ONLY);

  buildableContext.recordArtifactsInDirectory(genDirectory);
  // Some tools need to inspect .so files whose symbols haven't been stripped, so cache these too.
  buildableContext.recordArtifactsInDirectory(buildArtifactsDirectory);
  return ImmutableList.of(nkdBuildStep, mkDirStep, copyStep);
}
项目:buck    文件:SrcZipAwareFileBundler.java   
@Override
protected void addCopySteps(
    ProjectFilesystem filesystem,
    BuildCellRelativePathFactory buildCellRelativePathFactory,
    ImmutableList.Builder<Step> steps,
    Path relativePath,
    Path absolutePath,
    Path destination) {
  if (relativePath.toString().endsWith(Javac.SRC_ZIP)
      || relativePath.toString().endsWith(Javac.SRC_JAR)) {
    steps.add(new UnzipStep(filesystem, absolutePath, destination.getParent(), Optional.empty()));
    return;
  }

  if (destination.getParent() != null) {
    steps.add(MkdirStep.of(buildCellRelativePathFactory.from(destination.getParent())));
  }
  steps.add(CopyStep.forFile(filesystem, absolutePath, destination));
}
项目:buck    文件:CompareAbis.java   
@Override
public ImmutableList<Step> getBuildSteps(
    BuildContext context, BuildableContext buildableContext) {
  ProjectFilesystem filesystem = getProjectFilesystem();
  SourcePathResolver sourcePathResolver = context.getSourcePathResolver();

  Path classAbiPath = sourcePathResolver.getAbsolutePath(classAbi);
  Path sourceAbiPath = sourcePathResolver.getAbsolutePath(sourceAbi);
  buildableContext.recordArtifact(outputPath);
  return ImmutableList.of(
      MkdirStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              context.getBuildCellRootPath(), getProjectFilesystem(), outputPath.getParent())),
      DiffAbisStep.of(classAbiPath, sourceAbiPath, verificationMode),
      CopyStep.forFile(filesystem, classAbiPath, outputPath));
}
项目:buck    文件:CxxStrip.java   
@Override
public ImmutableList<Step> getBuildSteps(
    BuildContext context, BuildableContext buildableContext) {
  buildableContext.recordArtifact(output);
  return ImmutableList.of(
      CopyStep.forFile(
          getProjectFilesystem(),
          context.getSourcePathResolver().getAbsolutePath(unstrippedBinary),
          output),
      new StripSymbolsStep(
          getBuildTarget(),
          output,
          strip.getCommandPrefix(context.getSourcePathResolver()),
          strip.getEnvironment(context.getSourcePathResolver()),
          stripStyle.getStripToolArgs(),
          getProjectFilesystem()));
}
项目:buck    文件:PrebuiltDotnetLibrary.java   
@Override
public ImmutableList<Step> getBuildSteps(
    BuildContext context, BuildableContext buildableContext) {
  ImmutableList.Builder<Step> steps = ImmutableList.builder();

  steps.add(
      RmStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              context.getBuildCellRootPath(), getProjectFilesystem(), output)));
  steps.add(
      MkdirStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              context.getBuildCellRootPath(), getProjectFilesystem(), output.getParent())));
  steps.add(
      CopyStep.forFile(
          getProjectFilesystem(),
          context.getSourcePathResolver().getAbsolutePath(assembly),
          output));

  return steps.build();
}
项目:buck    文件:AppleBundle.java   
/**
 * @param binariesMap A map from destination to source. Destination is deliberately used as a key
 *     prevent multiple sources overwriting the same destination.
 */
private void copyBinariesIntoBundle(
    ImmutableList.Builder<Step> stepsBuilder,
    BuildContext context,
    ImmutableMap<Path, Path> binariesMap) {
  stepsBuilder.add(
      MkdirStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              context.getBuildCellRootPath(),
              getProjectFilesystem(),
              bundleRoot.resolve(this.destinations.getExecutablesPath()))));

  binariesMap.forEach(
      (binaryBundlePath, binaryOutputPath) -> {
        stepsBuilder.add(
            CopyStep.forFile(getProjectFilesystem(), binaryOutputPath, binaryBundlePath));
      });
}
项目:buck    文件:AppleBundle.java   
private void appendCopyDsymStep(
    ImmutableList.Builder<Step> stepsBuilder,
    BuildableContext buildableContext,
    BuildContext buildContext) {
  if (appleDsym.isPresent()) {
    stepsBuilder.add(
        CopyStep.forDirectory(
            getProjectFilesystem(),
            buildContext
                .getSourcePathResolver()
                .getRelativePath(appleDsym.get().getSourcePathToOutput()),
            bundleRoot.getParent(),
            CopyStep.DirectoryMode.DIRECTORY_AND_CONTENTS));
    appendDsymRenameStepToMatchBundleName(stepsBuilder, buildableContext, buildContext);
  }
}
项目:buck    文件:AppleBundle.java   
private void addStepsToCopyExtensionBundlesDependencies(
    BuildContext context,
    ImmutableList.Builder<Step> stepsBuilder,
    ImmutableList.Builder<Path> codeSignOnCopyPathsBuilder) {
  for (Map.Entry<SourcePath, String> entry : extensionBundlePaths.entrySet()) {
    Path srcPath = context.getSourcePathResolver().getAbsolutePath(entry.getKey());
    Path destPath = bundleRoot.resolve(entry.getValue());
    stepsBuilder.add(
        MkdirStep.of(
            BuildCellRelativePath.fromCellRelativePath(
                context.getBuildCellRootPath(), getProjectFilesystem(), destPath)));
    stepsBuilder.add(
        CopyStep.forDirectory(
            getProjectFilesystem(),
            srcPath,
            destPath,
            CopyStep.DirectoryMode.DIRECTORY_AND_CONTENTS));
    if (srcPath.toString().endsWith("." + FRAMEWORK_EXTENSION)) {
      codeSignOnCopyPathsBuilder.add(destPath.resolve(srcPath.getFileName()));
    }
  }
}
项目:buck    文件:PrebuiltAppleFramework.java   
@Override
public ImmutableList<Step> getBuildSteps(
    BuildContext context, BuildableContext buildableContext) {
  // This file is copied rather than symlinked so that when it is included in an archive zip and
  // unpacked on another machine, it is an ordinary file in both scenarios.
  ImmutableList.Builder<Step> builder = ImmutableList.builder();
  builder.add(
      MkdirStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              context.getBuildCellRootPath(), getProjectFilesystem(), out.getParent())));
  builder.add(
      RmStep.of(
              BuildCellRelativePath.fromCellRelativePath(
                  context.getBuildCellRootPath(), getProjectFilesystem(), out))
          .withRecursive(true));
  builder.add(
      CopyStep.forDirectory(
          getProjectFilesystem(),
          context.getSourcePathResolver().getAbsolutePath(frameworkPath),
          out,
          CopyStep.DirectoryMode.CONTENTS_ONLY));

  buildableContext.recordArtifact(out);
  return builder.build();
}
项目:buck    文件:AaptPackageResources.java   
static void prepareManifestForAapt(
    BuildContext context,
    ImmutableList.Builder<Step> stepBuilder,
    ProjectFilesystem projectFilesystem,
    Path finalManifestPath,
    Path rawManifestPath,
    ManifestEntries manifestEntries) {
  // Copy manifest to a path named AndroidManifest.xml after replacing the manifest placeholders
  // if needed. Do this before running any other commands to ensure that it is available at the
  // desired path.

  stepBuilder.add(
      MkdirStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              context.getBuildCellRootPath(), projectFilesystem, finalManifestPath.getParent())));

  Optional<ImmutableMap<String, String>> placeholders = manifestEntries.getPlaceholders();
  if (placeholders.isPresent() && !placeholders.get().isEmpty()) {
    stepBuilder.add(
        new ReplaceManifestPlaceholdersStep(
            projectFilesystem, rawManifestPath, finalManifestPath, placeholders.get()));
  } else {
    stepBuilder.add(CopyStep.forFile(projectFilesystem, rawManifestPath, finalManifestPath));
  }
}
项目:buck    文件:AssembleDirectories.java   
@Override
public ImmutableList<Step> getBuildSteps(
    BuildContext context, BuildableContext buildableContext) {
  ImmutableList.Builder<Step> steps = ImmutableList.builder();
  steps.addAll(
      MakeCleanDirectoryStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              context.getBuildCellRootPath(), getProjectFilesystem(), destinationDirectory)));
  for (SourcePath directory : originalDirectories) {
    Path resolvedPath = context.getSourcePathResolver().getAbsolutePath(directory);
    steps.add(
        CopyStep.forDirectory(
            getProjectFilesystem(),
            resolvedPath,
            destinationDirectory,
            CopyStep.DirectoryMode.CONTENTS_ONLY));
  }
  buildableContext.recordArtifact(destinationDirectory);
  return steps.build();
}
项目:buck    文件:ProguardTextOutput.java   
@Override
public ImmutableList<? extends Step> getBuildSteps(
    BuildContext buildContext, BuildableContext buildableContext) {
  SourcePathResolver resolver = buildContext.getSourcePathResolver();
  Path configPath = resolver.getAbsolutePath(proguardConfigPath);
  ImmutableList.Builder<Step> builder = ImmutableList.builder();
  builder.addAll(
      MakeCleanDirectoryStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              buildContext.getBuildCellRootPath(), getProjectFilesystem(), getOutputPath())));
  for (String file : ImmutableList.of("configuration.txt", "mapping.txt")) {
    builder.add(
        CopyStep.forFile(
            getProjectFilesystem(), configPath.resolve(file), getOutputPath().resolve(file)));
  }
  buildableContext.recordArtifact(getOutputPath());
  return builder.build();
}
项目:buck-cutom    文件:JavaSourceJar.java   
@Override
public ImmutableList<Step> getBuildSteps(
    BuildContext context, BuildableContext buildableContext) {
  JavaPackageFinder packageFinder = context.getJavaPackageFinder();

  ImmutableList.Builder<Step> steps = ImmutableList.builder();

  steps.add(new MkdirStep(output.getParent()));
  steps.add(new RmStep(output, /* force deletion */ true));
  steps.add(new MakeCleanDirectoryStep(temp));

  Set<Path> seenPackages = Sets.newHashSet();

  // We only want to consider raw source files, since the java package finder doesn't have the
  // smarts to read the "package" line from a source file.

  for (Path source : SourcePaths.filterInputsToCompareToOutput(sources)) {
    String packageFolder = packageFinder.findJavaPackageFolderForPath(source.toString());
    Path packageDir = temp.resolve(packageFolder);
    if (seenPackages.add(packageDir)) {
      steps.add(new MkdirStep(packageDir));
    }
    steps.add(CopyStep.forFile(source, packageDir.resolve(source.getFileName())));
  }
  steps.add(new ZipStep(
          output,
          ImmutableSet.<Path>of(),
          /* junk paths */ false,
          DEFAULT_COMPRESSION_LEVEL,
          temp));

  buildableContext.recordArtifact(output);

  return steps.build();
}
项目:buck-cutom    文件:ExportFile.java   
@Override
public ImmutableList<Step> getBuildSteps(
    BuildContext context,
    BuildableContext buildableContext) {

  // This file is copied rather than symlinked so that when it is included in an archive zip and
  // unpacked on another machine, it is an ordinary file in both scenarios.
  ImmutableList.Builder<Step> builder = ImmutableList.<Step>builder()
      .add(new MkdirStep(out.getParent()))
      .add(CopyStep.forFile(src.resolve(), out));

  buildableContext.recordArtifact(out);
  return builder.build();
}
项目:buck-cutom    文件:JavaSourceJarTest.java   
@Test
public void shouldOnlyIncludePathBasedSources() {
  SourcePath fileBased = new TestSourcePath("some/path/File.java");
  SourcePath ruleBased = new BuildRuleSourcePath(
      new FakeBuildRule(JavaLibraryDescription.TYPE,
      BuildTargetFactory.newInstance("//cheese:cake")));

  JavaPackageFinder finderStub = createNiceMock(JavaPackageFinder.class);
  expect(finderStub.findJavaPackageFolderForPath((String) anyObject())).andStubReturn("cheese");
  expect(finderStub.findJavaPackageForPath((String) anyObject())).andStubReturn("cheese");

  // No need to verify. It's a stub. I don't care about the interactions.
  EasyMock.replay(finderStub);

  JavaSourceJar rule = new JavaSourceJar(
      new FakeBuildRuleParamsBuilder("//example:target").build(),
      ImmutableSortedSet.of(fileBased, ruleBased));

  assertEquals(ImmutableList.of(fileBased.resolve()), rule.getInputsToCompareToOutput());

  BuildContext buildContext = FakeBuildContext.newBuilder(new FakeProjectFilesystem())
      .setActionGraph(new ActionGraph(new MutableDirectedGraph<BuildRule>()))
      .setJavaPackageFinder(finderStub)
      .build();
  ImmutableList<Step> steps = rule.getBuildSteps(
      buildContext,
      new FakeBuildableContext());

  // There should be a CopyStep per file being copied. Count 'em.
  int copyStepsCount = FluentIterable.from(steps)
      .filter(Predicates.instanceOf(CopyStep.class))
      .size();

  assertEquals(1, copyStepsCount);
}
项目:buck    文件:CopyingFileBundler.java   
@Override
protected void addCopySteps(
    ProjectFilesystem filesystem,
    BuildCellRelativePathFactory buildCellRelativePathFactory,
    ImmutableList.Builder<Step> steps,
    Path relativePath,
    Path absolutePath,
    Path destination) {
  if (destination.getParent() != null) {
    steps.add(MkdirStep.of(buildCellRelativePathFactory.from(destination.getParent())));
  }
  steps.add(CopyStep.forFile(filesystem, absolutePath, destination));
}
项目:buck    文件:AppleBundle.java   
private void copyAnotherCopyOfWatchKitStub(
    ImmutableList.Builder<Step> stepsBuilder, BuildContext context, Path binaryOutputPath) {
  if ((isLegacyWatchApp() || platform.getName().contains("watch"))
      && binary.get() instanceof WriteFile) {
    final Path watchKitStubDir = bundleRoot.resolve("_WatchKitStub");
    stepsBuilder.add(
        MkdirStep.of(
            BuildCellRelativePath.fromCellRelativePath(
                context.getBuildCellRootPath(), getProjectFilesystem(), watchKitStubDir)),
        CopyStep.forFile(
            getProjectFilesystem(), binaryOutputPath, watchKitStubDir.resolve("WK")));
  }
}
项目:buck    文件:MultiarchFile.java   
private void copyLinkMaps(
    BuildableContext buildableContext,
    BuildContext buildContext,
    ImmutableList.Builder<Step> steps) {
  Path linkMapDir = Paths.get(output + "-LinkMap");
  steps.addAll(
      MakeCleanDirectoryStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              buildContext.getBuildCellRootPath(), getProjectFilesystem(), linkMapDir)));

  for (SourcePath thinBinary : thinBinaries) {
    Optional<BuildRule> maybeRule = ruleFinder.getRule(thinBinary);
    if (maybeRule.isPresent()) {
      BuildRule rule = maybeRule.get();
      if (rule instanceof CxxBinary) {
        rule = ((CxxBinary) rule).getLinkRule();
      }
      if (rule instanceof CxxLink
          && !rule.getBuildTarget()
              .getFlavors()
              .contains(LinkerMapMode.NO_LINKER_MAP.getFlavor())) {
        Optional<Path> maybeLinkerMapPath = ((CxxLink) rule).getLinkerMapPath();
        if (maybeLinkerMapPath.isPresent()) {
          Path source = maybeLinkerMapPath.get();
          Path dest = linkMapDir.resolve(source.getFileName());
          steps.add(CopyStep.forFile(getProjectFilesystem(), source, dest));
          buildableContext.recordArtifact(dest);
        }
      }
    }
  }
}
项目:buck    文件:CopyNativeLibraries.java   
private void addStepsForCopyingStrippedNativeLibrariesOrAssets(
    BuildContext context,
    ProjectFilesystem filesystem,
    ImmutableSet<StrippedObjectDescription> strippedNativeLibrariesOrAssets,
    Path destinationRootDir,
    ImmutableList.Builder<Step> steps) {
  for (StrippedObjectDescription strippedObject : strippedNativeLibrariesOrAssets) {
    Optional<String> abiDirectoryComponent =
        getAbiDirectoryComponent(strippedObject.getTargetCpuType());
    Preconditions.checkState(abiDirectoryComponent.isPresent());

    Path destination =
        destinationRootDir
            .resolve(abiDirectoryComponent.get())
            .resolve(strippedObject.getStrippedObjectName());

    steps.add(
        MkdirStep.of(
            BuildCellRelativePath.fromCellRelativePath(
                context.getBuildCellRootPath(),
                getProjectFilesystem(),
                destination.getParent())));
    steps.add(
        CopyStep.forFile(
            filesystem,
            context.getSourcePathResolver().getAbsolutePath(strippedObject.getSourcePath()),
            destination));
  }
}
项目:buck    文件:AndroidBinaryBuildable.java   
private CopyStep createCopyProguardFilesStep(
    SourcePathResolver pathResolver, SourcePath proguardTextFilesPath) {
  return CopyStep.forDirectory(
      getProjectFilesystem(),
      pathResolver.getRelativePath(proguardTextFilesPath),
      getProguardTextFilesPath(),
      CopyStep.DirectoryMode.CONTENTS_ONLY);
}
项目:buck    文件:ExportFile.java   
@Override
public ImmutableList<Step> getBuildSteps(
    BuildContext context, BuildableContext buildableContext) {
  SourcePathResolver resolver = context.getSourcePathResolver();

  // This file is copied rather than symlinked so that when it is included in an archive zip and
  // unpacked on another machine, it is an ordinary file in both scenarios.
  ImmutableList.Builder<Step> builder = ImmutableList.builder();
  if (mode == ExportFileDescription.Mode.COPY) {
    Path out = getCopiedPath();
    builder.addAll(
        MakeCleanDirectoryStep.of(
            BuildCellRelativePath.fromCellRelativePath(
                context.getBuildCellRootPath(), getProjectFilesystem(), out.getParent())));
    if (resolver.getFilesystem(src).isDirectory(resolver.getRelativePath(src))) {
      builder.add(
          CopyStep.forDirectory(
              getProjectFilesystem(),
              resolver.getAbsolutePath(src),
              out,
              CopyStep.DirectoryMode.CONTENTS_ONLY));
    } else {
      builder.add(CopyStep.forFile(getProjectFilesystem(), resolver.getAbsolutePath(src), out));
    }
    buildableContext.recordArtifact(out);
  }

  return builder.build();
}
项目:buck    文件:RemoteFile.java   
@Override
public ImmutableList<Step> getBuildSteps(
    BuildContext context, BuildableContext buildableContext) {
  ImmutableList.Builder<Step> steps = ImmutableList.builder();
  Path tempFile =
      BuildTargets.getScratchPath(
          getProjectFilesystem(), getBuildTarget(), "%s/" + output.getFileName());

  steps.addAll(
      MakeCleanDirectoryStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              context.getBuildCellRootPath(), getProjectFilesystem(), tempFile.getParent())));
  steps.add(
      new DownloadStep(
          getProjectFilesystem(), downloader, uri, ImmutableList.of(), sha1, tempFile));

  steps.addAll(
      MakeCleanDirectoryStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              context.getBuildCellRootPath(), getProjectFilesystem(), output.getParent())));
  if (type == Type.EXPLODED_ZIP) {

    steps.addAll(
        MakeCleanDirectoryStep.of(
            BuildCellRelativePath.fromCellRelativePath(
                context.getBuildCellRootPath(), getProjectFilesystem(), output)));
    steps.add(new UnzipStep(getProjectFilesystem(), tempFile, output, Optional.empty()));
  } else {
    steps.add(CopyStep.forFile(getProjectFilesystem(), tempFile, output));
  }
  if (type == Type.EXECUTABLE) {
    steps.add(new MakeExecutableStep(getProjectFilesystem(), output));
  }

  buildableContext.recordArtifact(output);

  return steps.build();
}
项目:buck    文件:HaskellHaddockRule.java   
@Override
public ImmutableList<Step> getBuildSteps(
    BuildContext context, BuildableContext buildableContext) {

  SourcePathResolver resolver = context.getSourcePathResolver();
  String name = getBuildTarget().getShortName();
  Path dir = getOutputDir();

  LOG.info(name);

  ImmutableList.Builder<Step> steps = ImmutableList.builder();

  steps.addAll(
      MakeCleanDirectoryStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              context.getBuildCellRootPath(), getProjectFilesystem(), dir)));
  steps.add(new HaddockStep(getBuildTarget(), getProjectFilesystem().getRootPath(), context));

  // Copy the generated data from dependencies into our output directory
  for (SourcePath odir : outputDirs) {
    steps.add(
        CopyStep.forDirectory(
            getProjectFilesystem(),
            resolver.getRelativePath(odir),
            dir,
            CopyStep.DirectoryMode.DIRECTORY_AND_CONTENTS));
  }

  buildableContext.recordArtifact(dir);
  return steps.build();
}
项目:buck    文件:JavaSourceJarTest.java   
@Test
public void shouldOnlyIncludePathBasedSources() {
  SourcePath fileBased = FakeSourcePath.of("some/path/File.java");
  SourcePath ruleBased =
      DefaultBuildTargetSourcePath.of(BuildTargetFactory.newInstance("//cheese:cake"));

  JavaPackageFinder finderStub = createNiceMock(JavaPackageFinder.class);
  expect(finderStub.findJavaPackageFolder((Path) anyObject())).andStubReturn(Paths.get("cheese"));
  expect(finderStub.findJavaPackage((Path) anyObject())).andStubReturn("cheese");

  // No need to verify. It's a stub. I don't care about the interactions.
  EasyMock.replay(finderStub);

  BuildTarget buildTarget = BuildTargetFactory.newInstance("//example:target");
  JavaSourceJar rule =
      new JavaSourceJar(
          buildTarget,
          new FakeProjectFilesystem(),
          TestBuildRuleParams.create(),
          ImmutableSortedSet.of(fileBased, ruleBased),
          Optional.empty());

  BuildContext buildContext =
      FakeBuildContext.withSourcePathResolver(
              DefaultSourcePathResolver.from(
                  new SourcePathRuleFinder(
                      new SingleThreadedBuildRuleResolver(
                          TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))))
          .withJavaPackageFinder(finderStub);
  ImmutableList<Step> steps = rule.getBuildSteps(buildContext, new FakeBuildableContext());

  // There should be a CopyStep per file being copied. Count 'em.
  int copyStepsCount = FluentIterable.from(steps).filter(CopyStep.class::isInstance).size();

  assertEquals(1, copyStepsCount);
}
项目:buck    文件:JavaSourceJar.java   
@Override
public ImmutableList<Step> getBuildSteps(
    BuildContext context, BuildableContext buildableContext) {
  JavaPackageFinder packageFinder = context.getJavaPackageFinder();

  ImmutableList.Builder<Step> steps = ImmutableList.builder();

  steps.add(
      MkdirStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              context.getBuildCellRootPath(), getProjectFilesystem(), output.getParent())));
  steps.add(
      RmStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              context.getBuildCellRootPath(), getProjectFilesystem(), output)));

  steps.addAll(
      MakeCleanDirectoryStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              context.getBuildCellRootPath(), getProjectFilesystem(), temp)));

  Set<Path> seenPackages = new HashSet<>();

  // We only want to consider raw source files, since the java package finder doesn't have the
  // smarts to read the "package" line from a source file.

  for (Path source : context.getSourcePathResolver().filterInputsToCompareToOutput(sources)) {
    Path packageFolder = packageFinder.findJavaPackageFolder(source);
    Path packageDir = temp.resolve(packageFolder);
    if (seenPackages.add(packageDir)) {
      steps.add(
          MkdirStep.of(
              BuildCellRelativePath.fromCellRelativePath(
                  context.getBuildCellRootPath(), getProjectFilesystem(), packageDir)));
    }
    steps.add(
        CopyStep.forFile(
            getProjectFilesystem(), source, packageDir.resolve(source.getFileName())));
  }
  steps.add(
      new ZipStep(
          getProjectFilesystem(),
          output,
          ImmutableSet.of(),
          /* junk paths */ false,
          ZipCompressionLevel.DEFAULT,
          temp));

  buildableContext.recordArtifact(output);

  return steps.build();
}
项目:buck    文件:PrebuiltJar.java   
@Override
public ImmutableList<Step> getBuildSteps(
    BuildContext context, final BuildableContext buildableContext) {
  ImmutableList.Builder<Step> steps = ImmutableList.builder();

  SourcePathResolver resolver = context.getSourcePathResolver();

  // Create a copy of the JAR in case it was generated by another rule.
  Path resolvedBinaryJar = resolver.getAbsolutePath(binaryJar);
  Path resolvedCopiedBinaryJar = getProjectFilesystem().resolve(copiedBinaryJar);
  Preconditions.checkState(
      !resolvedBinaryJar.equals(resolvedCopiedBinaryJar),
      "%s: source (%s) can't be equal to destination (%s) when copying prebuilt JAR.",
      getBuildTarget().getFullyQualifiedName(),
      resolvedBinaryJar,
      copiedBinaryJar);

  if (resolver.getFilesystem(binaryJar).isDirectory(resolvedBinaryJar)) {
    steps.addAll(
        MakeCleanDirectoryStep.of(
            BuildCellRelativePath.fromCellRelativePath(
                context.getBuildCellRootPath(), getProjectFilesystem(), copiedBinaryJar)));
    steps.add(
        CopyStep.forDirectory(
            getProjectFilesystem(),
            resolvedBinaryJar,
            copiedBinaryJar,
            CopyStep.DirectoryMode.CONTENTS_ONLY));
  } else {
    if (!MorePaths.getFileExtension(copiedBinaryJar.getFileName())
        .equals(MorePaths.getFileExtension(resolvedBinaryJar))) {
      context
          .getEventBus()
          .post(
              ConsoleEvent.warning(
                  "Assuming %s is a JAR and renaming to %s in %s. "
                      + "Change the extension of the binary_jar to '.jar' to remove this warning.",
                  resolvedBinaryJar.getFileName(),
                  copiedBinaryJar.getFileName(),
                  getBuildTarget().getFullyQualifiedName()));
    }

    steps.add(
        MkdirStep.of(
            BuildCellRelativePath.fromCellRelativePath(
                context.getBuildCellRootPath(),
                getProjectFilesystem(),
                copiedBinaryJar.getParent())));
    steps.add(CopyStep.forFile(getProjectFilesystem(), resolvedBinaryJar, copiedBinaryJar));
  }
  buildableContext.recordArtifact(copiedBinaryJar);

  JavaLibraryRules.addAccumulateClassNamesStep(
      getBuildTarget(),
      getProjectFilesystem(),
      getSourcePathToOutput(),
      buildableContext,
      context,
      steps);

  return steps.build();
}
项目:buck    文件:AppleBundle.java   
private void addResourceProcessingSteps(
    SourcePathResolver resolver,
    Path sourcePath,
    Path destinationPath,
    ImmutableList.Builder<Step> stepsBuilder) {
  String sourcePathExtension =
      Files.getFileExtension(sourcePath.toString()).toLowerCase(Locale.US);
  switch (sourcePathExtension) {
    case "plist":
    case "stringsdict":
      LOG.debug("Converting plist %s to binary plist %s", sourcePath, destinationPath);
      stepsBuilder.add(
          new PlistProcessStep(
              getProjectFilesystem(),
              sourcePath,
              Optional.empty(),
              destinationPath,
              ImmutableMap.of(),
              ImmutableMap.of(),
              PlistProcessStep.OutputFormat.BINARY));
      break;
    case "storyboard":
      addStoryboardProcessingSteps(resolver, sourcePath, destinationPath, stepsBuilder);
      break;
    case "xib":
      String compiledNibFilename =
          Files.getNameWithoutExtension(destinationPath.toString()) + ".nib";
      Path compiledNibPath = destinationPath.getParent().resolve(compiledNibFilename);
      LOG.debug("Compiling XIB %s to NIB %s", sourcePath, destinationPath);
      stepsBuilder.add(
          new IbtoolStep(
              getBuildTarget(),
              getProjectFilesystem(),
              ibtool.getEnvironment(resolver),
              ibtool.getCommandPrefix(resolver),
              ibtoolModuleParams,
              ImmutableList.of("--compile"),
              sourcePath,
              compiledNibPath));
      break;
    default:
      stepsBuilder.add(CopyStep.forFile(getProjectFilesystem(), sourcePath, destinationPath));
      break;
  }
}
项目:buck    文件:BuiltinApplePackage.java   
@Override
public ImmutableList<Step> getBuildSteps(
    BuildContext context, BuildableContext buildableContext) {
  ImmutableList.Builder<Step> commands = ImmutableList.builder();
  // Remove the output .ipa file if it exists already
  commands.add(
      RmStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              context.getBuildCellRootPath(), getProjectFilesystem(), pathToOutputFile)));

  // Create temp folder to store the files going to be zipped

  commands.addAll(
      MakeCleanDirectoryStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              context.getBuildCellRootPath(), getProjectFilesystem(), temp)));

  Path payloadDir = temp.resolve("Payload");
  commands.add(
      MkdirStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              context.getBuildCellRootPath(), getProjectFilesystem(), payloadDir)));

  // Recursively copy the .app directory into the Payload folder
  Path bundleOutputPath =
      context
          .getSourcePathResolver()
          .getRelativePath(Preconditions.checkNotNull(bundle.getSourcePathToOutput()));

  appendAdditionalAppleWatchSteps(context, commands);

  commands.add(
      CopyStep.forDirectory(
          getProjectFilesystem(),
          bundleOutputPath,
          payloadDir,
          CopyStep.DirectoryMode.DIRECTORY_AND_CONTENTS));

  appendAdditionalSwiftSteps(context.getSourcePathResolver(), commands);

  // do the zipping
  commands.add(
      MkdirStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              context.getBuildCellRootPath(),
              getProjectFilesystem(),
              pathToOutputFile.getParent())));

  commands.add(
      new ZipStep(
          getProjectFilesystem(),
          pathToOutputFile,
          ImmutableSet.of(),
          false,
          compressionLevel,
          temp));

  buildableContext.recordArtifact(
      context.getSourcePathResolver().getRelativePath(getSourcePathToOutput()));

  return commands.build();
}
项目:buck    文件:JsBundleAndroid.java   
@Override
public ImmutableList<Step> getBuildSteps(
    BuildContext context, BuildableContext buildableContext) {
  final SourcePathResolver sourcePathResolver = context.getSourcePathResolver();

  buildableContext.recordArtifact(sourcePathResolver.getRelativePath(getSourcePathToOutput()));
  buildableContext.recordArtifact(sourcePathResolver.getRelativePath(getSourcePathToSourceMap()));
  buildableContext.recordArtifact(sourcePathResolver.getRelativePath(getSourcePathToResources()));
  buildableContext.recordArtifact(sourcePathResolver.getRelativePath(getSourcePathToMisc()));

  Path jsDir = sourcePathResolver.getRelativePath(getSourcePathToOutput());
  Path resourcesDir = sourcePathResolver.getRelativePath(getSourcePathToResources());
  Path sourceMapFile = sourcePathResolver.getRelativePath(getSourcePathToSourceMap());
  Path miscDirPath = sourcePathResolver.getRelativePath(getSourcePathToMisc());

  return ImmutableList.<Step>builder()
      .addAll(
          MakeCleanDirectoryStep.of(
              BuildCellRelativePath.fromCellRelativePath(
                  context.getBuildCellRootPath(),
                  getProjectFilesystem(),
                  sourcePathResolver.getRelativePath(
                      JsUtil.relativeToOutputRoot(
                          getBuildTarget(), getProjectFilesystem(), "")))))
      .add(
          MkdirStep.of(
              BuildCellRelativePath.fromCellRelativePath(
                  context.getBuildCellRootPath(), getProjectFilesystem(), jsDir.getParent())),
          MkdirStep.of(
              BuildCellRelativePath.fromCellRelativePath(
                  context.getBuildCellRootPath(),
                  getProjectFilesystem(),
                  resourcesDir.getParent())),
          MkdirStep.of(
              BuildCellRelativePath.fromCellRelativePath(
                  context.getBuildCellRootPath(),
                  getProjectFilesystem(),
                  sourceMapFile.getParent())),
          MkdirStep.of(
              BuildCellRelativePath.fromCellRelativePath(
                  context.getBuildCellRootPath(),
                  getProjectFilesystem(),
                  miscDirPath.getParent())),
          CopyStep.forDirectory(
              getProjectFilesystem(),
              sourcePathResolver.getAbsolutePath(delegate.getSourcePathToOutput()),
              jsDir.getParent(),
              CopyStep.DirectoryMode.DIRECTORY_AND_CONTENTS),
          CopyStep.forDirectory(
              getProjectFilesystem(),
              sourcePathResolver.getAbsolutePath(delegate.getSourcePathToResources()),
              resourcesDir.getParent(),
              CopyStep.DirectoryMode.DIRECTORY_AND_CONTENTS),
          CopyStep.forDirectory(
              getProjectFilesystem(),
              sourcePathResolver.getAbsolutePath(delegate.getSourcePathToSourceMap()),
              sourceMapFile.getParent(),
              CopyStep.DirectoryMode.DIRECTORY_AND_CONTENTS),
          CopyStep.forDirectory(
              getProjectFilesystem(),
              sourcePathResolver.getAbsolutePath(delegate.getSourcePathToMisc()),
              miscDirPath.getParent(),
              CopyStep.DirectoryMode.DIRECTORY_AND_CONTENTS))
      .build();
}
项目:buck    文件:IntraDexReorderStep.java   
private int reorderEntry(
    Path inputPath, boolean isPrimaryDex, ImmutableList.Builder<Step> steps) {

  if (!isPrimaryDex) {
    String tmpname = "dex-tmp-" + inputPath.getFileName().toString() + "-%s";
    Path temp = BuildTargets.getScratchPath(filesystem, buildTarget, tmpname);
    // Create tmp directory if necessary
    steps.addAll(
        MakeCleanDirectoryStep.of(
            BuildCellRelativePath.fromCellRelativePath(
                context.getBuildCellRootPath(), filesystem, temp)));
    // un-zip
    steps.add(new UnzipStep(filesystem, inputPath, temp, Optional.empty()));
    // run reorder tool
    steps.add(
        new DefaultShellStep(
            target,
            filesystem.getRootPath(),
            ImmutableList.of(
                reorderTool.toString(),
                reorderDataFile.toString(),
                temp.resolve("classes.dex").toString())));
    Path outputPath = Paths.get(inputPath.toString().replace(inputSubDir, outputSubDir));
    // re-zip
    steps.add(
        new ZipStep(
            filesystem,
            outputPath,
            /* paths */ ImmutableSet.of(),
            /* junkPaths */ false,
            ZipCompressionLevel.MAX,
            temp));
  } else {
    // copy dex
    // apply reorder directly on dex
    steps.add(CopyStep.forFile(filesystem, inputPrimaryDexPath, outputPrimaryDexPath));
    steps.add(
        new DefaultShellStep(
            target,
            filesystem.getRootPath(),
            ImmutableList.of(
                reorderTool.toString(),
                reorderDataFile.toString(),
                outputPrimaryDexPath.toString())));
  }
  return 0;
}
项目:buck    文件:AndroidBinaryBuildable.java   
private void getStepsForNativeAssets(
    BuildContext context,
    ImmutableList.Builder<Step> steps,
    final Path libSubdirectory,
    final String metadataFilename,
    final APKModule module) {

  steps.addAll(
      MakeCleanDirectoryStep.of(
          BuildCellRelativePath.fromCellRelativePath(
              context.getBuildCellRootPath(), getProjectFilesystem(), libSubdirectory)));

  // Input asset libraries are sorted in descending filesize order.
  final ImmutableSortedSet.Builder<Path> inputAssetLibrariesBuilder =
      ImmutableSortedSet.orderedBy(
          (libPath1, libPath2) -> {
            try {
              ProjectFilesystem filesystem = getProjectFilesystem();
              int filesizeResult =
                  -Long.compare(
                      filesystem.getFileSize(libPath1), filesystem.getFileSize(libPath2));
              int pathnameResult = libPath1.compareTo(libPath2);
              return filesizeResult != 0 ? filesizeResult : pathnameResult;
            } catch (IOException e) {
              return 0;
            }
          });

  if (packageAssetLibraries || !module.isRootModule()) {
    // TODO(cjhopman): This block should probably all be handled by CopyNativeLibraries.
    // TODO(cjhopman): Why is this packaging native libs as assets even when native exopackage is
    // enabled?
    if (nativeFilesInfo.nativeLibsAssetsDirs.isPresent()
        && nativeFilesInfo.nativeLibsAssetsDirs.get().containsKey(module)) {
      // Copy in cxx libraries marked as assets. Filtering and renaming was already done
      // in CopyNativeLibraries.getBuildSteps().
      Path cxxNativeLibsSrc =
          context
              .getSourcePathResolver()
              .getRelativePath(nativeFilesInfo.nativeLibsAssetsDirs.get().get(module));
      steps.add(
          CopyStep.forDirectory(
              getProjectFilesystem(),
              cxxNativeLibsSrc,
              libSubdirectory,
              CopyStep.DirectoryMode.CONTENTS_ONLY));
    }

    // Step that populates a list of libraries and writes a metadata.txt to decompress.
    steps.add(
        createAssetLibrariesMetadataStep(
            libSubdirectory, metadataFilename, module, inputAssetLibrariesBuilder));
  }

  if (compressAssetLibraries || !module.isRootModule()) {
    final ImmutableList.Builder<Path> outputAssetLibrariesBuilder = ImmutableList.builder();
    steps.add(
        createRenameAssetLibrariesStep(
            module, inputAssetLibrariesBuilder, outputAssetLibrariesBuilder));
    // Concat and xz compress.
    Path libOutputBlob = libSubdirectory.resolve("libraries.blob");
    steps.add(new ConcatStep(getProjectFilesystem(), outputAssetLibrariesBuilder, libOutputBlob));
    int compressionLevel = xzCompressionLevel.orElse(XzStep.DEFAULT_COMPRESSION_LEVEL).intValue();
    steps.add(
        new XzStep(
            getProjectFilesystem(),
            libOutputBlob,
            libSubdirectory.resolve(SOLID_COMPRESSED_ASSET_LIBRARY_FILENAME),
            compressionLevel));
  }
}