Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
Propagate aspect down srcs attr
Browse files Browse the repository at this point in the history
This will allow Tulsi to discover rules which generate source files
and generate indexer targets for them.

PiperOrigin-RevId: 196674653
  • Loading branch information
DavidGoldman committed May 16, 2018
1 parent 68f9816 commit 3476863
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 55 deletions.
3 changes: 2 additions & 1 deletion src/TulsiGenerator/Bazel/tulsi/tulsi_aspects.bzl
Expand Up @@ -40,6 +40,7 @@ _TULSI_COMPILE_DEPS = [
"frameworks",
"settings_bundle",
"non_propagated_deps",
"srcs", # To propagate down onto rules which generate source files.
"tests", # for test_suite when the --noexpand_test_suites flag is used.
"_implicit_tests", # test_suites without a `tests` attr have an '$implicit_tests' attr instead.
"test_bundle",
Expand Down Expand Up @@ -340,7 +341,7 @@ def _collect_dependency_labels(rule, filter, attr_list):
A list of the Bazel labels of dependencies of the given rule.
"""
attr = rule.attr
deps = [dep for attribute in attr_list for dep in _filter_deps(filter, _getattr_as_list(attr, attribute))]
deps = [dep for attribute in attr_list for dep in _filter_deps(filter, _getattr_as_list(attr, attribute)) if hasattr(dep, "tulsi_info_files")]
return [dep.label for dep in deps if hasattr(dep, "label")]

def _get_opt_attr(obj, attr_path):
Expand Down
4 changes: 3 additions & 1 deletion src/TulsiGenerator/PBXTargetGenerator.swift
Expand Up @@ -543,12 +543,14 @@ final class PBXTargetGenerator: PBXTargetGeneratorProtocol {
}

// Indexer targets aren't needed:
// - if the target is a filegroup (we generate an indexer for what references the filegroup).
// - if the target has no source files (there's nothing to index!)
// - if the target is a test bundle (we generate proper targets for these).
if (sourceFileInfos.isEmpty &&
nonARCSourceFileInfos.isEmpty &&
frameworkFileInfos.isEmpty &&
nonSourceVersionedFileInfos.isEmpty) || ruleEntry.pbxTargetType?.isTest ?? false {
nonSourceVersionedFileInfos.isEmpty)
|| ruleEntry.pbxTargetType?.isTest ?? false || ruleEntry.type == "filegroup" {
return (frameworkSearchPaths)
}

Expand Down
21 changes: 20 additions & 1 deletion src/TulsiGeneratorIntegrationTests/AspectTests.swift
Expand Up @@ -330,7 +330,7 @@ class TulsiSourcesAspectTests: BazelIntegrationTestCase {
let ruleEntryMap = try aspectInfoExtractor.extractRuleEntriesForLabels([BuildLabel("//tulsi_test:XCTest")],
startupOptions: bazelStartupOptions,
buildOptions: bazelBuildOptions)
XCTAssertEqual(ruleEntryMap.allRuleEntries.count, 26)
XCTAssertEqual(ruleEntryMap.allRuleEntries.count, 28)

let checker = InfoChecker(ruleEntryMap: ruleEntryMap)

Expand All @@ -340,13 +340,32 @@ class TulsiSourcesAspectTests: BazelIntegrationTestCase {
.dependsOn("//tulsi_test:Application")
.dependsOn("//tulsi_test:XCTest_test_bundle")

checker.assertThat("//tulsi_test:ApplicationLibrary")
.dependsOn("//tulsi_test:CoreDataResources")
.dependsOn("//tulsi_test:Library")
.dependsOn("//tulsi_test:ObjCFramework")
.dependsOn("//tulsi_test:SrcGenerator")

checker.assertThat("//tulsi_test:XCTest_test_bundle")
.dependsOn("//tulsi_test:Application")
.dependsOn("//tulsi_test:XCTest_test_binary")

checker.assertThat("//tulsi_test:XCTest_test_binary")
.dependsOn("//tulsi_test:Library")
.dependsOn("//tulsi_test:TestLibrary")

checker.assertThat("//tulsi_test:Library")
.hasSources(["tulsi_test/LibrarySources/srcs/src1.m",
"tulsi_test/LibrarySources/srcs/src2.m",
"tulsi_test/LibrarySources/srcs/src3.m",
"tulsi_test/LibrarySources/srcs/src4.m",
"tulsi_test/Library/srcs/src5.mm",
"tulsi_test/Library/srcs/SrcsHeader.h",
"tulsi_test/Library/hdrs/HdrsHeader.h"])
.dependsOn("//tulsi_test:LibrarySources")

checker.assertThat("//tulsi_test:SrcGenerator")
.hasSources(["tulsi_test/SrcGenerator/srcs/input.m"])
}

func testPlatformDependent() throws {
Expand Down

0 comments on commit 3476863

Please sign in to comment.