forked from spotify/XCRemoteCache
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXCSwiftFrontend.swift
More file actions
80 lines (71 loc) · 3.2 KB
/
XCSwiftFrontend.swift
File metadata and controls
80 lines (71 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2023 Spotify AB.
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
import Foundation
public class XCSwiftFrontend: XCSwiftAbstract<SwiftFrontendArgInput> {
// don't lock individual compilation invocations for more than 10s
private static let MaxLockingTimeout: TimeInterval = 10
private let env: [String: String]
public init(
command: String,
inputArgs: SwiftFrontendArgInput,
env: [String: String],
dependenciesWriter: @escaping (URL, FileManager) -> DependenciesWriter,
touchFactory: @escaping (URL, FileManager) -> Touch
) throws {
self.env = env
super.init(
command: command,
inputArgs: inputArgs,
dependenciesWriter: dependenciesWriter,
touchFactory: touchFactory
)
}
override func buildContext() throws -> (XCRemoteCacheConfig, SwiftcContext) {
let fileManager = FileManager.default
let config: XCRemoteCacheConfig
let context: SwiftcContext
let srcRoot: URL = URL(fileURLWithPath: fileManager.currentDirectoryPath)
config = try XCRemoteCacheConfigReader(srcRootPath: srcRoot.path, fileReader: fileManager)
.readConfiguration()
context = try SwiftcContext(config: config, input: inputArgs)
// do not cache this context, as it is subject to change when
// the emit-module finds that the cached artifact cannot be used
return (config, context)
}
override public func run() throws {
do {
let (_, context) = try buildContext()
let frontendContext = try SwiftFrontendContext(context, env: env)
let sharedLock = ExclusiveFile(frontendContext.invocationLockFile, mode: .override)
let action: CommonSwiftFrontendOrchestrator.Action = inputArgs.emitModule ? .emitModule : .compile
let swiftFrontendOrchestrator = CommonSwiftFrontendOrchestrator(
mode: context.mode,
action: action,
lockAccessor: sharedLock,
maxLockTimeout: Self.self.MaxLockingTimeout
)
try swiftFrontendOrchestrator.run(criticalSection: super.run)
} catch {
// Splitting into 2 invocations as os_log truncates a massage
defaultLog("Cannot correctly orchestrate the \(command) with params \(inputArgs)")
defaultLog("Cannot correctly orchestrate error: \(error)")
throw error
}
}
}