iOS development Detailed engineering -cocoapods

iOS开发工程化-cocoapods详解 | HChong的博客地址 I poke
Article Directory

This paper mainly on knowledge cocoapods, the practice of cocoapods, refer to here .

1 source analysis

pod is used mainly in pod installand pod updatewe can see the entrance of cocoapods in version 1.7.5 of the source code .

def install!
  prepare
  resolve_dependencies
  download_dependencies
  validate_targets
  generate_pods_project
  if installation_options.integrate_targets?
    integrate_user_project
  else
    UI.section 'Skipping User Project Integration'
  end
  perform_post_install_actions
end

Source code analysis can be found, install execution divided into the following steps: preparation phase, dependent libraries to find, download dependent files, test target, generating pod engineering, integration project file, perform the installation , the following will explain step by step.

1.1 Preparation stage

def prepare
  # Raise if pwd is inside Pods
  if Dir.pwd.start_with?(sandbox.root.to_path)
    message = 'Command should be run from a directory outside Pods directory.'
    message << "nntCurrent directory is #{UI.path(Pathname.pwd)}n"
    raise Informative, message
  end
  UI.message 'Preparing' do
    deintegrate_if_different_major_version
    sandbox.prepare
    ensure_plugins_are_installed!
    run_plugins_pre_install_hooks
  end
end

We can see that the preparation stage (prepare) mainly to do the following things:

  • cocoapods written examination podfile.lock version and the current version cocoapods whether, and if not will reshape the project, in addition to other related Podfile, Podfile.lock, Workspace and dependence Reset All
  • Sandbox ready - to delete some files and directories, and create
  • Migration sandbox of the file (version migration distinguish Pods different address)
  • Ensure Podfile specified plug-ins are already installed (or else throwing error)
  • Hook pre_install of execution

1.2 find dependent libraries

def resolve_dependencies
  plugin_sources = run_source_provider_hooks
  analyzer = create_analyzer(plugin_sources)

  UI.section 'Updating local specs repositories' do
    analyzer.update_repositories
  end if repo_update?

  UI.section 'Analyzing dependencies' do
    analyze(analyzer)
    validate_build_configurations
  end

  UI.section 'Verifying no changes' do
    verify_no_podfile_changes!
    verify_no_lockfile_changes!
  end if deployment?

  analyzer
end

We can see that, look for the dependent libraries (resolve_dependencies) mainly to do the following things:

  • All plug-traversal registered, which by HooksManager.register method to register name as: source_provider plug
  • Create_analyzer execution method to create an installation analyzer
  • If we added -repo-updateflag in the implementation of pod install, it just creates an instance of the analyzer will perform update_repositories way to update all local repo pod spec file repository.
  • Build Configurations validate parameters
  • Verify the change podfile
  • Verification of changes lockfile

1.3 download dependent files

def download_dependencies
  UI.section 'Downloading dependencies' do
    install_pod_sources
    run_podfile_pre_install_hooks
    clean_pod_sources
  end
end

We can see, download dependencies (download_dependencies) mainly to do the following things:

  • Download and install Pods dependent library source files
  • Execution Podfile in pre_install hook method
  • According Config and Installers parameters cleanup Pods source files

1.4 test target

def validate_targets
  validator = Xcode::TargetValidator.new(aggregate_targets, pod_targets)
  validator.validate!
end

Test target (validate_targets), mainly to do the following things:

  • Detect whether there are cases of multiple reference framework or library (Framework whether the name of the conflict, if conflict will throw frameworks with conflicting namesan exception)
  • Handling static library dependencies transfer (static library if the formation of transitive dependencies will automatically throw transitive dependencies that include static binariesan exception)
  • Different target check codes cited, if contained swift, swift used are the same version
  • Check whether quoted Switf writing framework (Podfile not specified use framework !. If the authentication fails, take the initiative to throw an exception)

1.5 generation Pods engineering

def generate_pods_project
  stage_sandbox(sandbox, pod_targets)

  cache_analysis_result = analyze_project_cache
  pod_targets_to_generate = cache_analysis_result.pod_targets_to_generate
  aggregate_targets_to_generate = cache_analysis_result.aggregate_targets_to_generate

  clean_sandbox(pod_targets_to_generate)

  create_and_save_projects(pod_targets_to_generate, aggregate_targets_to_generate,
                           cache_analysis_result.build_configurations, cache_analysis_result.project_object_version)
  SandboxDirCleaner.new(sandbox, pod_targets, aggregate_targets).clean!

  update_project_cache(cache_analysis_result, target_installation_results)
  write_lockfiles
