Search in sources :

Example 6 with CellPathResolver

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

the class BuildTargetPatternParserTest method visibilityCanContainCrossCellReference.

@Test
public void visibilityCanContainCrossCellReference() {
    BuildTargetPatternParser<BuildTargetPattern> buildTargetPatternParser = BuildTargetPatternParser.forVisibilityArgument();
    final ProjectFilesystem filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
    CellPathResolver cellNames = new FakeCellPathResolver(ImmutableMap.of("other", filesystem.getRootPath()));
    assertEquals(new SingletonBuildTargetPattern(filesystem.getRootPath(), "//:something"), buildTargetPatternParser.parse(cellNames, "other//:something"));
    assertEquals(new SubdirectoryBuildTargetPattern(filesystem.getRootPath(), filesystem.getPath("sub")), buildTargetPatternParser.parse(cellNames, "other//sub/..."));
}
Also used : SubdirectoryBuildTargetPattern(com.facebook.buck.model.SubdirectoryBuildTargetPattern) ImmediateDirectoryBuildTargetPattern(com.facebook.buck.model.ImmediateDirectoryBuildTargetPattern) BuildTargetPattern(com.facebook.buck.model.BuildTargetPattern) SingletonBuildTargetPattern(com.facebook.buck.model.SingletonBuildTargetPattern) SingletonBuildTargetPattern(com.facebook.buck.model.SingletonBuildTargetPattern) FakeCellPathResolver(com.facebook.buck.rules.FakeCellPathResolver) SubdirectoryBuildTargetPattern(com.facebook.buck.model.SubdirectoryBuildTargetPattern) CellPathResolver(com.facebook.buck.rules.CellPathResolver) FakeCellPathResolver(com.facebook.buck.rules.FakeCellPathResolver) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 7 with CellPathResolver

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

the class PrebuiltCxxLibraryDescriptionTest method locationMacro.

@Test
public void locationMacro() throws NoSuchBuildTargetException {
    ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
    CellPathResolver cellRoots = TestCellBuilder.createCellRoots(filesystem);
    Optional<String> libName = Optional.of("test");
    Optional<String> libDir = Optional.of("$(location //other:gen_lib)/");
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    BuildTarget genTarget = BuildTargetFactory.newInstance("//other:gen_lib");
    GenruleBuilder genruleBuilder = GenruleBuilder.newGenruleBuilder(genTarget).setOut("lib_dir");
    BuildRule genRule = genruleBuilder.build(resolver);
    CxxPlatform platform = CxxPlatformUtils.DEFAULT_PLATFORM.withFlavor(InternalFlavor.of("PLATFORM1"));
    Path path = pathResolver.getAbsolutePath(Preconditions.checkNotNull(genRule.getSourcePathToOutput()));
    final SourcePath staticLibraryPath = PrebuiltCxxLibraryDescription.getStaticLibraryPath(TARGET, cellRoots, filesystem, resolver, platform, Optional.empty(), libDir, libName);
    assertEquals(TARGET.getBasePath().resolve(String.format("%s/libtest.a", path)), pathResolver.getAbsolutePath(staticLibraryPath));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) CellPathResolver(com.facebook.buck.rules.CellPathResolver) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 8 with CellPathResolver

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

the class JavacExecutionContextSerializer method deserialize.

@SuppressWarnings("unchecked")
public static JavacExecutionContext deserialize(Map<String, Object> data, JavacEventSink eventSink, PrintStream stdErr, ClassLoaderCache classLoaderCache, ObjectMapper objectMapper, Console console) {
    Verbosity verbosity = Verbosity.valueOf((String) Preconditions.checkNotNull(data.get(VERBOSITY)));
    CellPathResolver cellPathResolver = CellPathResolverSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(CELL_PATH_RESOLVER)));
    JavaPackageFinder javaPackageFinder = JavaPackageFinderSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(JAVA_PACKAGE_FINDER)));
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(Paths.get((String) Preconditions.checkNotNull(data.get(PROJECT_FILE_SYSTEM_ROOT))));
    ClassUsageFileWriter classUsageFileWriter = ClassUsageFileWriterSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(CLASS_USAGE_FILE_WRITER)));
    ProcessExecutor processExecutor = ProcessExecutorSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(PROCESS_EXECUTOR)), console);
    ImmutableList<Path> absolutePathsForInputs = ImmutableList.copyOf(((List<String>) Preconditions.checkNotNull(data.get(ABSOLUTE_PATHS_FOR_INPUTS))).stream().map(s -> Paths.get(s)).iterator());
    Optional<DirectToJarOutputSettings> directToJarOutputSettings = Optional.empty();
    if (data.containsKey(DIRECT_TO_JAR_SETTINGS)) {
        directToJarOutputSettings = Optional.of(DirectToJarOutputSettingsSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(DIRECT_TO_JAR_SETTINGS))));
    }
    return JavacExecutionContext.of(eventSink, stdErr, classLoaderCache, objectMapper, verbosity, cellPathResolver, javaPackageFinder, projectFilesystem, classUsageFileWriter, (Map<String, String>) Preconditions.checkNotNull(data.get(ENVIRONMENT), "Missing environment when deserializing JavacExectionContext"), processExecutor, absolutePathsForInputs, directToJarOutputSettings);
}
Also used : Path(java.nio.file.Path) JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) CellPathResolver(com.facebook.buck.rules.CellPathResolver) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Verbosity(com.facebook.buck.util.Verbosity) ProcessExecutor(com.facebook.buck.util.ProcessExecutor)

