Skip to content

Commit

Permalink
support swift local package reference
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-makarov committed May 20, 2024
1 parent 09fe4bd commit 4a800bd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/censorius.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def generate_paths(object, parent_path = '') # rubocop:disable Metrics/Cyclomati
generate_paths_reference_proxy(object, parent_path)
when Xcodeproj::Project::Object::XCRemoteSwiftPackageReference
generate_paths_remote_swift_package_reference(object, parent_path)
when Xcodeproj::Project::Object::XCLocalSwiftPackageReference
generate_paths_local_swift_package_reference(object, parent_path)
when Xcodeproj::Project::Object::XCSwiftPackageProductDependency
generate_paths_remote_swift_package_product_dependency(object, parent_path)
else
Expand Down Expand Up @@ -176,6 +178,13 @@ def generate_paths_remote_swift_package_reference(reference, parent_path)
@paths_by_object[reference] = "#{parent_path}/XCRemoteSwiftPackageReference(#{params.join(', ')})"
end

def generate_paths_local_swift_package_reference(reference, parent_path)
params = [
reference.relative_path
]
@paths_by_object[reference] = "#{parent_path}/XCLocalSwiftPackageReference(#{params.join(', ')})"
end

def generate_paths_remote_swift_package_product_dependency(dependency, parent_path)
@paths_by_object[dependency] = "#{parent_path}/XCSwiftPackageProductDependency(#{dependency.product_name})"
end
Expand Down
4 changes: 4 additions & 0 deletions spec/censorius_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ def add_build_rule(target, rule_name)
package_reference.repositoryURL = 'https://url.to/'
package_reference.requirement = { kind: 'upToNextMajorVersion', minimumVersion: '5.0.0' }
@project.root_object.package_references << package_reference
local_package_reference = @project.new(Xcodeproj::Project::Object::XCLocalSwiftPackageReference)
local_package_reference.relative_path = '../path/to/package'
@project.root_object.package_references << local_package_reference

dependency = @project.new(Xcodeproj::Project::Object::XCSwiftPackageProductDependency)
dependency.package = package_reference
Expand Down Expand Up @@ -335,6 +338,7 @@ def add_build_rule(target, rule_name)
PBXProject(#{@spec_safe_name})/XCConfigurationList/XCBuildConfiguration(Release)
] + [
# declared in a weird way because of string split/escape
"PBXProject(#{@spec_safe_name})/XCLocalSwiftPackageReference(../path/to/package)",
"PBXProject(#{@spec_safe_name})/XCRemoteSwiftPackageReference(https://url.to/, {:kind=>\"upToNextMajorVersion\", :minimumVersion=>\"5.0.0\"})"
]).sorted_md5s
end
Expand Down

0 comments on commit 4a800bd

Please sign in to comment.