Search in sources :

Example 1 with SourceWithFlags

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

the class NewNativeTargetProjectMutator method traverseGroupsTreeAndHandleSources.

private void traverseGroupsTreeAndHandleSources(final PBXGroup sourcesGroup, final PBXSourcesBuildPhase sourcesBuildPhase, Iterable<GroupedSource> groupedSources) {
    GroupedSource.Visitor visitor = new GroupedSource.Visitor() {

        @Override
        public void visitSourceWithFlags(SourceWithFlags sourceWithFlags) {
            addSourcePathToSourcesBuildPhase(sourceWithFlags, sourcesGroup, sourcesBuildPhase);
        }

        @Override
        public void visitPublicHeader(SourcePath publicHeader) {
            addSourcePathToHeadersBuildPhase(publicHeader, sourcesGroup, HeaderVisibility.PUBLIC);
        }

        @Override
        public void visitPrivateHeader(SourcePath privateHeader) {
            addSourcePathToHeadersBuildPhase(privateHeader, sourcesGroup, HeaderVisibility.PRIVATE);
        }

        @Override
        public void visitSourceGroup(String sourceGroupName, Path sourceGroupPathRelativeToTarget, List<GroupedSource> sourceGroup) {
            PBXGroup newSourceGroup = sourcesGroup.getOrCreateChildGroupByName(sourceGroupName);
            newSourceGroup.setSourceTree(PBXReference.SourceTree.SOURCE_ROOT);
            newSourceGroup.setPath(sourceGroupPathRelativeToTarget.toString());
            // Sources groups stay in the order in which they're in the GroupedSource.
            newSourceGroup.setSortPolicy(PBXGroup.SortPolicy.UNSORTED);
            traverseGroupsTreeAndHandleSources(newSourceGroup, sourcesBuildPhase, sourceGroup);
        }
    };
    for (GroupedSource groupedSource : groupedSources) {
        groupedSource.visit(visitor);
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) GroupedSource(com.facebook.buck.apple.GroupedSource) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) NSString(com.dd.plist.NSString) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags)

Example 2 with SourceWithFlags

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

the class RuleKeyBuilder method setReflectively.

