Skip to content

Commit a11143c

Browse files
committed
Add --bazel-index-store argument to scan command
* Adds a new flag `--bazel-index-store` for providing a path to a global index store used by all modules compiled by Bazel * Adds logic to the Bazel rules to use the provided `--bazel-index-store` value to populate `indexstores` in the project config instead of populating with the list of module specific stores
1 parent 2d9b99a commit a11143c

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

Sources/Configuration/Configuration.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ public final class Configuration {
137137
@Setting(key: "bazel_filter", defaultValue: nil)
138138
public var bazelFilter: String?
139139

140+
@Setting(key: "bazel_index_store", defaultValue: nil)
141+
public var bazelIndexStore: FilePath?
142+
143+
140144
// Non user facing.
141145
public var guidedSetup: Bool = false
142146
public var projectRoot: FilePath = .init()
@@ -208,7 +212,7 @@ public final class Configuration {
208212
$externalTestCaseClasses, $verbose, $quiet, $disableUpdateCheck, $strict, $indexStorePath, $skipBuild,
209213
$skipSchemesValidation, $cleanBuild, $buildArguments, $xcodeListArguments, $relativeResults, $jsonPackageManifestPath,
210214
$retainCodableProperties, $retainEncodableProperties, $baseline, $writeBaseline, $writeResults, $genericProjectConfig,
211-
$bazel, $bazelFilter,
215+
$bazel, $bazelFilter, $bazelIndexStore
212216
]
213217

214218
private func buildFilenameMatchers(with patterns: [String]) -> [FilenameMatcher] {

Sources/Frontend/Commands/ScanCommand.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ struct ScanCommand: FrontendCommand {
144144
@Option(help: "Filter pattern applied to the Bazel top-level targets query")
145145
var bazelFilter: String?
146146

147+
@Option(help: "Path to a global index store populated by Bazel. If provided, will be used instead of individual module stores.")
148+
var bazelIndexStore: FilePath?
149+
147150
private static let defaultConfiguration = Configuration()
148151

149152
func run() throws {
@@ -200,6 +203,7 @@ struct ScanCommand: FrontendCommand {
200203
configuration.apply(\.$genericProjectConfig, genericProjectConfig)
201204
configuration.apply(\.$bazel, bazel)
202205
configuration.apply(\.$bazelFilter, bazelFilter)
206+
configuration.apply(\.$bazelIndexStore, bazelIndexStore)
203207

204208
configuration.buildFilenameMatchers()
205209

Sources/ProjectDrivers/BazelProjectDriver.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,17 @@ public class BazelProjectDriver: ProjectDriver {
8585

8686
let buildPath = outputPath.appending("BUILD.bazel")
8787
let deps = try queryTargets().joined(separator: ",\n")
88+
let globalIndexStoreValue = configuration.bazelIndexStore.map {
89+
"\"\(FilePath.makeAbsolute($0)))\""
90+
} ?? "None"
8891
let buildFileContents = """
8992
load("@periphery//bazel:rules.bzl", "scan")
9093
9194
scan(
9295
name = "scan",
9396
testonly = True,
9497
config = "\(configPath)",
98+
global_indexstore = \(globalIndexStoreValue),
9599
deps = [
96100
\(deps)
97101
],

bazel/internal/scan/scan.bzl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,12 @@ def scan_impl(ctx):
165165
xcmappingmodels = sets.to_list(xcmappingmodels_set)
166166
test_targets = sets.to_list(test_targets_set)
167167

168+
indexstores_config = [file.path for file in indexstores]
169+
if ctx.attr.global_indexstore:
170+
indexstores_config = [ctx.attr.global_indexstore]
171+
168172
project_config = struct(
169-
indexstores = [file.path for file in indexstores],
173+
indexstores = indexstores_config,
170174
plists = [file.path for file in plists],
171175
xibs = [file.path for file in xibs],
172176
xcdatamodels = [file.path for file in xcdatamodels],

bazel/rules.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ scan = rule(
1414
doc = "Top-level project targets to scan.",
1515
),
1616
"config": attr.string(doc = "Path to the periphery.yml configuration file."),
17+
"global_indexstore": attr.string(doc = "Path to a global index store."),
1718
"periphery": attr.label(
1819
doc = "The periphery executable target.",
1920
default = "@periphery//:periphery",

0 commit comments

Comments
 (0)