Skip to content

Commit

Permalink
Improve Bazel integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ileitch committed Nov 3, 2024
1 parent 52d6e73 commit a652e3b
Show file tree
Hide file tree
Showing 30 changed files with 925 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.3.0
7.4.0
14 changes: 11 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,28 @@ env:
cache_version: 1
jobs:
lint:
runs-on: macos-14
runs-on: macos-15
name: Lint
steps:
- uses: actions/checkout@master
- uses: jdx/mise-action@v2
- run: mise run lint-ci
bazel:
runs-on: macos-15
name: Bazel
steps:
- uses: actions/checkout@master
- run: bazel test //Tests/...
macOS:
strategy:
fail-fast: false
matrix:
xcode: ["16.0", "15.4", "15.2"]
xcode: ["16.1", "16.0", "15.4", "15.2"]
include:
- xcode: "16.1"
macos: macos-15
- xcode: "16.0"
macos: macos-14
macos: macos-15
- xcode: "15.4"
macos: macos-14
- xcode: "15.2"
Expand Down
1 change: 1 addition & 0 deletions .mise/tasks/lint
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ set -euo pipefail

cd $MISE_PROJECT_ROOT

bazel run //bazel/internal:buildifier.fix
swiftformat .
swiftlint lint --quiet
12 changes: 10 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package_group(
name = "generated",
includes = [
"@periphery_generated//:package_group"
"@periphery_generated//:package_group",
],
)

Expand All @@ -10,4 +10,12 @@ package_group(
packages = ["//..."],
)

alias(actual = "@periphery_generated//rule:scan", name = "scan")
alias(
name = "scan",
actual = "@periphery_generated//rule:scan",
)

alias(
name = "periphery",
actual = "//Sources/Frontend:Frontend",
)
27 changes: 25 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,32 @@ module(
compatibility_level = 1,
)

bazel_dep(name = "rules_swift", version = "2.1.1")
bazel_dep(name = "rules_apple", version = "3.8.0")
# Bazel dependencies
bazel_dep(name = "rules_swift", version = "2.2.2")
bazel_dep(name = "rules_apple", version = "3.11.1")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "apple_support", version = "1.17.1")
bazel_dep(name = "platforms", version = "0.0.10")

# Bazel dev dependencies
bazel_dep(name = "buildifier_prebuilt", version = "7.3.1", dev_dependency = True)

# Swift dependencies
bazel_dep(name = "swift-syntax", version = "600.0.0") # TODO: Update to 600.0.1
bazel_dep(name = "yams", version = "5.1.3")
bazel_dep(name = "aexml", version = "4.7.0")
bazel_dep(name = "swift_argument_parser", version = "1.3.1.1") # TODO: Update to 1.5.0
bazel_dep(name = "swift-indexstore", version = "0.3.0")
bazel_dep(name = "swift-filename-matcher", version = "0.1.2")

# Extensions
generated = use_extension("//bazel:extensions.bzl", "generated")
use_repo(generated, "periphery_generated")