/** Recursively serializes the value. Serialization of the key is handled outside. */
protected RuleKeyBuilder<RULE_KEY> setReflectively(@Nullable Object val) {
    if (val instanceof RuleKeyAppendable) {
        return setAppendableRuleKey((RuleKeyAppendable) val);
    }
    if (val instanceof BuildRule) {
        return setBuildRule((BuildRule) val);
    }
    if (val instanceof Supplier) {
        try (Scope containerScope = scopedHasher.wrapperScope(Wrapper.SUPPLIER)) {
            Object newVal = ((Supplier<?>) val).get();
            return setReflectively(newVal);
        }
    }
    if (val instanceof Optional) {
        Object o = ((Optional<?>) val).orElse(null);
        try (Scope wraperScope = scopedHasher.wrapperScope(Wrapper.OPTIONAL)) {
            return setReflectively(o);
        }
    }
    if (val instanceof Either) {
        Either<?, ?> either = (Either<?, ?>) val;
        if (either.isLeft()) {
            try (Scope wraperScope = scopedHasher.wrapperScope(Wrapper.EITHER_LEFT)) {
                return setReflectively(either.getLeft());
            }
        } else {
            try (Scope wraperScope = scopedHasher.wrapperScope(Wrapper.EITHER_RIGHT)) {
                return setReflectively(either.getRight());
            }
        }
    }
    // Note {@link java.nio.file.Path} implements "Iterable", so we explicitly exclude it here.
    if (val instanceof Iterable && !(val instanceof Path)) {
        try (ContainerScope containerScope = scopedHasher.containerScope(Container.LIST)) {
            for (Object element : (Iterable<?>) val) {
                try (Scope elementScope = containerScope.elementScope()) {
                    setReflectively(element);
                }
            }
            return this;
        }
    }
    if (val instanceof Iterator) {
        Iterator<?> iterator = (Iterator<?>) val;
        try (ContainerScope containerScope = scopedHasher.containerScope(Container.LIST)) {
            while (iterator.hasNext()) {
                try (Scope elementScope = containerScope.elementScope()) {
                    setReflectively(iterator.next());
                }
            }
        }
        return this;
    }
    if (val instanceof Map) {
        if (!(val instanceof SortedMap || val instanceof ImmutableMap)) {
            logger.warn("Adding an unsorted map to the rule key. " + "Expect unstable ordering and caches misses: %s", val);
        }
        try (ContainerScope containerScope = scopedHasher.containerScope(Container.MAP)) {
            for (Map.Entry<?, ?> entry : ((Map<?, ?>) val).entrySet()) {
                try (Scope elementScope = containerScope.elementScope()) {
                    setReflectively(entry.getKey());
                }
                try (Scope elementScope = containerScope.elementScope()) {
                    setReflectively(entry.getValue());
                }
            }
        }
        return this;
    }
    if (val instanceof Path) {
        throw new HumanReadableException("It's not possible to reliably disambiguate Paths. They are disallowed from rule keys");
    }
    if (val instanceof SourcePath) {
        try {
            return setSourcePath((SourcePath) val);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    if (val instanceof NonHashableSourcePathContainer) {
        SourcePath sourcePath = ((NonHashableSourcePathContainer) val).getSourcePath();
        return setNonHashingSourcePath(sourcePath);
    }
    if (val instanceof SourceWithFlags) {
        SourceWithFlags source = (SourceWithFlags) val;
        try {
            setSourcePath(source.getSourcePath());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        setReflectively(source.getFlags());
        return this;
    }
    return setSingleValue(val);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) ArchiveMemberSourcePath(com.facebook.buck.rules.ArchiveMemberSourcePath) ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Optional(java.util.Optional) ContainerScope(com.facebook.buck.rules.keys.RuleKeyScopedHasher.ContainerScope) NonHashableSourcePathContainer(com.facebook.buck.rules.NonHashableSourcePathContainer) IOException(java.io.IOException) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags) ImmutableMap(com.google.common.collect.ImmutableMap) SourcePath(com.facebook.buck.rules.SourcePath) ArchiveMemberSourcePath(com.facebook.buck.rules.ArchiveMemberSourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Scope(com.facebook.buck.rules.keys.RuleKeyScopedHasher.Scope) ContainerScope(com.facebook.buck.rules.keys.RuleKeyScopedHasher.ContainerScope) HumanReadableException(com.facebook.buck.util.HumanReadableException) SortedMap(java.util.SortedMap) Iterator(java.util.Iterator) Either(com.facebook.buck.model.Either) BuildRule(com.facebook.buck.rules.BuildRule) Supplier(com.google.common.base.Supplier) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) SortedMap(java.util.SortedMap) RuleKeyAppendable(com.facebook.buck.rules.RuleKeyAppendable)

Example 3 with SourceWithFlags

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

the class TypeCoercerTest method coercingHeterogeneousAppleSourceGroups.

@Test
public void coercingHeterogeneousAppleSourceGroups() throws NoSuchFieldException, CoerceFailedException {
    Type type = TestFields.class.getField("listOfSourcesWithFlags").getGenericType();
    TypeCoercer<?> coercer = typeCoercerFactory.typeCoercerForType(type);
    ImmutableList<?> input = ImmutableList.of("Group1/foo.m", ImmutableList.of("Group1/bar.m", ImmutableList.of("-Wall", "-Werror")), "Group2/baz.m", ImmutableList.of("Group2/blech.m", ImmutableList.of("-fobjc-arc")));
    Object result = coercer.coerce(cellRoots, filesystem, Paths.get(""), input);
    ImmutableList<SourceWithFlags> expectedResult = ImmutableList.of(SourceWithFlags.of(new FakeSourcePath("Group1/foo.m")), SourceWithFlags.of(new FakeSourcePath("Group1/bar.m"), ImmutableList.of("-Wall", "-Werror")), SourceWithFlags.of(new FakeSourcePath("Group2/baz.m")), SourceWithFlags.of(new FakeSourcePath("Group2/blech.m"), ImmutableList.of("-fobjc-arc")));
    assertEquals(expectedResult, result);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Type(java.lang.reflect.Type) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags) Test(org.junit.Test)

Example 4 with SourceWithFlags

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

the class AppleDescriptions method populateCxxConstructorArg.

public static void populateCxxConstructorArg(SourcePathResolver resolver, CxxConstructorArg output, AppleNativeTargetDescriptionArg arg, BuildTarget buildTarget) {
    Path headerPathPrefix = AppleDescriptions.getHeaderPathPrefix(arg, buildTarget);
    // The resulting cxx constructor arg will have no exported headers and both headers and exported
    // headers specified in the apple arg will be available with both public and private include
    // styles.
    ImmutableSortedMap<String, SourcePath> headerMap = ImmutableSortedMap.<String, SourcePath>naturalOrder().putAll(convertAppleHeadersToPublicCxxHeaders(resolver::getRelativePath, headerPathPrefix, arg)).putAll(convertAppleHeadersToPrivateCxxHeaders(resolver::getRelativePath, headerPathPrefix, arg)).build();
    ImmutableSortedSet.Builder<SourceWithFlags> nonSwiftSrcs = ImmutableSortedSet.naturalOrder();
    for (SourceWithFlags src : arg.srcs) {
        if (!MorePaths.getFileExtension(resolver.getAbsolutePath(src.getSourcePath())).equalsIgnoreCase(SWIFT_EXTENSION)) {
            nonSwiftSrcs.add(src);
        }
    }
    output.srcs = nonSwiftSrcs.build();
    output.platformSrcs = arg.platformSrcs;
    output.headers = SourceList.ofNamedSources(headerMap);
    output.platformHeaders = arg.platformHeaders;
    output.prefixHeader = arg.prefixHeader;
    output.compilerFlags = arg.compilerFlags;
    output.platformCompilerFlags = arg.platformCompilerFlags;
    output.langCompilerFlags = arg.langCompilerFlags;
    output.preprocessorFlags = arg.preprocessorFlags;
    output.platformPreprocessorFlags = arg.platformPreprocessorFlags;
    output.langPreprocessorFlags = arg.langPreprocessorFlags;
    output.linkerFlags = arg.linkerFlags;
    output.platformLinkerFlags = arg.platformLinkerFlags;
    output.frameworks = arg.frameworks;
    output.libraries = arg.libraries;
    output.deps = arg.deps;
    // This is intentionally an empty string; we put all prefixes into
    // the header map itself.
    output.headerNamespace = Optional.of("");
    output.cxxRuntimeType = arg.cxxRuntimeType;
    output.tests = arg.tests;
    output.precompiledHeader = arg.precompiledHeader;
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags)

Example 5 with SourceWithFlags

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

the class RuleUtilsTest method extractGroupedSources.

@Test
public void extractGroupedSources() {
    ImmutableList<SourceWithFlags> input = ImmutableList.of(SourceWithFlags.of(new FakeSourcePath("Group1/foo.m")), SourceWithFlags.of(new FakeSourcePath("Group1/bar.m"), ImmutableList.of("-Wall")), SourceWithFlags.of(new FakeSourcePath("Group2/baz.m")), SourceWithFlags.of(new FakeSourcePath("Group2/blech.m"), ImmutableList.of("-fobjc-arc")));
    SourcePathResolver resolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    ImmutableList<GroupedSource> sources = RuleUtils.createGroupsFromSourcePaths(resolver::getRelativePath, input, /* extraXcodeSources */
    ImmutableSortedSet.of(), /* publicHeaders */
    ImmutableSortedSet.of(), /* privateHeaders */
    ImmutableSortedSet.of());
    assertEquals(ImmutableList.of(GroupedSource.ofSourceGroup("Group1", Paths.get("Group1"), ImmutableList.of(GroupedSource.ofSourceWithFlags(SourceWithFlags.of(new FakeSourcePath("Group1/bar.m"), ImmutableList.of("-Wall"))), GroupedSource.ofSourceWithFlags(SourceWithFlags.of(new FakeSourcePath("Group1/foo.m"))))), GroupedSource.ofSourceGroup("Group2", Paths.get("Group2"), ImmutableList.of(GroupedSource.ofSourceWithFlags(SourceWithFlags.of(new FakeSourcePath("Group2/baz.m"))), GroupedSource.ofSourceWithFlags(SourceWithFlags.of(new FakeSourcePath("Group2/blech.m"), ImmutableList.of("-fobjc-arc")))))), sources);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

SourceWithFlags (com.facebook.buck.rules.SourceWithFlags)8 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)4 SourcePath (com.facebook.buck.rules.SourcePath)4 Path (java.nio.file.Path)4 Test (org.junit.Test)4 Type (java.lang.reflect.Type)3 BuildTargetSourcePath (com.facebook.buck.rules.BuildTargetSourcePath)2 PathSourcePath (com.facebook.buck.rules.PathSourcePath)2 NSString (com.dd.plist.NSString)1 GroupedSource (com.facebook.buck.apple.GroupedSource)1 PBXGroup (com.facebook.buck.apple.xcode.xcodeproj.PBXGroup)1 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)1 ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)1 Either (com.facebook.buck.model.Either)1 ArchiveMemberSourcePath (com.facebook.buck.rules.ArchiveMemberSourcePath)1 BuildRule (com.facebook.buck.rules.BuildRule)1 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)1 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)1 NonHashableSourcePathContainer (com.facebook.buck.rules.NonHashableSourcePathContainer)1 RuleKeyAppendable (com.facebook.buck.rules.RuleKeyAppendable)1