mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2026-03-18 20:02:25 +00:00
move basePath into ProjectSpec
This commit is contained in:
@@ -17,7 +17,6 @@ import ProjectSpec
|
||||
public class PBXProjGenerator {
|
||||
|
||||
let spec: ProjectSpec
|
||||
let basePath: Path
|
||||
let currentXcodeVersion: String
|
||||
|
||||
var fileReferencesByPath: [Path: String] = [:]
|
||||
@@ -38,10 +37,9 @@ public class PBXProjGenerator {
|
||||
return spec.options.carthageBuildPath ?? "Carthage/Build"
|
||||
}
|
||||
|
||||
public init(spec: ProjectSpec, path: Path, currentXcodeVersion: String) {
|
||||
public init(spec: ProjectSpec, currentXcodeVersion: String) {
|
||||
self.currentXcodeVersion = currentXcodeVersion
|
||||
self.spec = spec
|
||||
basePath = path
|
||||
}
|
||||
|
||||
public func generateUUID<T: PBXObject>(_ element: T.Type, _ id: String) -> String {
|
||||
@@ -67,14 +65,14 @@ public class PBXProjGenerator {
|
||||
project = PBXProj(archiveVersion: 1, objectVersion: 46, rootObject: generateUUID(PBXProject.self, spec.name))
|
||||
|
||||
for group in spec.fileGroups {
|
||||
_ = try getGroups(path: basePath + group)
|
||||
_ = try getGroups(path: spec.basePath + group)
|
||||
}
|
||||
|
||||
let buildConfigs: [XCBuildConfiguration] = spec.configs.map { config in
|
||||
let buildSettings = spec.getProjectBuildSettings(config: config)
|
||||
var baseConfigurationReference: String?
|
||||
if let configPath = spec.configFiles[config.name] {
|
||||
baseConfigurationReference = getFileReference(path: basePath + configPath, inPath: basePath)
|
||||
baseConfigurationReference = getFileReference(path: spec.basePath + configPath, inPath: spec.basePath)
|
||||
}
|
||||
return XCBuildConfiguration(reference: generateUUID(XCBuildConfiguration.self, config.name), name: config.name, baseConfigurationReference: baseConfigurationReference, buildSettings: buildSettings)
|
||||
}
|
||||
@@ -159,7 +157,7 @@ public class PBXProjGenerator {
|
||||
|
||||
let carthageDependencies = getAllCarthageDependencies(target: target)
|
||||
|
||||
let sourcePaths = target.sources.map { basePath + $0 }
|
||||
let sourcePaths = target.sources.map { spec.basePath + $0 }
|
||||
var sourceFiles: [SourceFile] = []
|
||||
|
||||
for source in sourcePaths {
|
||||
@@ -177,13 +175,13 @@ public class PBXProjGenerator {
|
||||
|
||||
// automatically set INFOPLIST_FILE path
|
||||
if let plistPath = infoPlists.first,
|
||||
!spec.targetHasBuildSetting("INFOPLIST_FILE", basePath: basePath, target: target, config: config) {
|
||||
buildSettings["INFOPLIST_FILE"] = plistPath.byRemovingBase(path: basePath)
|
||||
!spec.targetHasBuildSetting("INFOPLIST_FILE", basePath: spec.basePath, target: target, config: config) {
|
||||
buildSettings["INFOPLIST_FILE"] = plistPath.byRemovingBase(path: spec.basePath)
|
||||
}
|
||||
|
||||
// automatically calculate bundle id
|
||||
if let bundleIdPrefix = spec.options.bundleIdPrefix,
|
||||
!spec.targetHasBuildSetting("PRODUCT_BUNDLE_IDENTIFIER", basePath: basePath, target: target, config: config) {
|
||||
!spec.targetHasBuildSetting("PRODUCT_BUNDLE_IDENTIFIER", basePath: spec.basePath, target: target, config: config) {
|
||||
let characterSet = CharacterSet.alphanumerics.union(CharacterSet(charactersIn: "-.")).inverted
|
||||
let escapedTargetName = target.name.replacingOccurrences(of: "_", with: "-").components(separatedBy: characterSet).joined(separator: "")
|
||||
buildSettings["PRODUCT_BUNDLE_IDENTIFIER"] = bundleIdPrefix + "." + escapedTargetName
|
||||
@@ -191,7 +189,7 @@ public class PBXProjGenerator {
|
||||
|
||||
// automatically set test target name
|
||||
if target.type == .uiTestBundle,
|
||||
!spec.targetHasBuildSetting("TEST_TARGET_NAME", basePath: basePath, target: target, config: config) {
|
||||
!spec.targetHasBuildSetting("TEST_TARGET_NAME", basePath: spec.basePath, target: target, config: config) {
|
||||
for dependency in target.dependencies {
|
||||
if dependency.type == .target,
|
||||
let dependencyTarget = spec.getTarget(dependency.reference),
|
||||
@@ -219,7 +217,7 @@ public class PBXProjGenerator {
|
||||
|
||||
var baseConfigurationReference: String?
|
||||
if let configPath = target.configFiles[config.name] {
|
||||
baseConfigurationReference = getFileReference(path: basePath + configPath, inPath: basePath)
|
||||
baseConfigurationReference = getFileReference(path: spec.basePath + configPath, inPath: spec.basePath)
|
||||
}
|
||||
return XCBuildConfiguration(reference: generateUUID(XCBuildConfiguration.self, config.name + target.name), name: config.name, baseConfigurationReference: baseConfigurationReference, buildSettings: buildSettings)
|
||||
}
|
||||
@@ -277,7 +275,7 @@ public class PBXProjGenerator {
|
||||
|
||||
case .framework:
|
||||
|
||||
let fileReference = getFileReference(path: Path(dependency.reference), inPath: basePath)
|
||||
let fileReference = getFileReference(path: Path(dependency.reference), inPath: spec.basePath)
|
||||
|
||||
let buildFile = PBXBuildFile(reference: generateUUID(PBXBuildFile.self, fileReference + target.name), fileRef: fileReference)
|
||||
addObject(buildFile)
|
||||
@@ -330,7 +328,7 @@ public class PBXProjGenerator {
|
||||
var shellScript: String
|
||||
switch buildScript.script {
|
||||
case let .path(path):
|
||||
shellScript = try (basePath + path).read()
|
||||
shellScript = try (spec.basePath + path).read()
|
||||
case let .script(script):
|
||||
shellScript = script
|
||||
}
|
||||
@@ -583,7 +581,7 @@ public class PBXProjGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
let groupPath: String = depth == 0 ? path.byRemovingBase(path: basePath).string : path.lastComponent
|
||||
let groupPath: String = depth == 0 ? path.byRemovingBase(path: spec.basePath).string : path.lastComponent
|
||||
let group: PBXGroup
|
||||
if let cachedGroup = groupsByPath[path] {
|
||||
group = cachedGroup
|
||||
|
||||
@@ -16,12 +16,10 @@ import ProjectSpec
|
||||
public class ProjectGenerator {
|
||||
|
||||
var spec: ProjectSpec
|
||||
var path: Path
|
||||
let currentXcodeVersion = "0900"
|
||||
|
||||
public init(spec: ProjectSpec, path: Path) {
|
||||
public init(spec: ProjectSpec) {
|
||||
self.spec = spec
|
||||
self.path = path
|
||||
}
|
||||
|
||||
var defaultDebugConfig: Config {
|
||||
@@ -33,8 +31,8 @@ public class ProjectGenerator {
|
||||
}
|
||||
|
||||
public func generateProject() throws -> XcodeProj {
|
||||
try spec.validate(path: path)
|
||||
let pbxProjGenerator = PBXProjGenerator(spec: spec, path: path, currentXcodeVersion: currentXcodeVersion)
|
||||
try spec.validate()
|
||||
let pbxProjGenerator = PBXProjGenerator(spec: spec, currentXcodeVersion: currentXcodeVersion)
|
||||
let pbxProject = try pbxProjGenerator.generate()
|
||||
let workspace = try generateWorkspace()
|
||||
let sharedData = try generateSharedData(pbxProject: pbxProject)
|
||||
|
||||
@@ -16,7 +16,7 @@ public struct SpecLoader {
|
||||
|
||||
public static func loadSpec(path: Path) throws -> ProjectSpec {
|
||||
let dictionary = try loadDictionary(path: path)
|
||||
return try ProjectSpec(jsonDictionary: dictionary)
|
||||
return try ProjectSpec(basePath: path.parent(), jsonDictionary: dictionary)
|
||||
}
|
||||
|
||||
private static func loadDictionary(path: Path) throws -> JSONDictionary {
|
||||
|
||||
@@ -11,7 +11,7 @@ import PathKit
|
||||
|
||||
extension ProjectSpec {
|
||||
|
||||
public mutating func validate(path: Path) throws {
|
||||
public mutating func validate() throws {
|
||||
|
||||
if configs.isEmpty {
|
||||
configs = [Config(name: "Debug", type: .debug), Config(name: "Release", type: .release)]
|
||||
@@ -32,13 +32,13 @@ extension ProjectSpec {
|
||||
}
|
||||
|
||||
for fileGroup in fileGroups {
|
||||
if !(path + fileGroup).exists {
|
||||
if !(basePath + fileGroup).exists {
|
||||
errors.append(.invalidFileGroup(fileGroup))
|
||||
}
|
||||
}
|
||||
|
||||
for (config, configFile) in configFiles {
|
||||
if !(path + configFile).exists {
|
||||
if !(basePath + configFile).exists {
|
||||
errors.append(.invalidConfigFile(configFile: configFile, config: config))
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ extension ProjectSpec {
|
||||
}
|
||||
|
||||
for (config, configFile) in target.configFiles {
|
||||
if !(path + configFile).exists {
|
||||
if !(basePath + configFile).exists {
|
||||
errors.append(.invalidTargetConfigFile(configFile: configFile, config: config, target: target.name))
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ extension ProjectSpec {
|
||||
}
|
||||
|
||||
for source in target.sources {
|
||||
let sourcePath = path + source
|
||||
let sourcePath = basePath + source
|
||||
if !sourcePath.exists {
|
||||
errors.append(.missingTargetSource(target: target.name, source: sourcePath.string))
|
||||
}
|
||||
@@ -94,7 +94,7 @@ extension ProjectSpec {
|
||||
let scripts = target.prebuildScripts + target.postbuildScripts
|
||||
for script in scripts {
|
||||
if case let .path(pathString) = script.script {
|
||||
let scriptPath = path + pathString
|
||||
let scriptPath = basePath + pathString
|
||||
if !scriptPath.exists {
|
||||
errors.append(.invalidBuildScriptPath(target: target.name, path: pathString))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user