-
Notifications
You must be signed in to change notification settings - Fork 482
Open
Description
file :xcodeproj/project/object/helpers/file_references_factory.rb
function:def new_subproject(group, path, source_tree)
can not work properly,so i changed it:
def new_subproject(group, path, source_tree)
ref = new_file_reference(group.project.main_group, path, source_tree)
ref.include_in_index = nil
product_group_ref = find_products_group_ref(group, true)
#add project ref to main group
#create a Products group to hold proxy targets and remove it from project add it only to project_reference
if group == group.project.main_group
product_group_ref = group.project.new_group("Products")
product_group_ref.remove_from_project
end
subproj = Project.open(path)
subproj.products_group.files.each do |product_reference|
container_proxy = group.project.new(PBXContainerItemProxy)
container_proxy.container_portal = ref.uuid
container_proxy.proxy_type = Constants::PROXY_TYPES[:reference]
container_proxy.remote_global_id_string = product_reference.uuid
container_proxy.remote_info = 'Subproject'
reference_proxy = group.project.new(PBXReferenceProxy)
extension = File.extname(product_reference.path)[1..-1]
reference_proxy.file_type = product_reference.explicit_file_type#Constants::FILE_TYPES_BY_EXTENSION[extension]
reference_proxy.remote_ref = container_proxy
reference_proxy.source_tree = product_reference.source_tree #'BUILT_PRODUCTS_DIR'
#just for correct name
old_path = product_reference.path.to_s
name = old_path
path = old_path
puts old_path.split('/').first
if old_path.split('/').first.end_with?(".framework")
name = old_path # Get last part after "/"
path = old_path.split('/').first # Get the framework name
elsif old_path.split('/').first.end_with?(".app")
name = File.basename(old_path, ".app") # Remove .app extension
path = old_path
end
reference_proxy.name = name
reference_proxy.path = path
#just for correct name end
product_group_ref << reference_proxy
end
attribute = PBXProject.references_by_keys_attributes.find { |attrb| attrb.name == :project_references }
project_reference = ObjectDictionary.new(attribute, group.project.root_object)
project_reference[:project_ref] = ref
project_reference[:product_group] = product_group_ref
group.project.root_object.project_references << project_reference
ref
end
usage:
# Add subprojects
def add_subproject(main_project, subproject_path)
# Check if project reference already exists
existing_ref = main_project.root_object.project_references.find { |ref| ref[:project_ref].path == subproject_path }
return existing_ref[:project_ref] if existing_ref
#here should use main_group,in new_reference should create a Products Group
reference = main_project.main_group.new_reference(subproject_path)
#puts "reference: #{reference.class}"
main_project.save()
return reference
end
Metadata
Metadata
Assignees
Labels
No labels