non_module_deps = use_extension("//bazel/internal:extensions.bzl", "non_module_deps")
use_repo(
non_module_deps,
"com_github_apple_swift-system",
"com_github_kylef_pathkit",
"com_github_tuist_xcodeproj",
)
354 changes: 284 additions & 70 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var dependencies: [Package.Dependency] = [
.package(url: "https://github.com/tadija/AEXML", from: "4.0.0"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
.package(url: "https://github.com/kateinoigakukun/swift-indexstore", from: "0.3.0"),
.package(url: "https://github.com/apple/swift-syntax", from: "600.0.0"),
.package(url: "https://github.com/apple/swift-syntax", from: "600.0.1"),
.package(url: "https://github.com/ileitch/swift-filename-matcher", from: "0.0.0"),
]

Expand Down Expand Up @@ -82,6 +82,7 @@ var targets: [PackageDescription.Target] = [
.target(name: "SyntaxAnalysis"),
.target(name: "Shared"),
.product(name: "SwiftIndexStore", package: "swift-indexstore"),
.product(name: "AEXML", package: "AEXML"),
]
),
.target(
Expand Down
Empty file added Sources/BUILD.bazel
Empty file.
19 changes: 19 additions & 0 deletions Sources/Configuration/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("@rules_swift//swift:swift.bzl", "swift_library")

swift_library(
name = "Configuration",
srcs = [
"Configuration.swift",
"OutputFormat.swift",
],
module_name = "Configuration",
visibility = ["//visibility:public"],
deps = [
"//Sources/Extensions",
"//Sources/Logger",
"//Sources/Shared",
"@com_github_apple_swift-system//:SystemPackage",
"@swift-filename-matcher//:FilenameMatcher",
"@yams//:Yams",
],
)
22 changes: 22 additions & 0 deletions Sources/Extensions/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@rules_swift//swift:swift.bzl", "swift_library")

swift_library(
name = "Extensions",
srcs = [
"Array+Extension.swift",
"Collection+Extension.swift",
"FilePath+Extension.swift",
"FilePath+Glob.swift",
"FilenameMatcher+Extension.swift",
"Sequence+Extension.swift",
"Set+Extension.swift",
"String+Extension.swift",
"String+Version.swift",
],
module_name = "Extensions",
visibility = ["//visibility:public"],
deps = [
"@com_github_apple_swift-system//:SystemPackage",
"@swift-filename-matcher//:FilenameMatcher",
],
)
31 changes: 31 additions & 0 deletions Sources/Frontend/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("@rules_swift//swift:swift.bzl", "swift_binary")

swift_binary(
name = "Frontend",
srcs = [
"Commands/CheckUpdateCommand.swift",
"Commands/ClearCacheCommand.swift",
"Commands/FrontendCommand.swift",
"Commands/ScanCommand.swift",
"Commands/VersionCommand.swift",
"CommonSetupGuide.swift",
"GuidedSetup.swift",
"Logger+Extension.swift",
"Project.swift",
"SPMProjectSetupGuide.swift",
"Scan.swift",
"UpdateChecker.swift",
"Version.swift",
"main.swift",
],
visibility = ["//visibility:public"],
deps = [
"//Sources/Configuration",
"//Sources/PeripheryKit",
"//Sources/ProjectDrivers",
"//Sources/Shared",
"//Sources/SourceGraph",
"@swift-filename-matcher//:FilenameMatcher",
"@swift_argument_parser//:ArgumentParser",
],
)
29 changes: 29 additions & 0 deletions Sources/Indexer/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
load("@rules_swift//swift:swift.bzl", "swift_library")

swift_library(
name = "Indexer",
srcs = [
"IndexPipeline.swift",
"IndexPlan.swift",
"Indexer.swift",
"InfoPlistIndexer.swift",
"InfoPlistParser.swift",
"JobPool.swift",
"SourceFileCollector.swift",
"SwiftIndexer.swift",
"XCDataModelIndexer.swift",
"XCDataModelParser.swift",
"XCMappingModelIndexer.swift",
"XCMappingModelParser.swift",
"XibIndexer.swift",
"XibParser.swift",
],
module_name = "Indexer",
visibility = ["//visibility:public"],
deps = [
"//Sources/Shared",
"//Sources/SyntaxAnalysis",
"@aexml//:AEXML",
"@swift-indexstore//:SwiftIndexStore",
],
)
8 changes: 8 additions & 0 deletions Sources/Logger/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@rules_swift//swift:swift.bzl", "swift_library")

swift_library(
name = "Logger",
srcs = ["Logger.swift"],
module_name = "Logger",
visibility = ["//visibility:public"],
)
31 changes: 31 additions & 0 deletions Sources/PeripheryKit/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("@rules_swift//swift:swift.bzl", "swift_library")

swift_library(
name = "PeripheryKit",
srcs = [
"Results/Baseline.swift",
"Results/CheckstyleFormatter.swift",
"Results/CodeClimateFormatter.swift",
"Results/CsvFormatter.swift",
"Results/GitHubActionsFormatter.swift",
"Results/JsonFormatter.swift",
"Results/OutputDeclarationFilter.swift",
"Results/OutputFormatter.swift",
"Results/XcodeFormatter.swift",
"ScanResult.swift",
"ScanResultBuilder.swift",
],
module_name = "PeripheryKit",
visibility = ["//visibility:public"],
deps = [
"//Sources/Indexer",
"//Sources/Shared",
"//Sources/SourceGraph",
"@aexml//:AEXML",
"@com_github_apple_swift-system//:SystemPackage",
"@swift-filename-matcher//:FilenameMatcher",
"@swift-indexstore//:SwiftIndexStore",
"@swift-syntax//:SwiftParser",
"@swift-syntax//:SwiftSyntax",
],
)
21 changes: 21 additions & 0 deletions Sources/ProjectDrivers/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load("@rules_swift//swift:swift.bzl", "swift_library")

swift_library(
name = "ProjectDrivers",
srcs = [
"BazelProjectDriver.swift",
"GenericProjectDriver.swift",
"ProjectDriver.swift",
"SPM.swift",
"SPMProjectDriver.swift",
"XcodeProjectDriver.swift",
],
module_name = "ProjectDrivers",
visibility = ["//visibility:public"],
deps = [
"//Sources/Indexer",
"//Sources/Shared",
"//Sources/SourceGraph",
"//Sources/XcodeSupport",
],
)
25 changes: 25 additions & 0 deletions Sources/Shared/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
load("@rules_swift//swift:swift.bzl", "swift_library")

swift_library(
name = "Shared",
srcs = [
"Benchmark.swift",
"Constants.swift",
"PeripheryError.swift",
"ProjectKind.swift",
"PropertyTypeSanitizer.swift",
"SetupGuide.swift",
"Shell.swift",
"SwiftVersion.swift",
"SwiftVersionParser.swift",
"UnfairLock.swift",
],
module_name = "Shared",
visibility = ["//visibility:public"],
deps = [
"//Sources/Extensions",
"//Sources/Logger",
"@com_github_apple_swift-system//:SystemPackage",
"@swift-filename-matcher//:FilenameMatcher",
],
)
60 changes: 60 additions & 0 deletions Sources/SourceGraph/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
load("@rules_swift//swift:swift.bzl", "swift_library")

swift_library(
name = "SourceGraph",
srcs = [
"Elements/Accessibility.swift",
"Elements/AssetReference.swift",
"Elements/CommentCommand.swift",
"Elements/Declaration.swift",
"Elements/ImportStatement.swift",
"Elements/Location.swift",
"Elements/ProjectFileKind.swift",
"Elements/Reference.swift",
"Elements/SourceFile.swift",
"Mutators/AccessibilityCascader.swift",
"Mutators/AncestralReferenceEliminator.swift",
"Mutators/AssetReferenceRetainer.swift",
"Mutators/AssignOnlyPropertyReferenceEliminator.swift",
"Mutators/CapitalSelfFunctionCallRetainer.swift",
"Mutators/CodablePropertyRetainer.swift",
"Mutators/CodingKeyEnumReferenceBuilder.swift",
"Mutators/ComplexPropertyAccessorReferenceBuilder.swift",
"Mutators/DefaultConstructorReferenceBuilder.swift",
"Mutators/DynamicMemberLookupReferenceBuilder.swift",
"Mutators/EntryPointAttributeRetainer.swift",
"Mutators/EnumCaseReferenceBuilder.swift",
"Mutators/ExtensionReferenceBuilder.swift",
"Mutators/ExternalOverrideRetainer.swift",
"Mutators/ExternalTypeProtocolConformanceReferenceRemover.swift",
"Mutators/GenericClassAndStructConstructorReferenceBuilder.swift",
"Mutators/InterfaceBuilderPropertyRetainer.swift",
"Mutators/ObjCAccessibleRetainer.swift",
"Mutators/PropertyWrapperRetainer.swift",
"Mutators/ProtocolConformanceReferenceBuilder.swift",
"Mutators/ProtocolExtensionReferenceBuilder.swift",
"Mutators/PubliclyAccessibleRetainer.swift",
"Mutators/RedundantExplicitPublicAccessibilityMarker.swift",
"Mutators/RedundantProtocolMarker.swift",
"Mutators/ResultBuilderRetainer.swift",
"Mutators/StringInterpolationAppendInterpolationRetainer.swift",
"Mutators/StructImplicitInitializerReferenceBuilder.swift",
"Mutators/SwiftUIRetainer.swift",
"Mutators/UnusedImportMarker.swift",
"Mutators/UnusedParameterRetainer.swift",
"Mutators/UsedDeclarationMarker.swift",
"Mutators/XCTestRetainer.swift",
"SourceGraph.swift",
"SourceGraphDebugger.swift",
"SourceGraphMutator.swift",
"SourceGraphMutatorRunner.swift",
"SynchronizedSourceGraph.swift",
],
module_name = "SourceGraph",
visibility = ["//visibility:public"],
deps = [
"//Sources/Configuration",
"//Sources/Shared",
"@swift-syntax//:SwiftSyntax",
],
)
23 changes: 23 additions & 0 deletions Sources/SyntaxAnalysis/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
load("@rules_swift//swift:swift.bzl", "swift_library")

swift_library(
name = "SyntaxAnalysis",
srcs = [
"CommentCommand.swift",
"DeclarationSyntaxVisitor.swift",
"ImportSyntaxVisitor.swift",
"MultiplexingSyntaxVisitor.swift",
"SourceLocationBuilder.swift",
"TypeSyntaxInspector.swift",
"UnusedParameterAnalyzer.swift",
"UnusedParameterParser.swift",
],
module_name = "SyntaxAnalysis",
visibility = ["//visibility:public"],
deps = [
"//Sources/Shared",
"//Sources/SourceGraph",
"@swift-syntax//:SwiftParser",
"@swift-syntax//:SwiftSyntax",
],
)
Loading

0 comments on commit a652e3b

Please sign in to comment.