Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add knownRegions to generated projects #792

Merged
merged 3 commits into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Please, check out guidelines: https://keepachangelog.com/en/1.0.0/
- Remove duplicate HEADER_SEARCH_PATHS https://github.com/tuist/tuist/pull/787 by @kwridan
- Fix unstable scheme generation https://github.com/tuist/tuist/pull/790 by @marciniwanicki
- Add defaultConfigurationName to generated projects https://github.com/tuist/tuist/pull/793 by @kwridan
- Add knownRegions to generated projects https://github.com/tuist/tuist/pull/792 by @kwridan

## 0.19.0

Expand Down
13 changes: 9 additions & 4 deletions Sources/TuistGenerator/Generator/ProjectFileElements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ class ProjectFileElements {
var elements: [AbsolutePath: PBXFileElement] = [:]
var products: [String: PBXFileReference] = [:]
var sdks: [AbsolutePath: PBXFileReference] = [:]
let playgrounds: Playgrounding
let filesSortener: ProjectFilesSortening
var knownRegions: Set<String> = Set([])

// MARK: - Private

private let playgrounds: Playgrounding
private let filesSortener: ProjectFilesSortening

// MARK: - Init

Expand Down Expand Up @@ -372,13 +376,14 @@ class ProjectFileElements {
pbxproj: PBXProj) {
let localizedFilePath = localizedFile.relative(to: localizedContainer.parentDirectory)
let lastKnownFileType = localizedFile.extension.flatMap { Xcode.filetype(extension: $0) }
let name = localizedContainer.basename.split(separator: ".").first
let language = localizedContainer.basenameWithoutExt
let localizedFileReference = PBXFileReference(sourceTree: .group,
name: name.map { String($0) },
name: language,
lastKnownFileType: lastKnownFileType,
path: localizedFilePath.pathString)
pbxproj.add(object: localizedFileReference)
variantGroup.children.append(localizedFileReference)
knownRegions.insert(language)
}

func addVersionGroupElement(from: AbsolutePath,
Expand Down
6 changes: 5 additions & 1 deletion Sources/TuistGenerator/Generator/ProjectGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ final class ProjectGenerator: ProjectGenerating {
sourceRootPath: sourceRootPath)
let configurationList = try configGenerator.generateProjectConfig(project: project, pbxproj: pbxproj, fileElements: fileElements)
let pbxProject = try generatePbxproject(project: project,
projectFileElements: fileElements,
configurationList: configurationList,
groups: groups,
pbxproj: pbxproj)
Expand Down Expand Up @@ -134,16 +135,19 @@ final class ProjectGenerator: ProjectGenerating {
}

private func generatePbxproject(project: Project,
projectFileElements: ProjectFileElements,
configurationList: XCConfigurationList,
groups: ProjectGroups,
pbxproj: PBXProj) throws -> PBXProject {
let defaultRegions = ["en"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is en a default region always, is there a possibility you can have other region as default?

Copy link
Collaborator Author

@kwridan kwridan Dec 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment its set the match the default region generated by Tuist:

https://github.com/tuist/tuist/pull/792/files/18e490be0c7cbdda8e00e64c3d8514ab63d05c39#diff-8003e7a5fde9a1f00d9e93c3bad58745R148

https://github.com/tuist/XcodeProj/blob/master/Sources/XcodeProj/Project/Xcode.swift#L47

Could be a separate enhancement to support specifying the default development regions.

let knownRegions = Set(defaultRegions + projectFileElements.knownRegions).sorted()
let pbxProject = PBXProject(name: project.name,
buildConfigurationList: configurationList,
compatibilityVersion: Xcode.Default.compatibilityVersion,
mainGroup: groups.main,
developmentRegion: Xcode.Default.developmentRegion,
hasScannedForEncodings: 0,
knownRegions: ["en"],
knownRegions: knownRegions,
productsGroup: groups.products,
projectDirPath: "",
projects: [],
Expand Down
35 changes: 35 additions & 0 deletions Tests/TuistGeneratorTests/Generator/ProjectFileElementsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,41 @@ final class ProjectFileElementsTests: TuistUnitTestCase {
])
}

func test_addElement_lproj_knownRegions() throws {
// Given
let temporaryPath = try self.temporaryPath()
let resouces = try createFiles([
"resources/en.lproj/App.strings",
"resources/en.lproj/Extension.strings",
"resources/fr.lproj/App.strings",
"resources/fr.lproj/Extension.strings",
"resources/Base.lproj/App.strings",
"resources/Base.lproj/Extension.strings",
])

let elements = resouces.map {
GroupFileElement(path: $0,
group: .group(name: "Project"),
isReference: true)
}

// When
try elements.forEach {
try subject.generate(fileElement: $0,
groups: groups,
pbxproj: pbxproj,
sourceRootPath: temporaryPath)
}

// Then

XCTAssertEqual(subject.knownRegions, Set([
"en",
"fr",
"Base",
]))
}

func test_targetFiles() throws {
// Given
let settings = Settings.test(
Expand Down
31 changes: 31 additions & 0 deletions Tests/TuistGeneratorTests/Generator/ProjectGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,35 @@ final class ProjectGeneratorTests: TuistUnitTestCase {
XCTAssertEqual(got.pbxproj.objectVersion, 50)
XCTAssertEqual(got.pbxproj.archiveVersion, Xcode.LastKnown.archiveVersion)
}

func test_knownRegions() throws {
// Given
let path = try temporaryPath()
let graph = Graph.test(entryPath: path)
let resources = [
"resources/en.lproj/App.strings",
"resources/en.lproj/Extension.strings",
"resources/fr.lproj/App.strings",
"resources/fr.lproj/Extension.strings",
"resources/Base.lproj/App.strings",
"resources/Base.lproj/Extension.strings",
]
let project = Project.test(path: path,
targets: [
.test(resources: resources.map {
.file(path: path.appending(RelativePath($0)))
}),
])

// When
let got = try subject.generate(project: project, graph: graph)

// Then
let pbxProject = try XCTUnwrap(try got.pbxproj.rootProject())
XCTAssertEqual(pbxProject.knownRegions, [
"Base",
"en",
"fr",
])
}
}