Example 9 with CellPathResolver

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

the class AppleBundleDescription method findDepsForTargetFromConstructorArgs.

/**
   * Propagate the bundle's platform, debug symbol and strip flavors to its dependents
   * which are other bundles (e.g. extensions)
   */
@Override
public ImmutableSet<BuildTarget> findDepsForTargetFromConstructorArgs(BuildTarget buildTarget, CellPathResolver cellRoots, AppleBundleDescription.Arg constructorArg) {
    if (!cxxPlatformFlavorDomain.containsAnyOf(buildTarget.getFlavors())) {
        buildTarget = BuildTarget.builder(buildTarget).addAllFlavors(ImmutableSet.of(defaultCxxPlatform.getFlavor())).build();
    }
    Optional<MultiarchFileInfo> fatBinaryInfo = MultiarchFileInfos.create(appleCxxPlatformsFlavorDomain, buildTarget);
    CxxPlatform cxxPlatform;
    if (fatBinaryInfo.isPresent()) {
        AppleCxxPlatform appleCxxPlatform = fatBinaryInfo.get().getRepresentativePlatform();
        cxxPlatform = appleCxxPlatform.getCxxPlatform();
    } else {
        cxxPlatform = ApplePlatforms.getCxxPlatformForBuildTarget(cxxPlatformFlavorDomain, defaultCxxPlatform, buildTarget);
    }
    String platformName = cxxPlatform.getFlavor().getName();
    final Flavor actualWatchFlavor;
    if (ApplePlatform.isSimulator(platformName)) {
        actualWatchFlavor = WATCH_SIMULATOR_FLAVOR;
    } else if (platformName.startsWith(ApplePlatform.IPHONEOS.getName()) || platformName.startsWith(ApplePlatform.WATCHOS.getName())) {
        actualWatchFlavor = WATCH_OS_FLAVOR;
    } else {
        actualWatchFlavor = InternalFlavor.of(platformName);
    }
    FluentIterable<BuildTarget> depsExcludingBinary = FluentIterable.from(constructorArg.deps).filter(Predicates.not(constructorArg.binary::equals));
    // Propagate platform flavors.  Need special handling for watch to map the pseudo-flavor
    // watch to the actual watch platform (simulator or device) so can't use
    // BuildTargets.propagateFlavorsInDomainIfNotPresent()
    {
        FluentIterable<BuildTarget> targetsWithPlatformFlavors = depsExcludingBinary.filter(BuildTargets.containsFlavors(cxxPlatformFlavorDomain));
        FluentIterable<BuildTarget> targetsWithoutPlatformFlavors = depsExcludingBinary.filter(Predicates.not(BuildTargets.containsFlavors(cxxPlatformFlavorDomain)));
        FluentIterable<BuildTarget> watchTargets = targetsWithoutPlatformFlavors.filter(BuildTargets.containsFlavor(WATCH)).transform(input -> BuildTarget.builder(input.withoutFlavors(WATCH)).addFlavors(actualWatchFlavor).build());
        targetsWithoutPlatformFlavors = targetsWithoutPlatformFlavors.filter(Predicates.not(BuildTargets.containsFlavor(WATCH)));
        // Gather all the deps now that we've added platform flavors to everything.
        depsExcludingBinary = targetsWithPlatformFlavors.append(watchTargets).append(BuildTargets.propagateFlavorDomains(buildTarget, ImmutableSet.of(cxxPlatformFlavorDomain), targetsWithoutPlatformFlavors));
    }
    // Propagate some flavors
    depsExcludingBinary = BuildTargets.propagateFlavorsInDomainIfNotPresent(StripStyle.FLAVOR_DOMAIN, buildTarget, depsExcludingBinary);
    depsExcludingBinary = BuildTargets.propagateFlavorsInDomainIfNotPresent(AppleDebugFormat.FLAVOR_DOMAIN, buildTarget, depsExcludingBinary);
    depsExcludingBinary = BuildTargets.propagateFlavorsInDomainIfNotPresent(LinkerMapMode.FLAVOR_DOMAIN, buildTarget, depsExcludingBinary);
    if (fatBinaryInfo.isPresent()) {
        depsExcludingBinary = depsExcludingBinary.append(fatBinaryInfo.get().getRepresentativePlatform().getCodesignProvider().getParseTimeDeps());
    } else {
        depsExcludingBinary = depsExcludingBinary.append(appleCxxPlatformsFlavorDomain.getValue(buildTarget).map(platform -> platform.getCodesignProvider().getParseTimeDeps()).orElse(ImmutableSet.of()));
    }
    return ImmutableSet.copyOf(depsExcludingBinary);
}
Also used : FluentIterable(com.google.common.collect.FluentIterable) CellPathResolver(com.facebook.buck.rules.CellPathResolver) SourcePath(com.facebook.buck.rules.SourcePath) Either(com.facebook.buck.model.Either) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavored(com.facebook.buck.model.Flavored) HasTests(com.facebook.buck.model.HasTests) FlavorDomain(com.facebook.buck.model.FlavorDomain) FluentIterable(com.google.common.collect.FluentIterable) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) ImplicitDepsInferringDescription(com.facebook.buck.rules.ImplicitDepsInferringDescription) Predicates(com.google.common.base.Predicates) StripStyle(com.facebook.buck.cxx.StripStyle) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) CxxDescriptionEnhancer(com.facebook.buck.cxx.CxxDescriptionEnhancer) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) Version(com.facebook.buck.versions.Version) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) MetadataProvidingDescription(com.facebook.buck.rules.MetadataProvidingDescription) LinkerMapMode(com.facebook.buck.cxx.LinkerMapMode) AbstractDescriptionArg(com.facebook.buck.rules.AbstractDescriptionArg) Hint(com.facebook.buck.rules.Hint) Optional(java.util.Optional) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTargets(com.facebook.buck.model.BuildTargets) Description(com.facebook.buck.rules.Description) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) BuildTarget(com.facebook.buck.model.BuildTarget) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor)

