其他分享
首页 > 其他分享> > iOS.CocoaPods.25-issues-pod install: Stuck at "Generating deterministic UUIDs"

iOS.CocoaPods.25-issues-pod install: Stuck at "Generating deterministic UUIDs"

作者:互联网

pod install: Stuck at "Generating deterministic UUIDs"

 

1. Pod Version

$ pod --version 

1.10.1

 

2. "Generating deterministic UUIDs"

2.1 Calling predictabilize_uuids function

 

https://github.com/CocoaPods/CocoaPods/blob/1.10.1/lib/cocoapods/installer.rb#L323

def create_and_save_projects(pod_targets_to_generate, aggregate_targets_to_generate, build_configurations, project_object_version)
// ... ...

        predictabilize_uuids(generated_projects) if installation_options.deterministic_uuids?
        stabilize_target_uuids(generated_projects)

// ... ...

end

 

对应到cocoapods在本地的安装路径为: 

/usr/local/lib/ruby/gems/2.7.0/gems/cocoapods-1.10.1/lib/cocoapods/installer.rb

 

2.2 The predictabilize_uuids function

https://github.com/CocoaPods/CocoaPods/blob/1.10.1/lib/cocoapods/installer.rb#L343

def predictabilize_uuids(projects)
      UI.message('- Generating deterministic UUIDs') { Xcodeproj::Project.predictabilize_uuids(projects) }
end

def stabilize_target_uuids(projects)
      UI.message('- Stabilizing target UUIDs') { TargetUUIDGenerator.new(projects).generate! }
end

 

2.2.1 测量Xcodeproj::Project.predictabilize_uuids(projects)的耗时

在Xcodeproj::Project.predictabilize_uuids(projects)前后输出时间戳到UI(User Interface),如下所示: 

    def predictabilize_uuids(projects)
      UI.message('- Generating deterministic UUIDs') {
                begin_ts = Time.now.strftime '%Y-%m-%d %H:%M:%S' 
                UI.message(begin_ts)
                Xcodeproj::Project.predictabilize_uuids(projects)
                end_ts = Time.now.strftime '%Y-%m-%d %H:%M:%S'
                UI.message(end_ts)
        }
    end

 

"pod install --verbose"的输出为:

Integrating target `ZipArchive`
    Adding Build Phase '[CP] Copy dSYMs' to project.
    Adding Build Phase '[CP] Copy XCFrameworks' to project.
  - Generating deterministic UUIDs
    2022-09-14 10:57:39
    2022-09-14 10:59:05
  - Stabilizing target UUIDs
  - Running post install hooks

 

  

2.3 The message function

https://github.com/CocoaPods/CocoaPods/blob/1.10.1/lib/cocoapods/user_interface.rb#L140

def message(message, verbose_prefix = '', relative_indentation = 2)
        message = verbose_prefix + message if config.verbose?
        puts_indented message if config.verbose?

        self.indentation_level += relative_indentation
        yield if block_given?
ensure
        self.indentation_level -= relative_indentation
end

 

 

yield if block_given?

Ruby.yield-and-block_given

 

2.4 The hot point

"Xcodeproj::Project.predictabilize_uuids(projects)"

https://github.com/CocoaPods/Xcodeproj/blob/1.19.0/lib/xcodeproj/project.rb

 

1     def self.predictabilize_uuids(projects)
2       UUIDGenerator.new(projects).generate!
3     end

  

2.4.1 Class Xcodeproj::Project

https://www.rubydoc.info/github/CocoaPods/Xcodeproj/Xcodeproj/Project

 

2.4.2 UUIDGenerator类的generate!方法

https://github.com/CocoaPods/Xcodeproj/blob/1.19.0/lib/xcodeproj/project/uuid_generator.rb

generate!方法中耗时操作集中在: 

generate_all_paths_by_objects()方法和switch_uuids()方法。

 1       def generate!
 2         generate_all_paths_by_objects(@projects)
 3 
 4         new_objects_by_project = Hash[@projects.map do |project|
 5           [project, switch_uuids(project)]
 6         end]
 7         all_new_objects_by_project = new_objects_by_project.values.flat_map(&:values)
 8         all_objects_by_uuid = @projects.map(&:objects_by_uuid).inject(:merge)
 9         all_objects = @projects.flat_map(&:objects)
10         verify_no_duplicates!(all_objects, all_new_objects_by_project)
11         @projects.each { |project| fixup_uuid_references(project, all_objects_by_uuid) }
12         new_objects_by_project.each do |project, new_objects_by_uuid|
13           project.instance_variable_set(:@generated_uuids, project.instance_variable_get(:@available_uuids))
14           project.instance_variable_set(:@objects_by_uuid, new_objects_by_uuid)
15         end
16       end

 

 

 

generate!方法中调用switch_uuids()方法来计算MD5。

 1       def switch_uuids(project)
 2         project.mark_dirty!
 3         project.objects.each_with_object({}) do |object, hash|
 4           next unless path = @paths_by_object[object]
 5           uuid = uuid_for_path(path)
 6           object.instance_variable_set(:@uuid, uuid)
 7           hash[uuid] = object
 8         end
 9       end
10 
11       def uuid_for_path(path)
12         Digest::MD5.hexdigest(path).upcase
13       end

 

3. 跳过"Generating deterministic UUIDs"

Ref[14]

通过在Podfile中使用Root Option来跳过"Generating deterministic UUIDs"步骤:

install! 'cocoapods',
         :deterministic_uuids => false

: 跳过"Generating deterministic UUIDs"的影响是什么? 

 

 

 

 

 

 


Reference

1. pod install: Stuck at "Generating deterministic UUIDs" #10506 

https://github.com/CocoaPods/CocoaPods/issues/10506

 

2. What Is a UUID and How Are They Generated?

A look at Universally Unique Identifiers

https://betterprogramming.pub/what-is-a-uuid-and-how-are-they-generated-17f0acbd7233

 

3. Deterministic UUIDs #175

https://github.com/CocoaPods/Xcodeproj/issues/175

 

4. install!

https://guides.cocoapods.org/syntax/podfile.html#install_bang

 

标签:Generating,end,uuid,deterministic,iOS,project,objects,uuids,projects
来源: https://www.cnblogs.com/cwgk/p/16582152.html