atllbuild.swift 20 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
// Copyright (c) 2016 Anarchy Tools Contributors.
//
// Licensed 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.
Drew's avatar
Drew committed
14

Drew's avatar
Drew committed
15
import Foundation
16
import atpkg
Drew's avatar
Drew committed
17

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
 /**Synthesize a module map.
 - parameter name: The name of the module to synthesize
 - parameter umbrellaHeader: A path to the umbrella header.  The path must be relative to the exported module map file.
 - returns String contents of the synthesized modulemap
 */
 private func synthesizeModuleMap(name: String, umbrellaHeader: String?) -> String {
     var s = ""
     s += "module \(name) {\n"
     if let u = umbrellaHeader {
         s += "  umbrella header \"\(u)\"\n"
     }
     s += "\n"
     s += "}\n"
     return s
 }
Drew's avatar
Drew committed
33

Drew's avatar
Drew committed
34

Drew's avatar
Drew committed
35 36
/**The ATllbuild tool builds a swift module via llbuild.
For more information on this tool, see `docs/attllbuild.md` */
Drew's avatar
Drew committed
37 38
final class ATllbuild : Tool {
    
39 40 41 42 43 44 45
    /**We inject this sourcefile in xctestify=true on OSX
    On Linux, the API requires you to explicitly list tests
    which is not required on OSX.  Injecting this file into test targets
    will enforce that API on OSX as well */
    private static let xcTestCaseProvider: String = { () -> String in
        var s = ""
        s += "import XCTest\n"
46 47
        s += "public func testCase<T: XCTestCase>(allTests: [(String, T -> () throws -> Void)]) -> XCTestCase {\n"
        s += "    fatalError(\"Can't get here.\")\n"
48 49 50 51 52 53 54 55 56
        s += "}\n"
        s += "\n"
        s += "public func XCTMain(testCases: [XCTestCase]) {\n"
        s += "    fatalError(\"Can't get here.\")\n"
        s += "}\n"
        s += "\n"
        return s
    }()
    
57 58 59
    enum OutputType {
        case Executable
        case StaticLibrary
Drew's avatar
Drew committed
60
        case DynamicLibrary
61
    }
Drew's avatar
Drew committed
62 63 64 65 66

