Search in sources :

Example 11 with WriteFileStep

use of com.facebook.buck.step.fs.WriteFileStep in project buck by facebook.

the class JarFattener method writeFatJarInfo.

/**
   * @return a {@link Step} that generates the fat jar info resource.
   */
private Step writeFatJarInfo(Path destination, final ImmutableMap<String, String> nativeLibraries) {
    ByteSource source = new ByteSource() {

        @Override
        public InputStream openStream() throws IOException {
            FatJar fatJar = new FatJar(FAT_JAR_INNER_JAR, nativeLibraries);
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            try {
                fatJar.store(bytes);
            } catch (JAXBException e) {
                throw new RuntimeException(e);
            }
            return new ByteArrayInputStream(bytes.toByteArray());
        }
    };
    return new WriteFileStep(getProjectFilesystem(), source, destination, /* executable */
    false);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) JAXBException(javax.xml.bind.JAXBException) ByteSource(com.google.common.io.ByteSource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep)

Example 12 with WriteFileStep

use of com.facebook.buck.step.fs.WriteFileStep in project buck by facebook.

the class HaskellPackageRule method getWriteRegistrationFileStep.

private WriteFileStep getWriteRegistrationFileStep(SourcePathResolver resolver, Path registrationFile, Path packageDb) {
    Map<String, String> entries = new LinkedHashMap<>();
    entries.put("name", packageInfo.getName());
    entries.put("version", packageInfo.getVersion());
    entries.put("id", packageInfo.getIdentifier());
    if (haskellVersion.getMajorVersion() >= 8) {
        entries.put("key", packageInfo.getIdentifier());
    }
    entries.put("exposed", "True");
    entries.put("exposed-modules", Joiner.on(' ').join(modules));
    Path pkgRoot = getProjectFilesystem().getPath("${pkgroot}");
    if (!modules.isEmpty()) {
        List<String> importDirs = new ArrayList<>();
        for (SourcePath interfaceDir : interfaces) {
            Path relInterfaceDir = pkgRoot.resolve(packageDb.getParent().relativize(resolver.getRelativePath(interfaceDir)));
            importDirs.add('"' + relInterfaceDir.toString() + '"');
        }
        entries.put("import-dirs", Joiner.on(", ").join(importDirs));
    }
    List<String> libDirs = new ArrayList<>();
    List<String> libs = new ArrayList<>();
    for (SourcePath library : libraries) {
        Path relLibPath = pkgRoot.resolve(packageDb.getParent().relativize(resolver.getRelativePath(library)));
        libDirs.add('"' + relLibPath.getParent().toString() + '"');
        libs.add(MorePaths.stripPathPrefixAndExtension(relLibPath.getFileName(), "lib"));
    }
    entries.put("library-dirs", Joiner.on(", ").join(libDirs));
    // Use extra libraries here, so GHC won't try to find libraries with any extra suffices
    // (e.g. lib<name>-ghc7.10.3.dylib).
    entries.put("extra-libraries", Joiner.on(", ").join(libs));
    entries.put("depends", Joiner.on(", ").join(depPackages.keySet()));
    return new WriteFileStep(getProjectFilesystem(), entries.entrySet().stream().map(input -> input.getKey() + ": " + input.getValue()).collect(Collectors.joining(System.lineSeparator())), registrationFile, /* executable */
    false);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ArrayList(java.util.ArrayList) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

WriteFileStep (com.facebook.buck.step.fs.WriteFileStep)12 Path (java.nio.file.Path)9 SourcePath (com.facebook.buck.rules.SourcePath)7 MkdirStep (com.facebook.buck.step.fs.MkdirStep)7 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)6 ImmutableList (com.google.common.collect.ImmutableList)6 Step (com.facebook.buck.step.Step)5 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)5 RmStep (com.facebook.buck.step.fs.RmStep)3 AbstractBuildRule (com.facebook.buck.rules.AbstractBuildRule)2 PathSourcePath (com.facebook.buck.rules.PathSourcePath)2 ExecutionContext (com.facebook.buck.step.ExecutionContext)2 CopyStep (com.facebook.buck.step.fs.CopyStep)2 HumanReadableException (com.facebook.buck.util.HumanReadableException)2 IOException (java.io.IOException)2 NSDictionary (com.dd.plist.NSDictionary)1 NSString (com.dd.plist.NSString)1 MiniAapt (com.facebook.buck.android.aapt.MiniAapt)1 WriteFile (com.facebook.buck.file.WriteFile)1 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1