end

Pods generation project (generate_pods_project), mainly to do:

  • Podfile hook method calls in post_install
  • Generate all the Pods / directory project
  • Podfile.lock files and documents generated Manifest.lock

1.6 Integration project file

def integrate_user_project
  UI.section "Integrating client #{'project'.pluralize(aggregate_targets.map(&:user_project_path).uniq.count)}" do
    installation_root = config.installation_root
    integrator = UserProjectIntegrator.new(podfile, sandbox, installation_root, aggregate_targets, generated_aggregate_targets,
                                           :use_input_output_paths => !installation_options.disable_input_output_paths?)
    integrator.integrate!
  end
end

Integration project file (integrate_user_project), mainly to do:

  • Create a file .xcworkspace
  • Integrated Target
  • Warning checks
  • Save the file to the directory .xcworkspace

1.7 Performing post-installation operations

def perform_post_install_actions
  run_plugins_post_install_hooks
  warn_for_deprecations
  warn_for_installed_script_phases
  print_post_install_message
end

After the installation operation (perform_post_install_actions), mainly to do the following:

  • File under unLock Pods library
  • Call the plugin method of post_install hook
  • Print all abandoned pods warnings
  • Print all warning messages in scripts pods
  • All information in print install

1.8 summary

  • Preparation Phase
    • cocoapods written examination podfile.lock version and the current version cocoapods whether, and if not will reshape the project, in addition to other related Podfile, Podfile.lock, Workspace and dependence Reset All
    • Sandbox ready - to delete some files and directories, and create
    • Migration sandbox of the file (version migration distinguish Pods different address)
    • Ensure Podfile specified plug-ins are already installed (or else throwing error)
    • Hook pre_install of execution
  • Find dependent libraries
    • All plug-traversal registered, which by HooksManager.register method to register name as: source_provider plug
    • Create_analyzer execution method to create an installation analyzer
    • If we added -repo-updateflag in the implementation of pod install, it just creates an instance of the analyzer will perform update_repositories way to update all local repo pod spec file repository.
    • Build Configurations validate parameters
    • Verify the change podfile
    • Verification of changes lockfile
  • Download dependent files
    • Download and install Pods dependent library source files
    • Execution Podfile in pre_install hook method
    • Pods according to the source file cleanup and Installers Config parameters *
  • Test target
    • Detect whether there are cases of multiple reference framework or library (Framework whether the name of the conflict, if conflict will throw frameworks with conflicting namesan exception)
    • Handling static library dependencies transfer (static library if the formation of transitive dependencies will automatically throw transitive dependencies that include static binariesan exception)
    • Different target check codes cited, if contained swift, swift used are the same version
    • Check whether quoted Switf writing framework (Podfile not specified use framework !. If the authentication fails, take the initiative to throw an exception)
  • Project generation pod
    • Podfile hook method calls in post_install
      • Generate all the Pods / directory project
      • Podfile.lock files and documents generated Manifest.lock
  • Integration project file
    • Create a file .xcworkspace
    • Integrated Target
    • Warning checks
    • Save the file to the directory .xcworkspace
  • After the installation operations
    • File under unLock Pods library
    • Call the plugin method of post_install hook
    • Print all abandoned pods warnings
    • Print all warning messages in scripts pods
    • All information in print install

2 private practice & Pod

You can refer to the previous summary

3 binary program

Here

Here is a more complete industry solutions

  • The main idea is that there will be two forms of source code and framework package (in two ways by creating a new target or new construction) at the same time in the creation of pod
  • In podspec to specify how to switch the source and the parameters passed in binary.

4 Frequently Asked Questions


References:
1. CocoaPods have done what?
2. CocoaPods Source On
3. pod and pod behind the update install that something
4. CocoaPods source
5. CocoaPods binary
6. Based CocoaPods binary components Practice
7. iOS CocoaPods components smoothing the binary solution
8. the the iOS CocoaPods assembly smoothing binary solutions and the two articles detailed tutorial subspecs

Original: Big Box  iOS development Detailed engineering -cocoapods


Guess you like

Origin www.cnblogs.com/chinatrump/p/11589010.html