Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Sources/Configuration/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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] {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Frontend/Commands/ScanCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()

Expand Down
4 changes: 4 additions & 0 deletions Sources/ProjectDrivers/BazelProjectDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,17 @@ 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")

scan(
name = "scan",
testonly = True,
config = "\(configPath)",
global_indexstore = \(globalIndexStoreValue),
deps = [
\(deps)
],
Expand Down
6 changes: 5 additions & 1 deletion bazel/internal/scan/scan.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
1 change: 1 addition & 0 deletions bazel/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading