mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2024-12-11 07:16:40 +03:00
Merge pull request #681 from giginet/project-path
Resolving relative paths with custom project destination
This commit is contained in:
commit
5b5d0e917e
@ -16,6 +16,7 @@
|
||||
- Add `rcproject` files to sources build phase instead of resources [#669](https://github.com/yonaskolb/XcodeGen/pull/669) @Qusic
|
||||
- Prefer default configuration names for generated schemes [#673](https://github.com/yonaskolb/XcodeGen/pull/673) @giginet
|
||||
- Fixed some resource files being placed to "Recovered References" group [#679](https://github.com/yonaskolb/XcodeGen/pull/679) @nivanchikov
|
||||
- Fixed resolving relative paths with custom project destination [#681](https://github.com/yonaskolb/XcodeGen/pull/681) @giginet
|
||||
|
||||
#### Internal
|
||||
- Updated to SwiftCLI 5.3.2 [#667](https://github.com/yonaskolb/XcodeGen/pull/667) @giginet
|
||||
|
@ -125,7 +125,7 @@ class GenerateCommand: Command {
|
||||
let xcodeProject: XcodeProj
|
||||
do {
|
||||
let projectGenerator = ProjectGenerator(project: project)
|
||||
xcodeProject = try projectGenerator.generateXcodeProject()
|
||||
xcodeProject = try projectGenerator.generateXcodeProject(in: projectDirectory)
|
||||
} catch {
|
||||
throw GenerationError.generationError(error)
|
||||
}
|
||||
|
@ -24,11 +24,13 @@ public class PBXProjGenerator {
|
||||
|
||||
var generated = false
|
||||
|
||||
public init(project: Project) {
|
||||
public init(project: Project, projectDirectory: Path? = nil) {
|
||||
self.project = project
|
||||
carthageResolver = CarthageDependencyResolver(project: project)
|
||||
pbxProj = PBXProj(rootObject: nil, objectVersion: project.objectVersion)
|
||||
sourceGenerator = SourceGenerator(project: project, pbxProj: pbxProj)
|
||||
sourceGenerator = SourceGenerator(project: project,
|
||||
pbxProj: pbxProj,
|
||||
projectDirectory: projectDirectory)
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
|
@ -13,10 +13,11 @@ public class ProjectGenerator {
|
||||
self.project = project
|
||||
}
|
||||
|
||||
public func generateXcodeProject() throws -> XcodeProj {
|
||||
public func generateXcodeProject(in projectDirectory: Path? = nil) throws -> XcodeProj {
|
||||
|
||||
// generate PBXProj
|
||||
let pbxProjGenerator = PBXProjGenerator(project: project)
|
||||
let pbxProjGenerator = PBXProjGenerator(project: project,
|
||||
projectDirectory: projectDirectory)
|
||||
let pbxProj = try pbxProjGenerator.generate()
|
||||
|
||||
// generate Schemes
|
||||
|
@ -13,6 +13,7 @@ struct SourceFile {
|
||||
class SourceGenerator {
|
||||
|
||||
var rootGroups: Set<PBXFileElement> = []
|
||||
private let projectDirectory: Path?
|
||||
private var fileReferencesByPath: [String: PBXFileElement] = [:]
|
||||
private var groupsByPath: [Path: PBXGroup] = [:]
|
||||
private var variantGroupsByPath: [Path: PBXVariantGroup] = [:]
|
||||
@ -30,9 +31,18 @@ class SourceGenerator {
|
||||
|
||||
private(set) var knownRegions: Set<String> = []
|
||||
|
||||
init(project: Project, pbxProj: PBXProj) {
|
||||
init(project: Project, pbxProj: PBXProj, projectDirectory: Path?) {
|
||||
self.project = project
|
||||
self.pbxProj = pbxProj
|
||||
self.projectDirectory = projectDirectory
|
||||
}
|
||||
|
||||
private func resolveGroupPath(_ path: Path, isTopLevelGroup: Bool) -> String {
|
||||
if isTopLevelGroup, let relativePath = try? path.relativePath(from: projectDirectory ?? project.basePath).string {
|
||||
return relativePath
|
||||
} else {
|
||||
return path.lastComponent
|
||||
}
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
@ -286,9 +296,8 @@ class SourceGenerator {
|
||||
let isTopLevelGroup = (isBaseGroup && !createIntermediateGroups) || isRootPath
|
||||
|
||||
let groupName = name ?? path.lastComponent
|
||||
let groupPath = isTopLevelGroup ?
|
||||
((try? path.relativePath(from: project.basePath)) ?? path).string :
|
||||
path.lastComponent
|
||||
let groupPath = resolveGroupPath(path, isTopLevelGroup: isTopLevelGroup)
|
||||
|
||||
let group = PBXGroup(
|
||||
children: children,
|
||||
sourceTree: .group,
|
||||
|
@ -1035,4 +1035,38 @@ class ProjectGeneratorTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testGenerateXcodeProjectWithDestination() throws {
|
||||
let groupName = "App_iOS"
|
||||
let sourceDirectory = fixturePath + "TestProject" + groupName
|
||||
let frameworkWithSources = Target(
|
||||
name: "MyFramework",
|
||||
type: .framework,
|
||||
platform: .iOS,
|
||||
sources: [TargetSource(path: sourceDirectory.string)]
|
||||
)
|
||||
|
||||
describe("generateXcodeProject") {
|
||||
$0.context("without projectDirectory") {
|
||||
$0.it("generate groups") {
|
||||
let project = Project(name: "test", targets: [frameworkWithSources])
|
||||
let generator = ProjectGenerator(project: project)
|
||||
let generatedProject = try generator.generateXcodeProject()
|
||||
let group = generatedProject.pbxproj.groups.first(where: { $0.nameOrPath == groupName })
|
||||
try expect(group?.path) == "App_iOS"
|
||||
}
|
||||
}
|
||||
|
||||
$0.context("with projectDirectory") {
|
||||
$0.it("generate groups") {
|
||||
let destinationPath = fixturePath
|
||||
let project = Project(name: "test", targets: [frameworkWithSources])
|
||||
let generator = ProjectGenerator(project: project)
|
||||
let generatedProject = try generator.generateXcodeProject(in: destinationPath)
|
||||
let group = generatedProject.pbxproj.groups.first(where: { $0.nameOrPath == groupName })
|
||||
try expect(group?.path) == "TestProject/App_iOS"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user