    enum ModuleMapType {
        case None
        case Synthesized
    }
67
    
68 69 70 71 72 73 74
    /**
     * Calculates the llbuild.yaml contents for the given configuration options
     *   - parameter sources: A resolved list of swift sources
     *   - parameter workdir: A temporary working directory for `atllbuild` to use
     *   - parameter modulename: The name of the module to be built.
     *   - returns: The string contents for llbuild.yaml suitable for processing by swift-build-tool
     */
Drew's avatar
Drew committed
75
    func llbuildyaml(sources: [String], workdir: String, modulename: String, linkSDK: Bool, compileOptions: [String], linkOptions: [String], outputType: OutputType, linkWithProduct:[String], swiftCPath: String) -> String {
76
        let productPath = workdir + "products/"
Drew's avatar
Drew committed
77 78
        //this format is largely undocumented, but I reverse-engineered it from SwiftPM.
        var yaml = "client:\n  name: swift-build\n\n"
Drew's avatar
Drew committed
79 80 81 82
        
        yaml += "tools: {}\n\n"

        
Drew's avatar
Drew committed
83
        yaml += "targets:\n"
Drew's avatar
Drew committed
84 85 86
        yaml += "  \"\": [<atllbuild>]\n"
        yaml += "  atllbuild: [<atllbuild>]\n"
        
Drew's avatar
Drew committed
87
        //this is the "compile" command
Drew's avatar
Drew committed
88 89 90 91
        
        yaml += "commands:\n"
        yaml += "  <atllbuild-swiftc>:\n"
        yaml += "     tool: swift-compiler\n"
Drew's avatar
Drew committed
92
        yaml += "     executable: \"\(swiftCPath)\"\n"
Drew's avatar
Drew committed
93 94 95 96 97
        yaml += "     inputs: \(sources)\n"
        yaml += "     sources: \(sources)\n"
        
        //swiftPM wants "objects" which is just a list of %.swift.o files.  We have to put them in a temp directory though.
        let objects = sources.map { (source) -> String in
Drew's avatar
Drew committed
98
            workdir + "objects/" + source.toNSString.lastPathComponent + ".o"
Drew's avatar
Drew committed
99 100
        }
        yaml += "     objects: \(objects)\n"
Drew's avatar
Drew committed
101 102
        //this crazy syntax is how llbuild specifies outputs
        var llbuild_outputs = ["<atllbuild-swiftc>"]
103
        llbuild_outputs.append(contentsOf: objects)
Drew's avatar
Drew committed
104
        yaml += "     outputs: \(llbuild_outputs)\n"
105 106 107 108
        
        switch(outputType) {
        case .Executable:
            break
Drew's avatar
Drew committed
109
        case .StaticLibrary, .DynamicLibrary:
110 111
            yaml += "     is-library: true\n" //I have no idea what the effect of this is, but swiftPM does it, so I'm including it.
        }
Drew's avatar
Drew committed
112 113
        
        yaml += "     module-name: \(modulename)\n"
114 115
        let swiftModulePath = "\(productPath + modulename).swiftmodule"
        yaml += "     module-output-path: \(swiftModulePath)\n"
Drew's avatar
Drew committed
116 117 118
        yaml += "     temps-path: \(workdir)/llbuildtmp\n"
        
        var args : [String] = []
119
        args.append(contentsOf: ["-j8", "-D","ATBUILD","-I",workdir+"products/"])
120 121
        
        if linkSDK {
Drew's avatar
Drew committed
122
            #if os(OSX) //we don't have SDKPath on linux
123
            args.append(contentsOf: ["-sdk", SDKPath])
Drew's avatar
Drew committed
124
            #endif
125
        }
126
        args.append(contentsOf: compileOptions)
Drew's avatar
Drew committed
127 128
        
        yaml += "     other-args: \(args)\n"
Drew's avatar
Drew committed
129 130 131
        
        //and this is the "link" command
        yaml += "  <atllbuild>:\n"
132 133 134 135 136
        switch(outputType) {
        case .Executable:
            yaml += "    tool: shell\n"
            //this crazy syntax is how sbt declares a dependency
            var llbuild_inputs = ["<atllbuild-swiftc>"]
137
            llbuild_inputs.append(contentsOf: objects)
Drew's avatar
Drew committed
138
            let builtProducts = linkWithProduct.map {workdir+"products/"+$0}
139
            llbuild_inputs.append(contentsOf: builtProducts)
140
            let executablePath = productPath+modulename
141
            yaml += "    inputs: \(llbuild_inputs)\n"
142
            yaml += "    outputs: [\"<atllbuild>\", \"\(executablePath)\"]\n"
143
            //and now we have the crazy 'args'
Drew's avatar
Drew committed
144
            args = [swiftCPath, "-o",executablePath]
145 146 147
            args.append(contentsOf: objects)
            args.append(contentsOf: builtProducts)
            args.append(contentsOf: linkOptions)
148
            yaml += "    args: \(args)\n"
149 150
            yaml += "    description: Linking executable \(executablePath)\n"
            return yaml
Drew's avatar
Drew committed
151

152 153 154 155
        
        case .StaticLibrary:
            yaml += "    tool: shell\n"
            var llbuild_inputs = ["<atllbuild-swiftc>"]
156
            llbuild_inputs.append(contentsOf: objects)
157
            yaml += "    inputs: \(llbuild_inputs)\n"
158
            let libPath = productPath + modulename + ".a"
159 160 161 162 163 164 165 166 167 168
            yaml += "    outputs: [\"<atllbuild>\", \"\(libPath)\"]\n"
            
            //build the crazy args, mostly consisting of an `ar` shell command
            var shellCmd = "rm -rf \(libPath); ar cr '\(libPath)'"
            for obj in objects {
                shellCmd += " '\(obj)'"
            }
            let args = "[\"/bin/sh\",\"-c\",\(shellCmd)]"
            yaml += "    args: \(args)\n"
            yaml += "    description: \"Linking Library:  \(libPath)\""
169
            return yaml
Drew's avatar
Drew committed
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186

        case .DynamicLibrary:
            yaml += "    tool: shell\n"
            var llbuild_inputs = ["<atllbuild-swiftc>"]
            llbuild_inputs.append(contentsOf: objects)
            let builtProducts = linkWithProduct.map {workdir+"products/"+$0}
            llbuild_inputs.append(contentsOf: builtProducts)
            yaml += "    inputs: \(llbuild_inputs)\n"
            let libPath = productPath + modulename + DynamicLibraryExtension
            yaml += "    outputs: [\"<atllbuild>\", \"\(libPath)\"]\n"
            var args = [swiftCPath, "-o", libPath, "-emit-library"]
            args.append(contentsOf: objects)
            args.append(contentsOf: builtProducts)
            args.append(contentsOf: linkOptions)
            yaml += "    args: \(args)\n"
            yaml += "    description: \"Linking Library:  \(libPath)\""
            return yaml
187
        }
188
     }
Drew's avatar
Drew committed
189
    
Drew's avatar
Drew committed
190 191 192 193
    private enum Options: String {
        case Tool = "tool"
        case Name = "name"
        case Dependencies = "dependencies"
194 195 196
        case OutputType = "output-type"
        case Source = "sources"
        case BootstrapOnly = "bootstrap-only"
Drew's avatar
Drew committed
197
        case llBuildYaml = "llbuildyaml"
198 199 200 201 202
        case CompileOptions = "compile-options"
        case LinkOptions = "link-options"
        case LinkSDK = "link-sdk"
        case LinkWithProduct = "link-with"
        case SwiftCPath = "swiftc-path"
Drew's avatar
Drew committed
203
        case XCTestify = "xctestify"
204
        case XCTestStrict = "xctest-strict"
205
		case IncludeWithUser = "include-with-user"
206
        case PublishProduct = "publish-product"
207
        case UmbrellaHeader = "umbrella-header"
Drew's avatar
Drew committed
208
        case ModuleMap = "module-map"
Drew's avatar
Drew committed
209
        case WholeModuleOptimization = "whole-module-optimization"
210

Drew's avatar
Drew committed
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
        
