Skip to content

Commit

Permalink
special case for target-only dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-makarov committed May 22, 2024
1 parent 1c7e75c commit 7b5858f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/censorius.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def generate_paths_build_file(build_file, parent_path)
file_ref_path = generate_paths(build_file.file_ref)
@paths_by_object[build_file] = "#{parent_path}/PBXBuildFile(#{file_ref_path})"
elsif build_file.product_ref
@paths_by_object[build_file.product_ref] ||= generate_paths(dependency.product_ref, parent_path)
product_ref_path = @paths_by_object[build_file.product_ref]
@paths_by_object[build_file] = "#{parent_path}/PBXBuildFile(#{product_ref_path})"
else
Expand Down Expand Up @@ -149,6 +150,7 @@ def generate_paths_target_dependency(dependency, parent_path)
@paths_by_object[dependency] = path = "#{parent_path}/PBXTargetDependency(#{dependency.name})"
generate_paths(dependency.target_proxy, path)
elsif dependency.product_ref
@paths_by_object[dependency.product_ref] ||= generate_paths(dependency.product_ref, parent_path)
product_ref_path = @paths_by_object[dependency.product_ref]
@paths_by_object[dependency] = "#{parent_path}/PBXTargetDependency(#{product_ref_path})"
else
Expand Down
49 changes: 49 additions & 0 deletions spec/censorius_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,53 @@ def add_build_rule(target, rule_name)
"PBXProject(#{@spec_safe_name})/XCRemoteSwiftPackageReference(https://url.to/, {:kind=>\"upToNextMajorVersion\", :minimumVersion=>\"5.0.0\"})"
]).sorted_md5s
end

it 'generates UUIDs for SwiftPM dependencies when they are target-only' do
target = @project.new_target(:application, 'AppTarget', :ios)
target.resources_build_phase.remove_from_project
target.source_build_phase.remove_from_project

package_reference = @project.new(Xcodeproj::Project::Object::XCRemoteSwiftPackageReference)
package_reference.repositoryURL = 'https://url.to/'
package_reference.requirement = { kind: 'upToNextMajorVersion', minimumVersion: '5.0.0' }
@project.root_object.package_references << package_reference

dependency = @project.new(Xcodeproj::Project::Object::XCSwiftPackageProductDependency)
dependency.package = package_reference
dependency.product_name = 'Product1'

target_dependency = @project.new(Xcodeproj::Project::PBXTargetDependency)
target_dependency.product_ref = dependency
target.dependencies << target_dependency

@generator.generate!

expect(@project.sorted_md5s).to eq (%W[
PBXProject(#{@spec_safe_name})
PBXProject(#{@spec_safe_name})/PBXFileReference(${BUILT_PRODUCTS_DIR}/AppTarget.app)
PBXProject(#{@spec_safe_name})/PBXFileReference(${DEVELOPER_DIR}/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.0.sdk/System/Library/Frameworks/Foundation.framework)
PBXProject(#{@spec_safe_name})/PBXGroup(/)
PBXProject(#{@spec_safe_name})/PBXGroup(/Frameworks)
PBXProject(#{@spec_safe_name})/PBXGroup(/Frameworks/iOS)
PBXProject(#{@spec_safe_name})/PBXGroup(/Products)
PBXProject(#{@spec_safe_name})/PBXNativeTarget(AppTarget)
PBXProject(#{@spec_safe_name})/PBXNativeTarget(AppTarget)/PBXFrameworksBuildPhase(Frameworks)
PBXProject(#{@spec_safe_name})/PBXNativeTarget(AppTarget)/PBXFrameworksBuildPhase(Frameworks)/PBXBuildFile(PBXProject(#{@spec_safe_name})/PBXFileReference(${DEVELOPER_DIR}/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.0.sdk/System/Library/Frameworks/Foundation.framework))
] + [
"PBXProject(#{@spec_safe_name})/PBXNativeTarget(AppTarget)/PBXTargetDependency(PBXProject(#{@spec_safe_name})/PBXNativeTarget(AppTarget)/XCSwiftPackageProductDependency(PBXProject(#{@spec_safe_name})/XCRemoteSwiftPackageReference(https://url.to/, {:kind=>\"upToNextMajorVersion\", :minimumVersion=>\"5.0.0\"}), Product1))"
] + %W[
PBXProject(#{@spec_safe_name})/PBXNativeTarget(AppTarget)/XCConfigurationList
PBXProject(#{@spec_safe_name})/PBXNativeTarget(AppTarget)/XCConfigurationList/XCBuildConfiguration(Debug)
PBXProject(#{@spec_safe_name})/PBXNativeTarget(AppTarget)/XCConfigurationList/XCBuildConfiguration(Release)
] + [
"PBXProject(#{@spec_safe_name})/PBXNativeTarget(AppTarget)/XCSwiftPackageProductDependency(PBXProject(#{@spec_safe_name})/XCRemoteSwiftPackageReference(https://url.to/, {:kind=>\"upToNextMajorVersion\", :minimumVersion=>\"5.0.0\"}), Product1)"
] + %W[
PBXProject(#{@spec_safe_name})/XCConfigurationList
PBXProject(#{@spec_safe_name})/XCConfigurationList/XCBuildConfiguration(Debug)
PBXProject(#{@spec_safe_name})/XCConfigurationList/XCBuildConfiguration(Release)
] + [
# declared in a weird way because of string split/escape
"PBXProject(#{@spec_safe_name})/XCRemoteSwiftPackageReference(https://url.to/, {:kind=>\"upToNextMajorVersion\", :minimumVersion=>\"5.0.0\"})"
]).sorted_md5s
end
end

0 comments on commit 7b5858f

Please sign in to comment.