Example 10 with CellPathResolver

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

the class BuildConfigFieldsTypeCoercer method coerce.

@Override
public BuildConfigFields coerce(CellPathResolver cellRoots, ProjectFilesystem filesystem, Path pathRelativeToProjectRoot, Object object) throws CoerceFailedException {
    if (!(object instanceof List)) {
        throw CoerceFailedException.simple(object, getOutputClass());
    }
    List<?> list = (List<?>) object;
    List<String> values = list.stream().map(input -> {
        if (input instanceof String) {
            return (String) input;
        } else {
            throw new HumanReadableException("Expected string for build config values but was: %s", input);
        }
    }).collect(MoreCollectors.toImmutableList());
    return BuildConfigFields.fromFieldDeclarations(values);
}
Also used : ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) List(java.util.List) CellPathResolver(com.facebook.buck.rules.CellPathResolver) HumanReadableException(com.facebook.buck.util.HumanReadableException) Path(java.nio.file.Path) MoreCollectors(com.facebook.buck.util.MoreCollectors) HumanReadableException(com.facebook.buck.util.HumanReadableException) List(java.util.List)

Aggregations

CellPathResolver (com.facebook.buck.rules.CellPathResolver)12 BuildTarget (com.facebook.buck.model.BuildTarget)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)6 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 Path (java.nio.file.Path)5 Optional (java.util.Optional)5 BuildTargetPattern (com.facebook.buck.model.BuildTargetPattern)4 TargetGraph (com.facebook.buck.rules.TargetGraph)4 BuildTargetPatternParser (com.facebook.buck.parser.BuildTargetPatternParser)3 BuildRule (com.facebook.buck.rules.BuildRule)3 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)3 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)3 Test (org.junit.Test)3 BuildTargets (com.facebook.buck.model.BuildTargets)2 Flavor (com.facebook.buck.model.Flavor)2 FlavorDomain (com.facebook.buck.model.FlavorDomain)2 Flavored (com.facebook.buck.model.Flavored)2 MacroException (com.facebook.buck.model.MacroException)2 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)2