Skip to content

Commit a9f49d7

Browse files
Test and app specs base support (sergiikhliustin#112)
* Test and app specs base support * Update tests * Fix integration tests
1 parent 844abfb commit a9f49d7

File tree

98 files changed

+7577
-1151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+7577
-1151
lines changed

.swiftlint.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ disabled_rules:
99
- operator_whitespace
1010
- nesting
1111
- file_length
12+
- type_name
1213

1314
line_length:
1415
ignores_comments: true
@@ -19,5 +20,5 @@ force_cast:
1920
force_try:
2021
severity: warning
2122
function_parameter_count:
22-
warning: 8
23-
error: 10
23+
warning: 10
24+
error: 12

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ integration:
3838

3939
prepare-tests:
4040
swift TestTools/generate_podfile.swift TestTools/Pods.json TestTools/Podfile_template > Tests/Podfile
41-
cd Tests && pod install || pod install --repo-update
41+
cd Tests && bundle exec pod install || bundle exec pod install --repo-update
4242
bazel run :bazelpods $(CONFIG) -- \
4343
--src "$(shell pwd)/Tests" \
4444
--deps-prefix "//Tests/Pods" \
@@ -93,7 +93,7 @@ record-tests:
9393

9494
integration-setup:
9595
swift TestTools/generate_podfile.swift TestTools/Pods_Integration.json TestTools/Podfile_template > IntegrationTests/Podfile
96-
cd IntegrationTests && pod install
96+
cd IntegrationTests && bundle exec pod install
9797
swift TestTools/generate_buildfile.swift TestTools/Pods_Integration.json TestTools/BUILD_template //IntegrationTests > IntegrationTests/BUILD.bazel
9898

9999
integration-generate-static:

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ Core idea, Podspec parser, Starlark compiler are forked from [PodToBUILD](https:
1616
| vendored frameworks |||||
1717
| vendored xcframeworks |||||
1818
| bundles and resources |||||
19-
| [rules_xcodeproj](https://github.com/buildbuddy-io/rules_xcodeproj) |||||
19+
| [rules_xcodeproj](https://github.com/MobileNativeFoundation/rules_xcodeproj) |||||
20+
| tests specs | Beta ||||
21+
| app specs | Beta ||||
2022

21-
###### ✅ - full support (report issues if no), 🔜 - not yet supported, ❓ - unknown, ❌ - not supported
23+
###### ✅ - full support (report issues if no), 🔜 - not yet supported, ❓ - unknown, ❌ - not supported
2224

2325
- [x] Autodetect vendored frameworks and libs architectures and ignore unsupported
2426
- [x] Local pods with custom paths, private pods (resolved by CocoaPods)
25-
- [ ] Nested subspecs (possibly works, but not tested yet)
27+
- [x] Test and app specs 🚀
2628

2729
### 🎸 Let's rock
2830
Don't forget to setup [`rules_ios`](https://github.com/bazel-ios/rules_ios) and [`rules_apple`](https://github.com/bazelbuild/rules_apple) first.
@@ -92,19 +94,24 @@ OPTIONS:
9294
If 'user_options' not specified, but --user_options exist, user_options patch are applied automatically.
9395
--user-options <user-options>
9496
User extra options.
95-
Supported fields: 'sdk_frameworks', 'sdk_dylibs', 'weak_sdk_frameworks', 'vendored_libraries', 'vendored_frameworks', 'vendored_xcframeworks', 'testonly', 'link_dynamic'.
97+
Supported fields: 'sdk_frameworks', 'sdk_dylibs', 'weak_sdk_frameworks', 'vendored_libraries', 'vendored_frameworks', 'vendored_xcframeworks', 'testonly', 'link_dynamic', 'runner'.
9698
Supported operators: '+=' (append), '-=' (delete), ':=' (replace).
9799
Example:
98100
'SomePod.sdk_dylibs += something,something'
99101
'SomePod.testonly := true'
100102
Platform specific:
101103
'SomePod.platform_ios.sdk_dylibs += something,something'
104+
For test specs:
105+
'SomePod/UnitTests.runner := //:SomeTestsRunner'
102106
--deps-prefix <deps-prefix>
103107
Dependencies prefix (default: //Pods)
104108
--pods-root <pods-root> Pods root relative to workspace. Used for headers search paths (default: Pods)
105109
-f, --frameworks Packaging pods in dynamic frameworks if possible (same as `use_frameworks!`)
106110
--no-concurrency Disable concurrency.
107111
--log-level <log-level> Log level (debug|info|warning|error|none) (default: info)
112+
--use-bundler Option to use `bundle exec` for `pod` calls
113+
--tests-timeout <tests-timeout>
114+
(Optional) Default timeout for test targets (short|moderate|long|eternal)
108115
--pods-json <pods-json> Pods.json (default: Pods/Pods.json)
109116
--print-output Print BUILD files contents to terminal output
110117
--dry-run Dry run. Files will not be written
@@ -117,7 +124,7 @@ Compile
117124
```
118125
OVERVIEW: Compiles podspec.json to BUILD file
119126
120-
USAGE: bazelpods compile --src <src> [--platforms <platforms> ...] [--min-ios <min-ios>] [--patches <patches> ...] [--user-options <user-options> ...] [--deps-prefix <deps-prefix>] [--pods-root <pods-root>] [--frameworks] [--no-concurrency] [--log-level <log-level>] --podspec <podspec> [--subspecs <subspecs> ...]
127+
USAGE: bazelpods compile [<options>] --src <src> --podspec <podspec>
121128
122129
OPTIONS:
123130
--src <src> Sources root where Pods directory located (or renamed by podsRoot)
@@ -130,19 +137,24 @@ OPTIONS:
130137
If 'user_options' not specified, but --user_options exist, user_options patch are applied automatically.
131138
--user-options <user-options>
132139
User extra options.
133-
Supported fields: 'sdk_frameworks', 'sdk_dylibs', 'weak_sdk_frameworks', 'vendored_libraries', 'vendored_frameworks', 'vendored_xcframeworks', 'testonly', 'link_dynamic'.
140+
Supported fields: 'sdk_frameworks', 'sdk_dylibs', 'weak_sdk_frameworks', 'vendored_libraries', 'vendored_frameworks', 'vendored_xcframeworks', 'testonly', 'link_dynamic', 'runner'.
134141
Supported operators: '+=' (append), '-=' (delete), ':=' (replace).
135142
Example:
136143
'SomePod.sdk_dylibs += something,something'
137144
'SomePod.testonly := true'
138145
Platform specific:
139146
'SomePod.platform_ios.sdk_dylibs += something,something'
147+
For test specs:
148+
'SomePod/UnitTests.runner := //:SomeTestsRunner'
140149
--deps-prefix <deps-prefix>
141150
Dependencies prefix (default: //Pods)
142151
--pods-root <pods-root> Pods root relative to workspace. Used for headers search paths (default: Pods)
143152
-f, --frameworks Packaging pods in dynamic frameworks if possible (same as `use_frameworks!`)
144153
--no-concurrency Disable concurrency.
145154
--log-level <log-level> Log level (debug|info|warning|error|none) (default: info)
155+
--use-bundler Option to use `bundle exec` for `pod` calls
156+
--tests-timeout <tests-timeout>
157+
(Optional) Default timeout for test targets (short|moderate|long|eternal)
146158
--podspec <podspec> podspec.json
147159
--subspecs <subspecs> Subspecs list
148160
-h, --help Show help information.

Sources/BazelPods/Arm64sim.swift

Lines changed: 0 additions & 83 deletions
This file was deleted.

Sources/BazelPods/BazelPods.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Logger
1313
extension Platform: ExpressibleByArgument {}
1414
extension LogLevel: ExpressibleByArgument {}
1515
extension PatchType: ExpressibleByArgument {}
16+
extension TestsTimeout: ExpressibleByArgument {}
1617

1718
func absolutePath(_ path: String, base: String) -> String {
1819
guard !path.starts(with: "/") else { return path }
@@ -101,7 +102,7 @@ struct BazelPods: ParsableCommand {
101102
static var configuration = CommandConfiguration(
102103
commandName: "bazelpods",
103104
abstract: "One more way to convert CocoaPods into Bazel.",
104-
subcommands: [Generate.self, Compile.self, Arm64sim.self],
105+
subcommands: [Generate.self, Compile.self],
105106
defaultSubcommand: Generate.self)
106107

107108
struct Options: ParsableArguments {
@@ -137,6 +138,8 @@ Example:
137138
'SomePod.testonly := true'
138139
Platform specific:
139140
'SomePod.platform_ios.sdk_dylibs += something,something'
141+
For test specs:
142+
'SomePod/UnitTests.runner := //:SomeTestsRunner'
140143
"""
141144
)
142145
var userOptions: [String] = []
@@ -158,5 +161,8 @@ Platform specific:
158161

159162
@Flag(help: "Option to use `bundle exec` for `pod` calls")
160163
var useBundler: Bool = false
164+
165+
@Option(help: "(Optional) Default timeout for test targets (\(TestsTimeout.allCases.map({ $0.rawValue }).joined(separator: "|")))")
166+
var testsTimeout: TestsTimeout?
161167
}
162168
}

Sources/BazelPods/Compile.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ extension BazelPods {
5353
podsRoot: options.podsRoot,
5454
useFrameworks: options.frameworks,
5555
noConcurrency: options.noConcurrency,
56-
hostArm64: isHostArm64)
56+
hostArm64: isHostArm64,
57+
testsTimeout: options.testsTimeout)
5758

5859
let result = PodBuildFile.with(podSpec: podSpec, buildOptions: options).compile()
5960
print(result)

Sources/BazelPods/Generate.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ extension BazelPods {
127127
podsRoot: options.podsRoot,
128128
useFrameworks: options.frameworks,
129129
noConcurrency: options.noConcurrency,
130-
hostArm64: isHostArm64)
130+
hostArm64: isHostArm64,
131+
testsTimeout: options.testsTimeout)
131132
let starlarkString = PodBuildFile
132133
.with(podSpec: podSpec, buildOptions: buildOptions)
133134
.compile()

Sources/BazelPodsCore/Analyzer/Analyzer.swift

Lines changed: 0 additions & 82 deletions
This file was deleted.

Sources/BazelPodsCore/Analyzer/Analyzers/BaseAnalyzer.swift

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,25 @@
77

88
import Foundation
99

10-
public struct BaseAnalyzer {
11-
public struct Result {
10+
struct BaseAnalyzer<S: BaseInfoRepresentable> {
11+
struct Result {
1212
let name: String
1313
let version: String
1414
let moduleName: String
1515
let platforms: [String: String]
16+
let minimumOsVersion: String
1617
let swiftVersion: String?
1718
}
1819

1920
private let platform: Platform
20-
private let spec: PodSpec
21-
private let subspecs: [PodSpec]
21+
private let spec: S
22+
private let subspecs: [S]
2223
private let options: BuildOptions
2324

24-
public init(platform: Platform,
25-
spec: PodSpec,
26-
subspecs: [PodSpec],
27-
options: BuildOptions) {
25+
init(platform: Platform,
26+
spec: S,
27+
subspecs: [S],
28+
options: BuildOptions) {
2829
self.platform = platform
2930
self.spec = spec
3031
self.subspecs = subspecs
@@ -33,14 +34,9 @@ public struct BaseAnalyzer {
3334

3435
public func run() throws -> Result {
3536
let name = spec.name
36-
let version = spec.version ?? "1.0"
37+
let version = spec.version
3738
let platformVersion = try resolvePlatformVersion(platform)
38-
let moduleName: String
39-
if let specModuleName = spec.moduleName ?? spec.platformRepresentable(platform)?.moduleName {
40-
moduleName = specModuleName
41-
} else {
42-
moduleName = name.replacingOccurrences(of: "-", with: "_")
43-
}
39+
let moduleName: String = spec.resolveModuleName(platform)
4440
let platforms = [platform.bazelKey: platformVersion]
4541
let swiftVersion: String?
4642
if let versions = spec.attr(\.swiftVersions).platform(platform)??.compactMap({ Double($0) }) {
@@ -60,6 +56,7 @@ public struct BaseAnalyzer {
6056
version: version,
6157
moduleName: moduleName,
6258
platforms: platforms,
59+
minimumOsVersion: platformVersion,
6360
swiftVersion: swiftVersion)
6461
}
6562

0 commit comments

Comments
 (0)