-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b441f46
commit 3f0f121
Showing
53 changed files
with
6,038 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
|
||
build \ | ||
--announce_rc \ | ||
--spawn_strategy=local \ | ||
--strategy=SwiftCompile=worker \ | ||
--verbose_failures \ | ||
--apple_platform_type=macos \ | ||
--compilation_mode=dbg \ | ||
--features=swift.use_global_module_cache | ||
build --announce_rc | ||
build --spawn_strategy=local | ||
build --strategy=SwiftCompile=worker | ||
build --verbose_failures | ||
build --apple_platform_type=macos | ||
build --compilation_mode=dbg | ||
build --features=swift.use_global_module_cache | ||
build --objc_enable_binary_stripping=true | ||
build --features=dead_strip | ||
build --experimental_multi_threaded_digest | ||
build --disk_cache=./bazel-cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// MainCommand.swift | ||
// PodToBUILD | ||
// | ||
// Created by Sergey Khliustin on 26.08.2022. | ||
// | ||
|
||
import Foundation | ||
import ArgumentParser | ||
import PodToBUILD | ||
import ObjcSupport | ||
|
||
extension String: LocalizedError { | ||
public var errorDescription: String? { return self } | ||
} | ||
|
||
struct RootCommand: ParsableCommand { | ||
static var configuration = CommandConfiguration(commandName: "Compiler", abstract: "Compiles podspec.json to BUILD file") | ||
@Argument(help: "podspec.json", completion: .file(extensions: ["json"])) | ||
var podspecJson: String | ||
|
||
@Option(name: .long, help: "Sources root") | ||
var src: String? | ||
|
||
@Option(name: .long, parsing: .upToNextOption, help: "Subspecs list") | ||
var subspecs: [String] = [] | ||
|
||
@Option(name: .long, help: "Minimum iOS version if not listed in podspec") | ||
var minIos: String = "13.0" | ||
|
||
func run() throws { | ||
_ = CrashReporter() | ||
let jsonData = try NSData(contentsOfFile: podspecJson, options: []) as Data | ||
let jsonFile = try JSONSerialization.jsonObject(with: jsonData, options: .allowFragments) as AnyObject | ||
|
||
guard let jsonPodspec = jsonFile as? JSONDict else { | ||
throw "Error parsing podspec at path \(podspecJson)" | ||
} | ||
|
||
let podSpec = try PodSpec(JSONPodspec: jsonPodspec) | ||
|
||
let podSpecURL = NSURL(fileURLWithPath: podspecJson) | ||
let assumedPodName = podSpecURL.lastPathComponent!.components(separatedBy: ".")[0] | ||
let options = BasicBuildOptions(podName: assumedPodName, | ||
subspecs: subspecs, | ||
iosPlatform: minIos) | ||
|
||
let result = PodBuildFile.with(podSpec: podSpec, buildOptions: options).compile() | ||
print(result) | ||
} | ||
|
||
func absolutePath(_ path: String) -> String { | ||
guard let src = src else { return path } | ||
guard !path.starts(with: "/") else { return path } | ||
return (src as NSString).appendingPathComponent(path) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
RootCommand.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// PodConfig.swift | ||
// PodToBUILD | ||
// | ||
// Created by Sergey Khliustin on 25.08.2022. | ||
// | ||
|
||
import Foundation | ||
|
||
struct PodConfig: Decodable { | ||
let name: String | ||
let podspec: String | ||
let development: Bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// PodSpecification.swift | ||
// PodToBUILD | ||
// | ||
// Created by Sergey Khliustin on 25.08.2022. | ||
// | ||
|
||
import Foundation | ||
import PodToBUILD | ||
|
||
struct PodSpecification { | ||
let name: String | ||
let subspecs: [String] | ||
let podspec: String | ||
let development: Bool | ||
|
||
static func resolve(with podConfigsMap: [String: PodConfig]) -> [PodSpecification] { | ||
let podConfigs = Array(podConfigsMap.values) | ||
let (podspecPaths, subspecsByPodName) = | ||
podConfigs.reduce(([String: String](), [String: [String]]())) { partialResult, podConfig in | ||
var podspecPaths = partialResult.0 | ||
var subspecsByPodName = partialResult.1 | ||
|
||
let components = podConfig.name.components(separatedBy: "/") | ||
guard let podName = components.first else { | ||
return partialResult | ||
} | ||
|
||
podspecPaths[podName] = podConfig.podspec | ||
|
||
if components.count == 2, let subspecName = components.last { | ||
var subspecs = subspecsByPodName[podName] ?? [] | ||
subspecs.append(subspecName) | ||
subspecsByPodName[podName] = subspecs | ||
} | ||
return (podspecPaths, subspecsByPodName) | ||
} | ||
return podspecPaths.map({ | ||
PodSpecification(name: $0.key, subspecs: subspecsByPodName[$0.key] ?? [], podspec: $0.value, development: podConfigsMap[$0.key]?.development ?? false) | ||
}) | ||
} | ||
|
||
func toBuildOptions(src: String, ios: String) -> BuildOptions { | ||
let path = (src as NSString).appendingPathComponent("Pods/\(name)") | ||
return BasicBuildOptions(podName: name, subspecs: subspecs, podspecPath: podspec, sourcePath: path, iosPlatform: ios) | ||
} | ||
} |
Oops, something went wrong.