diff --git a/Package.swift b/Package.swift index 3f4b86bf..12d0dd22 100644 --- a/Package.swift +++ b/Package.swift @@ -1,12 +1,12 @@ import PackageDescription -#if os(OSX) let package = Package( name: "RxSwift", targets: [ Target( name: "RxSwift" ), + Target( name: "RxCocoa", dependencies: [ @@ -30,39 +30,15 @@ let package = Package( dependencies: [ .Target(name: "RxSwift"), .Target(name: "RxBlocking"), + .Target(name: "RxCocoa"), .Target(name: "RxTests") ] ) ] ) +#if os(OSX) + package.exclude = ["Sources/RxCocoa", "Sources/RxTests", "Sources/AllTests"] #elseif os(Linux) -let package = Package( - name: "RxSwift", - targets: [ - Target( - name: "RxSwift" - ), - Target( - name: "RxTests", - dependencies: [ - .Target(name: "RxSwift") - ] - ), - Target( - name: "RxBlocking", - dependencies: [ - .Target(name: "RxSwift") - ] - ), - Target( - name: "AllTests", - dependencies: [ - .Target(name: "RxSwift"), - .Target(name: "RxBlocking"), - .Target(name: "RxTests") - ] - ) - ] -) + package.exclude = ["Sources/RxCocoa"] #else #endif diff --git a/Rx.xcworkspace/contents.xcworkspacedata b/Rx.xcworkspace/contents.xcworkspacedata index 3f37983c..145caa31 100644 --- a/Rx.xcworkspace/contents.xcworkspacedata +++ b/Rx.xcworkspace/contents.xcworkspacedata @@ -72,6 +72,9 @@ + + Bool { + return (allowedExtensions.map { path.hasSuffix($0) }).reduce(false) { $0 || $1 } +} + +func checkExtension(path: String) throws { + if !isExtensionAllowed(path) { + throw NSError(domain: "Security", code: -1, userInfo: ["path" : path]) + } +} + +func packageRelativePath(paths: [String], targetDirName: String) throws { + let targetPath = "Sources/\(targetDirName)" + + print(targetPath) + + for file in try fileManager.contentsOfDirectoryAtPath(targetPath) { + try checkExtension(file) + + print("Cleaning \(file)") + try fileManager.removeItemAtPath("\(targetPath)/\(file)") + } + + for sourcePath in paths { + var isDirectory: ObjCBool = false + fileManager.fileExistsAtPath(sourcePath, isDirectory: &isDirectory) + + let files = isDirectory ? try fileManager.subpathsOfDirectoryAtPath(sourcePath) + : [sourcePath] + + for file in files { + if !isExtensionAllowed(file) { + continue + } + + let fileRelativePath = isDirectory ? "\(sourcePath)/\(file)" : file + + let destinationURL = NSURL(string: "../../\(fileRelativePath)")! + + let fileName = (file as NSString).lastPathComponent + let atURL = NSURL(string: "file:///\(fileManager.currentDirectoryPath)/\(targetPath)/\(fileName)")! + + print("Linking \(fileName) [\(atURL)] -> \(destinationURL)") + try fileManager.createSymbolicLinkAtURL(atURL, withDestinationURL: destinationURL) + } + } +} + +try packageRelativePath(["RxSwift"], targetDirName: "RxSwift") +try packageRelativePath(["RxCocoa/Common", "RxCocoa/OSX", "RxCocoa/RxCocoa.h"], targetDirName: "RxCocoa") +try packageRelativePath(["RxBlocking"], targetDirName: "RxBlocking") +try packageRelativePath(["RxTests"], targetDirName: "RxTests") +// It doesn't work under `Tests` subpath ¯\_(ツ)_/¯ +try packageRelativePath(["Tests"], targetDirName: "AllTests") \ No newline at end of file