Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ def write_pbxproj_prefix_test_suite(name):
"Debug",
# developmentRegion
"en",
# projectName
"--project-name",
"project",
# platforms
"--platforms",
"macosx",
Expand Down Expand Up @@ -370,6 +373,9 @@ def write_pbxproj_prefix_test_suite(name):
# organizationName
"--organization-name",
"MobileNativeFoundation 2",
# projectName
"--project-name",
"project",
# platforms
"--platforms",
"macosx",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ extension ElementCreator.CreateGroupElement {
object: .init(
identifier: createIdentifier(
path: bazelPath.path,
name: attributes.elementAttributes.path,
// Xcode comments an element with its `name`, falling
// back to its `path`
name: attributes.elementAttributes.name ??
attributes.elementAttributes.path,
type: .group
),
content: content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,55 @@ final class CreateGroupElementTests: XCTestCase {
XCTAssertEqual(result.element.object.identifier, stubbedIdentifier)
}

func test_element_identifier_name() {
// Arrange

let name = "node_name"
let bazelPath = BazelPath("a/bazel/path/node_name")

let createAttributes = ElementCreator.CreateAttributes.mock(
elementAttributes: .init(
sourceTree: .group,
name: "a_name",
path: "/abs/path/to/a_path"
),
resolvedRepository: nil
)

let expectedCreateIdentifierCalled: [
ElementCreator.CreateIdentifier.MockTracker.Called
] = [
.init(
path: bazelPath.path,
// Xcode comments an element with its name when it has one
name: "a_name",
type: .group
)
]
let stubbedIdentifier = "1234abcd"
let createIdentifier = ElementCreator.CreateIdentifier
.mock(identifier: stubbedIdentifier)

// Act

let result = ElementCreator.CreateGroupElement.defaultCallable(
name: name,
bazelPath: bazelPath,
bazelPathType: .workspace,
childIdentifiers: [],
createAttributes: createAttributes.mock,
createIdentifier: createIdentifier.mock
)

// Assert

XCTAssertNoDifference(
createIdentifier.tracker.called,
expectedCreateIdentifierCalled
)
XCTAssertEqual(result.element.object.identifier, stubbedIdentifier)
}

// MARK: element.sortOrder

func test_element_sortOrder() {
Expand Down
17 changes: 16 additions & 1 deletion tools/generators/lib/PBXProj/src/Identifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,24 @@ FF0000000000000000000008 /* rules_xcodeproj */

public enum Project {
public static let id = #"FF0000000000000000000001 /* Project object */"#
public static let buildConfigurationList = #"""
/// The identifier of the `PBXProject`'s `XCConfigurationList`.
///
/// Xcode comments it with the project's name (e.g.
/// `Build configuration list for PBXProject "Foo"`). The name is
/// optional only to keep older callers working; when it's `nil` the
/// name is omitted.
public static func buildConfigurationList(
projectName: String?
) -> String {
guard let projectName else {
return #"""
FF0000000000000000000002 /* Build configuration list for PBXProject */
"""#
}
return #"""
FF0000000000000000000002 /* Build configuration list for PBXProject "\#(projectName)" */
"""#
}

/// Calculates the identifier for one of the `PBXProject`
/// `XCBBuildConfiguration`s.
Expand Down
4 changes: 2 additions & 2 deletions tools/generators/pbxproj_prefix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ Here is an example output:
};
name = Release;
};
FF0000000000000000000002 /* Build configuration list for PBXProject */ = {
FF0000000000000000000002 /* Build configuration list for PBXProject "Foo" */ = {
isa = XCConfigurationList;
buildConfigurations = (
FF0000000000000000000100 /* Debug */,
Expand All @@ -325,7 +325,7 @@ Here is an example output:
};
FF0000000000000000000001 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = FF0000000000000000000002 /* Build configuration list for PBXProject */;
buildConfigurationList = FF0000000000000000000002 /* Build configuration list for PBXProject "Foo" */;
compatibilityVersion = "Xcode 14.0";
developmentRegion = enGB;
hasScannedForEncodings = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ Populates the `ORGANIZATIONNAME` attribute for the project.
""")
var organizationName: String?

@Option(help: """
Name of the project (the `.xcodeproj` basename without its extension). Used \
in object comments, to match how Xcode writes them.
""")
var projectName: String?

@Option(
parsing: .upToNextOption,
help: "Names of the platforms the project is using."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ extension Generator {
_ developmentRegion: String,
_ organizationName: String?,
_ projectDir: String,
_ projectName: String?,
_ workspace: String,
_ xcodeConfigurations: [String]
) -> String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ struct Generator {
/*developmentRegion:*/ arguments.developmentRegion,
/*organizationName:*/ arguments.organizationName,
/*projectDir:*/ projectDir,
/*projectName:*/ arguments.projectName,
/*workspace:*/ arguments.workspace,
/*xcodeConfigurations:*/ arguments.xcodeConfigurations
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extension Generator {
developmentRegion: String,
organizationName: String?,
projectDir: String,
projectName: String?,
workspace: String,
xcodeConfigurations: [String]
) -> String {
Expand All @@ -24,6 +25,9 @@ extension Generator {
organizationNameAttribute = ""
}

let buildConfigurationList = Identifiers.Project
.buildConfigurationList(projectName: projectName)

// Build configurations

let buildConfigurations = xcodeConfigurations
Expand Down Expand Up @@ -56,7 +60,7 @@ extension Generator {
// correctly.
return #"""
\#(buildConfigurations.map(\.element).joined(separator: "\n"))
\#(Identifiers.Project.buildConfigurationList) = {
\#(buildConfigurationList) = {
isa = XCConfigurationList;
buildConfigurations = (
\#(
Expand All @@ -71,7 +75,7 @@ extension Generator {
};
\#(Identifiers.Project.id) = {
isa = PBXProject;
buildConfigurationList = \#(Identifiers.Project.buildConfigurationList);
buildConfigurationList = \#(buildConfigurationList);
compatibilityVersion = \#(compatibilityVersion.pbxProjEscaped);
developmentRegion = \#(developmentRegion.pbxProjEscaped);
hasScannedForEncodings = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PBXProjectPrefixPartialTests: XCTestCase {
buildSettings = {BUILD_SETTINGS_HERE};
name = Debug;
};
FF0000000000000000000002 /* Build configuration list for PBXProject */ = {
FF0000000000000000000002 /* Build configuration list for PBXProject "Foo" */ = {
isa = XCConfigurationList;
buildConfigurations = (
FF0000000000000000000100 /* Release */,
Expand All @@ -53,7 +53,7 @@ class PBXProjectPrefixPartialTests: XCTestCase {
};
FF0000000000000000000001 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = FF0000000000000000000002 /* Build configuration list for PBXProject */;
buildConfigurationList = FF0000000000000000000002 /* Build configuration list for PBXProject "Foo" */;
compatibilityVersion = "AppCode 42.7.4";
developmentRegion = "en-GB";
hasScannedForEncodings = 0;
Expand All @@ -77,6 +77,7 @@ class PBXProjectPrefixPartialTests: XCTestCase {
developmentRegion: developmentRegion,
organizationName: organizationName,
projectDir: projectDir,
projectName: "Foo",
workspace: workspace,
xcodeConfigurations: xcodeConfigurations
)
Expand Down Expand Up @@ -124,7 +125,7 @@ class PBXProjectPrefixPartialTests: XCTestCase {
buildSettings = {BUILD_SETTINGS_HERE};
name = Debug;
};
FF0000000000000000000002 /* Build configuration list for PBXProject */ = {
FF0000000000000000000002 /* Build configuration list for PBXProject "Foo" */ = {
isa = XCConfigurationList;
buildConfigurations = (
FF0000000000000000000100 /* Release */,
Expand All @@ -136,7 +137,7 @@ class PBXProjectPrefixPartialTests: XCTestCase {
};
FF0000000000000000000001 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = FF0000000000000000000002 /* Build configuration list for PBXProject */;
buildConfigurationList = FF0000000000000000000002 /* Build configuration list for PBXProject "Foo" */;
compatibilityVersion = "AppCode 42.7.4";
developmentRegion = "en-GB";
hasScannedForEncodings = 0;
Expand All @@ -160,6 +161,7 @@ class PBXProjectPrefixPartialTests: XCTestCase {
developmentRegion: developmentRegion,
organizationName: organizationName,
projectDir: projectDir,
projectName: "Foo",
workspace: workspace,
xcodeConfigurations: xcodeConfigurations
)
Expand Down Expand Up @@ -207,7 +209,7 @@ class PBXProjectPrefixPartialTests: XCTestCase {
buildSettings = {BUILD_SETTINGS_HERE};
name = Debug;
};
FF0000000000000000000002 /* Build configuration list for PBXProject */ = {
FF0000000000000000000002 /* Build configuration list for PBXProject "Foo" */ = {
isa = XCConfigurationList;
buildConfigurations = (
FF0000000000000000000100 /* Release */,
Expand All @@ -219,7 +221,7 @@ class PBXProjectPrefixPartialTests: XCTestCase {
};
FF0000000000000000000001 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = FF0000000000000000000002 /* Build configuration list for PBXProject */;
buildConfigurationList = FF0000000000000000000002 /* Build configuration list for PBXProject "Foo" */;
compatibilityVersion = "AppCode 42.7.4";
developmentRegion = enGB;
hasScannedForEncodings = 0;
Expand All @@ -244,6 +246,7 @@ class PBXProjectPrefixPartialTests: XCTestCase {
developmentRegion: developmentRegion,
organizationName: organizationName,
projectDir: projectDir,
projectName: "Foo",
workspace: workspace,
xcodeConfigurations: xcodeConfigurations
)
Expand Down Expand Up @@ -291,7 +294,7 @@ class PBXProjectPrefixPartialTests: XCTestCase {
buildSettings = {BUILD_SETTINGS_HERE};
name = Debug;
};
FF0000000000000000000002 /* Build configuration list for PBXProject */ = {
FF0000000000000000000002 /* Build configuration list for PBXProject "Foo" */ = {
isa = XCConfigurationList;
buildConfigurations = (
FF0000000000000000000100 /* Release */,
Expand All @@ -303,7 +306,7 @@ class PBXProjectPrefixPartialTests: XCTestCase {
};
FF0000000000000000000001 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = FF0000000000000000000002 /* Build configuration list for PBXProject */;
buildConfigurationList = FF0000000000000000000002 /* Build configuration list for PBXProject "Foo" */;
compatibilityVersion = "AppCode 42.7.4";
developmentRegion = enGB;
hasScannedForEncodings = 0;
Expand All @@ -328,6 +331,7 @@ class PBXProjectPrefixPartialTests: XCTestCase {
developmentRegion: developmentRegion,
organizationName: organizationName,
projectDir: projectDir,
projectName: "Foo",
workspace: workspace,
xcodeConfigurations: xcodeConfigurations
)
Expand Down Expand Up @@ -375,7 +379,7 @@ class PBXProjectPrefixPartialTests: XCTestCase {
buildSettings = {BUILD_SETTINGS_HERE};
name = Debug;
};
FF0000000000000000000002 /* Build configuration list for PBXProject */ = {
FF0000000000000000000002 /* Build configuration list for PBXProject "Foo" */ = {
isa = XCConfigurationList;
buildConfigurations = (
FF0000000000000000000100 /* Release */,
Expand All @@ -387,7 +391,7 @@ class PBXProjectPrefixPartialTests: XCTestCase {
};
FF0000000000000000000001 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = FF0000000000000000000002 /* Build configuration list for PBXProject */;
buildConfigurationList = FF0000000000000000000002 /* Build configuration list for PBXProject "Foo" */;
compatibilityVersion = "AppCode 42.7.4";
developmentRegion = enGB;
hasScannedForEncodings = 0;
Expand All @@ -412,6 +416,7 @@ class PBXProjectPrefixPartialTests: XCTestCase {
developmentRegion: developmentRegion,
organizationName: organizationName,
projectDir: projectDir,
projectName: "Foo",
workspace: workspace,
xcodeConfigurations: xcodeConfigurations
)
Expand Down
8 changes: 8 additions & 0 deletions xcodeproj/internal/pbxproj_partials.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Actions for creating `PBXProj` partials."""

load("@bazel_skylib//lib:paths.bzl", "paths")
load("//xcodeproj/internal/files:files.bzl", "join_paths_ignoring_empty")
load(":collections.bzl", "uniq")
load(
Expand Down Expand Up @@ -122,6 +123,7 @@ _FLAGS = struct(
organization_name = "--organization-name",
platforms = "--platforms",
post_build_script = "--post-build-script",
project_name = "--project-name",
pre_build_script = "--pre-build-script",
target_and_test_hosts = "--target-and-test-hosts",
target_and_watch_kit_extensions = "--target-and-watch-kit-extensions",
Expand Down Expand Up @@ -775,6 +777,12 @@ def _write_pbxproj_prefix(
if organization_name:
args.add(_FLAGS.organization_name, organization_name)

# projectName
args.add(
_FLAGS.project_name,
paths.split_extension(paths.basename(install_path))[0],
)

# platforms
args.add_all(
_FLAGS.platforms,
Expand Down