Search in sources :

Example 6 with PathSourcePath

use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.

the class AbstractPrebuiltCxxLibraryGroupDescription method getSharedLinkArgs.

/**
   * @return the link args formed from the user-provided shared link line after resolving library
   *         macro references.
   */
private Iterable<Arg> getSharedLinkArgs(BuildTarget target, ImmutableMap<String, SourcePath> libs, ImmutableList<String> args) {
    ImmutableList.Builder<Arg> builder = ImmutableList.builder();
    for (String arg : args) {
        Optional<Pair<String, String>> libRef = getLibRef(ImmutableSet.of(LIB_MACRO, REL_LIB_MACRO), arg);
        if (libRef.isPresent()) {
            SourcePath lib = libs.get(libRef.get().getSecond());
            if (lib == null) {
                throw new HumanReadableException("%s: library \"%s\" (in \"%s\") must refer to keys in the `sharedLibs` parameter", target, libRef.get().getSecond(), arg);
            }
            Arg libArg;
            if (libRef.get().getFirst().equals(LIB_MACRO)) {
                libArg = SourcePathArg.of(lib);
            } else if (libRef.get().getFirst().equals(REL_LIB_MACRO)) {
                if (!(lib instanceof PathSourcePath)) {
                    throw new HumanReadableException("%s: can only link prebuilt DSOs without sonames", target);
                }
                libArg = new RelativeLinkArg((PathSourcePath) lib);
            } else {
                throw new IllegalStateException();
            }
            builder.add(libArg);
        } else {
            builder.add(StringArg.of(arg));
        }
    }
    return builder.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) ImmutableList(com.google.common.collect.ImmutableList) HumanReadableException(com.facebook.buck.util.HumanReadableException) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) StringArg(com.facebook.buck.rules.args.StringArg) Arg(com.facebook.buck.rules.args.Arg) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Pair(com.facebook.buck.model.Pair)

Example 7 with PathSourcePath

use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.

the class Project method addSourceFolders.

private boolean addSourceFolders(SerializableModule module, @Nullable BuildRule buildRule, @Nullable ImmutableList<SourceRoot> sourceRoots, boolean isTestSource) {
    if (buildRule == null || sourceRoots == null) {
        return false;
    }
    if (buildRule.getProperties().is(PACKAGING) && sourceRoots.isEmpty()) {
        return false;
    }
    JavaLibrary javaLibrary;
    if (buildRule instanceof JavaLibrary) {
        javaLibrary = (JavaLibrary) buildRule;
        Path basePath = buildRule.getBuildTarget().getBasePath();
        for (SourcePath path : javaLibrary.getSources()) {
            if (!(path instanceof PathSourcePath)) {
                Path pathToTarget = resolver.getRelativePath(path);
                Path relativePath = basePath.relativize(Paths.get("")).resolve(pathToTarget).getParent();
                String url = "file://$MODULE_DIR$/" + MorePaths.pathWithUnixSeparators(relativePath);
                SerializableModule.SourceFolder sourceFolder = new SerializableModule.SourceFolder(url, isTestSource, "");
                module.sourceFolders.add(sourceFolder);
            }
        }
    }
    if (sourceRoots.isEmpty()) {
        // When there is a src_target, but no src_roots were specified, then the current directory is
        // treated as the SourceRoot. This is the common case when a project contains one folder of
        // Java source code with a build file for each Java package. For example, if the project's
        // only source folder were named "java/" and a build file in java/com/example/base/ contained
        // the an extremely simple set of build rules:
        //
        // java_library(
        //   name = 'base',
        //   srcs = glob(['*.java']),
        // }
        //
        // project_config(
        //   src_target = ':base',
        // )
        //
        // then the corresponding .iml file (in the same directory) should contain:
        //
        // <content url="file://$MODULE_DIR$">
        //   <sourceFolder url="file://$MODULE_DIR$"
        //                 isTestSource="false"
        //                 packagePrefix="com.example.base" />
        //   <sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" />
        //
        //   <!-- It will have an <excludeFolder> for every "subpackage" of com.example.base. -->
        //   <excludeFolder url="file://$MODULE_DIR$/util" />
        // </content>
        //
        // Note to prevent the <excludeFolder> elements from being included, the project_config()
        // rule should be:
        //
        // project_config(
        //   src_target = ':base',
        //   src_root_includes_subdirectories = True,
        // )
        //
        // Because developers who organize their code this way will have many build files, the default
        // values of project_config() assume this approach to help minimize the tedium in writing all
        // of those project_config() rules.
        String url = "file://$MODULE_DIR$";
        String packagePrefix = javaPackageFinder.findJavaPackage(Preconditions.checkNotNull(module.pathToImlFile));
        SerializableModule.SourceFolder sourceFolder = new SerializableModule.SourceFolder(url, isTestSource, packagePrefix);
        module.sourceFolders.add(sourceFolder);
    } else {
        for (SourceRoot sourceRoot : sourceRoots) {
            SerializableModule.SourceFolder sourceFolder = new SerializableModule.SourceFolder("file://$MODULE_DIR$/" + sourceRoot.getName(), isTestSource);
            module.sourceFolders.add(sourceFolder);
        }
    }
    // Include <excludeFolder> elements, as appropriate.
    for (Path relativePath : this.buildFileTree.getChildPaths(buildRule.getBuildTarget())) {
        String excludeFolderUrl = "file://$MODULE_DIR$/" + relativePath;
        SerializableModule.SourceFolder excludeFolder = new SerializableModule.SourceFolder(excludeFolderUrl, /* isTestSource */
        false);
        module.excludeFolders.add(excludeFolder);
    }
    return true;
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourceRoot(com.facebook.buck.rules.SourceRoot)

Example 8 with PathSourcePath

use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.

the class AbstractOcamlBuildContext method getLexOutput.

protected FluentIterable<SourcePath> getLexOutput(Iterable<SourcePath> lexInputs) {
    return FluentIterable.from(lexInputs).transform(lexInput -> {
        Path fileName = getSourcePathResolver().getAbsolutePath(lexInput).getFileName();
        Path out = getGeneratedSourceDir().resolve(fileName.toString().replaceFirst(OcamlCompilables.OCAML_MLL_REGEX, OcamlCompilables.OCAML_ML));
        return new PathSourcePath(getProjectFilesystem(), out);
    });
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath)

Example 9 with PathSourcePath

use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.

the class ShTestDescription method createBuildRule.

@Override
public <A extends Arg> ShTest createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    Function<String, com.facebook.buck.rules.args.Arg> toArg = MacroArg.toMacroArgFunction(MACRO_HANDLER, params.getBuildTarget(), params.getCellRoots(), resolver);
    final ImmutableList<com.facebook.buck.rules.args.Arg> testArgs = args.args.stream().map(toArg::apply).collect(MoreCollectors.toImmutableList());
    final ImmutableMap<String, com.facebook.buck.rules.args.Arg> testEnv = ImmutableMap.copyOf(Maps.transformValues(args.env, toArg));
    return new ShTest(params.copyAppendingExtraDeps(() -> FluentIterable.from(testArgs).append(testEnv.values()).transformAndConcat(arg -> arg.getDeps(ruleFinder))), ruleFinder, args.test, testArgs, testEnv, FluentIterable.from(args.resources).transform(p -> new PathSourcePath(params.getProjectFilesystem(), p)).toSortedSet(Ordering.natural()), args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), args.runTestSeparately.orElse(false), args.labels, args.contacts);
}
Also used : Optional(java.util.Optional) MacroArg(com.facebook.buck.rules.args.MacroArg) AbstractDescriptionArg(com.facebook.buck.rules.AbstractDescriptionArg) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder)