        static var allOptions : [Options] {
            return [
                Name,
                Dependencies,
                OutputType,
                Source,
                BootstrapOnly,
                llBuildYaml,
                CompileOptions,
                LinkOptions,
                LinkSDK,
                LinkWithProduct,
                SwiftCPath,
                XCTestify,
                XCTestStrict,
227
				IncludeWithUser,
228
                PublishProduct,
Drew's avatar
Drew committed
229 230
				UmbrellaHeader,
                WholeModuleOptimization
Drew's avatar
Drew committed
231 232 233
            ]
        }
    }
Drew's avatar
Drew committed
234

235
    func run(task: Task) {
Drew's avatar
Drew committed
236 237 238 239
        run(task, wmoHack: false)
    }
    
    func run(task: Task, wmoHack : Bool = false) {
240 241
        
        //warn if we don't understand an option
242 243 244 245
        var knownOptions = Options.allOptions.map({$0.rawValue})
        for option in Task.Option.allOptions.map({$0.rawValue}) {
            knownOptions.append(option)
        }
246
        for key in task.allKeys {
247
            if !knownOptions.contains(key) {
Drew's avatar
Drew committed
248
                print("Warning: unknown option \(key) for task \(task.qualifiedName)")
249 250 251
            }
        }
        
Drew's avatar
Drew committed
252 253 254
        //create the working directory
        let workDirectory = ".atllbuild/"
        let manager = NSFileManager.defaultManager()
Drew's avatar
Drew committed
255 256 257 258 259
        
        //NSFileManager is pretty anal about throwing errors if we try to remove something that doesn't exist, etc.
        //We just want to create a state where .atllbuild/objects and .atllbuild/llbuildtmp and .atllbuild/products exists.
        //and in particular, without erasing the product directory, since that accumulates build products across
        //multiple invocations of atllbuild.
Drew's avatar
Drew committed
260
        if Process.arguments.contains("--clean") {
261 262
            let _ = try? manager.removeItem(atPath: workDirectory + "/objects")
            let _ = try? manager.removeItem(atPath: workDirectory + "/llbuildtmp")
Drew's avatar
Drew committed
263
        }
264
        let _ = try? manager.removeItem(atPath: workDirectory + "/include")
265

Drew's avatar
Drew committed
266 267


268 269 270 271
        let _ = try? manager.createDirectory(atPath: workDirectory, withIntermediateDirectories: false, attributes: nil)
        let _ = try? manager.createDirectory(atPath: workDirectory + "/products", withIntermediateDirectories: false, attributes: nil)
        let _ = try? manager.createDirectory(atPath: workDirectory + "/objects", withIntermediateDirectories: false, attributes: nil)
        let _ = try? manager.createDirectory(atPath: workDirectory + "/include", withIntermediateDirectories: false, attributes: nil)
Drew's avatar
Drew committed
272

Drew's avatar
Drew committed
273
        //parse arguments
Drew's avatar
Drew committed
274
        var linkWithProduct: [String] = []
Drew's avatar
Drew committed
275 276 277 278
        if let arr_ = task[Options.LinkWithProduct.rawValue] {
            guard let arr = arr_.vector else {
                fatalError("Non-vector link directive \(arr_)")
            }
Drew's avatar
Drew committed
279
            for product in arr {
Drew's avatar
Drew committed
280 281 282 283
                guard var p = product.string else { fatalError("non-string product \(product)") }
                if p.hasSuffix(".dynamic") {
                    p = p.replacingOccurrences(of: ".dynamic", with: DynamicLibraryExtension)
                }
Drew's avatar
Drew committed
284 285 286
                linkWithProduct.append(p)
            }
        }
Drew's avatar
Drew committed
287

288
        let outputType: OutputType
Drew's avatar
Drew committed
289
        if task[Options.OutputType.rawValue]?.string == "static-library" {
290 291
            outputType = .StaticLibrary
        }
Drew's avatar
Drew committed
292
        else if task[Options.OutputType.rawValue]?.string == "executable" {
293 294
            outputType = .Executable
        }
Drew's avatar
Drew committed
295 296 297
        else if task[Options.OutputType.rawValue]?.string == "dynamic-library" {
            outputType = .DynamicLibrary
        }
298
        else {
299
            fatalError("Unknown \(Options.OutputType.rawValue) \(task["outputType"])")
300 301
        }
        
Drew's avatar
Drew committed
302
        var compileOptions: [String] = []
Drew's avatar
Drew committed
303
        if let opts = task[Options.CompileOptions.rawValue]?.vector {
Drew's avatar
Drew committed
304
            for o in opts {
305
                guard let os = o.string else { fatalError("Compile option \(o) is not a string") }
Drew's avatar
Drew committed
306 307 308
                compileOptions.append(os)
            }
        }
Drew's avatar
Drew committed
309 310 311 312 313

        if wmoHack {
            compileOptions.append("-whole-module-optimization")
        }
        
314
        if let includePaths = task[Options.IncludeWithUser.rawValue]?.vector {
Drew's avatar
Drew committed
315 316 317 318 319 320
            for path_s in includePaths {
                guard let path = path_s.string else { fatalError("Non-string path \(path_s)") }
                compileOptions.append("-I")
                compileOptions.append(userPath() + "/" + path)
            }
        }
Drew's avatar
Drew committed
321
        var linkOptions: [String] = []
Drew's avatar
Drew committed
322
        if let opts = task[Options.LinkOptions.rawValue]?.vector {
Drew's avatar
Drew committed
323 324 325 326 327
            for o in opts {
                guard let os = o.string else { fatalError("Link option \(o) is not a string") }
                linkOptions.append(os)
            }
        }
Drew's avatar
Drew committed
328 329 330

        //check for modulemaps
        for product in linkWithProduct {
331
            let productName = product.componentsSeparated(by: ".")[0]
Drew's avatar
Drew committed
332
            let moduleMapPath = workDirectory + "/products/\(productName).modulemap"
333
            if manager.fileExists(atPath: moduleMapPath) {
Drew's avatar
Drew committed
334 335 336 337 338
                /*per http://clang.llvm.org/docs/Modules.html#command-line-parameters, pretty much
                the only way to do this is to create a file called `module.modulemap`.  That
                potentially conflicts with other modulemaps, so we give it its own directory, namespaced
                by the product name. */
                let pathName = workDirectory + "/include/\(productName)"
339
                try! manager.createDirectory(atPath: pathName, withIntermediateDirectories:false, attributes: nil)
Drew's avatar
Drew committed
340
                try! manager.copyItemAtPath_SWIFTBUG(moduleMapPath, toPath: pathName + "/module.modulemap")
341
                compileOptions.append(contentsOf: ["-I",pathName])
Drew's avatar
Drew committed
342 343 344
            }
        }

Drew's avatar
Drew committed
345
        guard let sourceDescriptions = task[Options.Source.rawValue]?.vector?.flatMap({$0.string}) else { fatalError("Can't find sources for atllbuild.") }
Drew's avatar
Drew committed
346
        var sources = collectSources(sourceDescriptions, taskForCalculatingPath: task)
347
        
Drew's avatar
Drew committed
348
        //xctestify
Drew's avatar
Drew committed
349
        if task[Options.XCTestify.rawValue]?.bool == true {
350
            precondition(outputType == .Executable, "You must use :\(Options.OutputType.rawValue) executable with xctestify.")
Drew's avatar
Drew committed
351 352
            //inject platform-specific flags
            #if os(OSX)
353 354
                compileOptions.append(contentsOf: ["-F", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/"])
                linkOptions.append(contentsOf: ["-F", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/", "-target", "x86_64-apple-macosx10.11", "-Xlinker", "-rpath", "-Xlinker", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/", "-Xlinker", "-bundle"])
355 356
            #endif
        }
Drew's avatar
Drew committed
357
        if task[Options.XCTestStrict.rawValue]?.bool == true {
358 359 360
            #if os(OSX)
            //inject XCTestCaseProvider.swift
            var xcTestCaseProviderPath = "/tmp/XXXXXXX"
361 362 363
            var template = xcTestCaseProviderPath.cString(usingEncoding: NSUTF8StringEncoding)!
            xcTestCaseProviderPath = String(cString: mkdtemp(&template), encoding: NSUTF8StringEncoding)!

364
            xcTestCaseProviderPath += "/XCTestCaseProvider.swift"
365 366

            try! ATllbuild.xcTestCaseProvider.write(toFile: xcTestCaseProviderPath, atomically: false, encoding: NSUTF8StringEncoding)
367
            sources.append(xcTestCaseProviderPath)
Drew's avatar
Drew committed
368 369
            #endif
        }
Drew's avatar
Drew committed
370 371 372 373 374 375 376
        let moduleMap: ModuleMapType
        if task[Options.ModuleMap.rawValue]?.string == "synthesized" {
            moduleMap = .Synthesized
        }
        else {
            moduleMap = .None
        }
Drew's avatar
Drew committed
377

Drew's avatar
Drew committed
378
        guard let name = task[Options.Name.rawValue]?.string else { fatalError("No name for atllbuild task") }
Drew's avatar
Drew committed
379
        
380
        if let umbrellaHeader = task[Options.UmbrellaHeader.rawValue]?.string {
Drew's avatar
Drew committed
381 382
            precondition(moduleMap == .Synthesized, ":\(Options.UmbrellaHeader.rawValue) \"synthesized\" must be used with the \(Options.UmbrellaHeader.rawValue) option")
            let s = synthesizeModuleMap(name, umbrellaHeader: "Umbrella.h")
383
            try! s.write(toFile: workDirectory+"/include/module.modulemap", atomically: false, encoding: NSUTF8StringEncoding)
Drew's avatar
Drew committed
384
            try! manager.copyItemAtPath_SWIFTBUG(task.importedPath + umbrellaHeader, toPath: workDirectory + "/include/Umbrella.h")
385 386 387 388 389
            compileOptions.append("-I")
            compileOptions.append(workDirectory + "/include/")
            compileOptions.append("-import-underlying-module")
        }
        
Drew's avatar
Drew committed
390
        let bootstrapOnly: Bool
Drew's avatar
Drew committed
391

Drew's avatar
Drew committed
392
        if task[Options.BootstrapOnly.rawValue]?.bool == true {
Drew's avatar
Drew committed
393 394 395 396 397 398
            bootstrapOnly = true
        }
        else {
            bootstrapOnly = false
        }
        
399
        let sdk: Bool
Drew's avatar
Drew committed
400
        if task[Options.LinkSDK.rawValue]?.bool == false {
401 402 403 404
            sdk = false
        }
        else { sdk = true }
        
Drew's avatar
Drew committed
405
        let llbuildyamlpath : String
Drew's avatar
Drew committed
406

Drew's avatar
Drew committed
407
        if let value = task[Options.llBuildYaml.rawValue]?.string {
408
            llbuildyamlpath = value
Drew's avatar
Drew committed
409 410 411 412
        }
        else {
            llbuildyamlpath = workDirectory + "llbuild.yaml"
        }
Drew's avatar
Drew committed
413 414

        let swiftCPath: String
Drew's avatar
Drew committed
415
        if let c = task[Options.SwiftCPath.rawValue]?.string {
Drew's avatar
Drew committed
416 417 418 419 420
            swiftCPath = c
        }
        else {
            swiftCPath = SwiftCPath
        }
Drew's avatar
Drew committed
421
        
Drew's avatar
Drew committed
422
        let yaml = llbuildyaml(sources, workdir: workDirectory, modulename: name, linkSDK: sdk, compileOptions: compileOptions, linkOptions: linkOptions, outputType: outputType, linkWithProduct: linkWithProduct, swiftCPath: swiftCPath)
423
        let _ = try? yaml.write(toFile: llbuildyamlpath, atomically: false, encoding: NSUTF8StringEncoding)
Drew's avatar
Drew committed
424
        if bootstrapOnly { return }
Drew's avatar
Drew committed
425 426 427 428 429 430

        switch moduleMap {
                case .None:
                break
                case .Synthesized:
                let s = synthesizeModuleMap(name, umbrellaHeader: nil)
431
                try! s.write(toFile: workDirectory + "/products/\(name).modulemap", atomically: false, encoding: NSUTF8StringEncoding)
Drew's avatar
Drew committed
432
        }
Drew's avatar
Drew committed
433
        
Drew's avatar
Drew committed
434 435 436 437
        //SR-566
        let cmd = "\(SwiftBuildToolpath) -f \(llbuildyamlpath)"
        if system(cmd) != 0 {
            fatalError(cmd)
Drew's avatar
Drew committed
438
        }
Drew's avatar
Drew committed
439
        if task[Options.PublishProduct.rawValue]?.bool == true {
440 441
            if !manager.fileExists(atPath: "bin") {
                try! manager.createDirectory(atPath: "bin", withIntermediateDirectories: false, attributes: nil)
Drew's avatar
Drew committed
442 443 444 445 446 447 448
            }
            try! copyByOverwriting("\(workDirectory)/products/\(name).swiftmodule", toPath: "bin/\(name).swiftmodule")
            switch outputType {
            case .Executable:
                try! copyByOverwriting("\(workDirectory)/products/\(name)", toPath: "bin/\(name)")
            case .StaticLibrary:
                try! copyByOverwriting("\(workDirectory)/products/\(name).a", toPath: "bin/\(name).a")
Drew's avatar
Drew committed
449 450
            case .DynamicLibrary:
                try! copyByOverwriting("\(workDirectory)/products/\(name).\(DynamicLibraryExtension)", toPath: "bin/\(name).\(DynamicLibraryExtension)")
Drew's avatar
Drew committed
451
            }
Drew's avatar
Drew committed
452 453 454 455 456 457
            switch moduleMap {
                case .None:
                break
                case .Synthesized:
                try! copyByOverwriting("\(workDirectory)/products/\(name).modulemap", toPath: "bin/\(name).modulemap")
            }
Drew's avatar
Drew committed
458
        }
Drew's avatar
Drew committed
459 460 461 462 463 464

        if task[Options.WholeModuleOptimization.rawValue]?.bool == true && !wmoHack {
            print("Work around SR-881")
            run(task, wmoHack: true)
        }

Drew's avatar
Drew committed
465 466 467 468 469
    }
}

private func copyByOverwriting(fromPath: String, toPath: String) throws {
    let manager = NSFileManager.defaultManager()
470 471
    if manager.fileExists(atPath: toPath) {
        try manager.removeItem(atPath: toPath)
Drew's avatar
Drew committed
472
    }
473
    try! manager.copyItemAtPath_SWIFTBUG(fromPath, toPath: toPath)
Drew's avatar
Drew committed
474
}