diff --git a/Sources/Configuration/Configuration.swift b/Sources/Configuration/Configuration.swift index e5e5c9ecc..16f0e6a17 100644 --- a/Sources/Configuration/Configuration.swift +++ b/Sources/Configuration/Configuration.swift @@ -137,6 +137,10 @@ public final class Configuration { @Setting(key: "bazel_filter", defaultValue: nil) public var bazelFilter: String? + @Setting(key: "bazel_index_store", defaultValue: nil) + public var bazelIndexStore: FilePath? + + // Non user facing. public var guidedSetup: Bool = false public var projectRoot: FilePath = .init() @@ -208,7 +212,7 @@ public final class Configuration { $externalTestCaseClasses, $verbose, $quiet, $disableUpdateCheck, $strict, $indexStorePath, $skipBuild, $skipSchemesValidation, $cleanBuild, $buildArguments, $xcodeListArguments, $relativeResults, $jsonPackageManifestPath, $retainCodableProperties, $retainEncodableProperties, $baseline, $writeBaseline, $writeResults, $genericProjectConfig, - $bazel, $bazelFilter, + $bazel, $bazelFilter, $bazelIndexStore ] private func buildFilenameMatchers(with patterns: [String]) -> [FilenameMatcher] { diff --git a/Sources/Frontend/Commands/ScanCommand.swift b/Sources/Frontend/Commands/ScanCommand.swift index 1aa846347..56f93f626 100644 --- a/Sources/Frontend/Commands/ScanCommand.swift +++ b/Sources/Frontend/Commands/ScanCommand.swift @@ -144,6 +144,9 @@ struct ScanCommand: FrontendCommand { @Option(help: "Filter pattern applied to the Bazel top-level targets query") var bazelFilter: String? + @Option(help: "Path to a global index store populated by Bazel. If provided, will be used instead of individual module stores.") + var bazelIndexStore: FilePath? + private static let defaultConfiguration = Configuration() func run() throws { @@ -200,6 +203,7 @@ struct ScanCommand: FrontendCommand { configuration.apply(\.$genericProjectConfig, genericProjectConfig) configuration.apply(\.$bazel, bazel) configuration.apply(\.$bazelFilter, bazelFilter) + configuration.apply(\.$bazelIndexStore, bazelIndexStore) configuration.buildFilenameMatchers() diff --git a/Sources/ProjectDrivers/BazelProjectDriver.swift b/Sources/ProjectDrivers/BazelProjectDriver.swift index bd1a82c24..3c5278493 100644 --- a/Sources/ProjectDrivers/BazelProjectDriver.swift +++ b/Sources/ProjectDrivers/BazelProjectDriver.swift @@ -85,6 +85,9 @@ public class BazelProjectDriver: ProjectDriver { let buildPath = outputPath.appending("BUILD.bazel") let deps = try queryTargets().joined(separator: ",\n") + let globalIndexStoreValue = configuration.bazelIndexStore.map { + "\"\(FilePath.makeAbsolute($0)))\"" + } ?? "None" let buildFileContents = """ load("@periphery//bazel:rules.bzl", "scan") @@ -92,6 +95,7 @@ public class BazelProjectDriver: ProjectDriver { name = "scan", testonly = True, config = "\(configPath)", + global_indexstore = \(globalIndexStoreValue), deps = [ \(deps) ], diff --git a/bazel/internal/scan/scan.bzl b/bazel/internal/scan/scan.bzl index fcd0e1489..e46cce083 100644 --- a/bazel/internal/scan/scan.bzl +++ b/bazel/internal/scan/scan.bzl @@ -165,8 +165,12 @@ def scan_impl(ctx): xcmappingmodels = sets.to_list(xcmappingmodels_set) test_targets = sets.to_list(test_targets_set) + indexstores_config = [file.path for file in indexstores] + if ctx.attr.global_indexstore: + indexstores_config = [ctx.attr.global_indexstore] + project_config = struct( - indexstores = [file.path for file in indexstores], + indexstores = indexstores_config, plists = [file.path for file in plists], xibs = [file.path for file in xibs], xcdatamodels = [file.path for file in xcdatamodels], diff --git a/bazel/rules.bzl b/bazel/rules.bzl index 4fbaa763b..4e6f48830 100644 --- a/bazel/rules.bzl +++ b/bazel/rules.bzl @@ -14,6 +14,7 @@ scan = rule( doc = "Top-level project targets to scan.", ), "config": attr.string(doc = "Path to the periphery.yml configuration file."), + "global_indexstore": attr.string(doc = "Path to a global index store."), "periphery": attr.label( doc = "The periphery executable target.", default = "@periphery//:periphery",