Example 10 with PathSourcePath

use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.

the class ExportFileDescription method createBuildRule.

@Override
public <A extends Arg> ExportFile createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) {
    BuildTarget target = params.getBuildTarget();
    Mode mode = args.mode.orElse(Mode.COPY);
    String name;
    if (args.out.isPresent()) {
        if (mode == ExportFileDescription.Mode.REFERENCE) {
            throw new HumanReadableException("%s: must not set `out` for `export_file` when using `REFERENCE` mode", params.getBuildTarget());
        }
        name = args.out.get();
    } else {
        name = target.getShortNameAndFlavorPostfix();
    }
    SourcePath src;
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    if (args.src.isPresent()) {
        if (mode == ExportFileDescription.Mode.REFERENCE && !pathResolver.getFilesystem(args.src.get()).equals(params.getProjectFilesystem())) {
            throw new HumanReadableException("%s: must use `COPY` mode for `export_file` when source (%s) uses a different cell", target, args.src.get());
        }
        src = args.src.get();
    } else {
        src = new PathSourcePath(params.getProjectFilesystem(), target.getBasePath().resolve(target.getShortNameAndFlavorPostfix()));
    }
    return new ExportFile(params, ruleFinder, pathResolver, name, mode, src);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Aggregations

PathSourcePath (com.facebook.buck.rules.PathSourcePath)114 Test (org.junit.Test)82 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)69 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)68 SourcePath (com.facebook.buck.rules.SourcePath)65 Path (java.nio.file.Path)63 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)60 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)58 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)56 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)52 BuildTarget (com.facebook.buck.model.BuildTarget)51 TargetGraph (com.facebook.buck.rules.TargetGraph)37 BuildRule (com.facebook.buck.rules.BuildRule)26 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)23 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)21 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)16 RuleKey (com.facebook.buck.rules.RuleKey)15 DefaultFileHashCache (com.facebook.buck.util.cache.DefaultFileHashCache)15 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)14 ImmutableList (com.google.common.collect.ImmutableList)14