cocoapods-podspec-binary 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f72431b055019b6e7378fb89425060fd38fd73a574a857831af8d21366fa232a
4
+ data.tar.gz: c427ddfdaf904ca14d68028d03caf4c1826211147f0a3a979cceb3404696dcfd
5
+ SHA512:
6
+ metadata.gz: 1e2f9b66964e91d6becd2e3177520ebac2cb54c8b334d6aac09359aebbd4bfa2fa878a743c1f4e16190c86a17c03698793e15235ce6b80ea76feeec7e5c6b114
7
+ data.tar.gz: e361d70899cea6182de506a59fe5dae029fcca3fc0399e478a08811627023ba625c5ce0e043b611808f7c3ca42fc49ae4836b0d8f8c39bb42395a14240ba725b
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cocoapods-podspec-binary/mbuild/mbuild_binary'
4
+ require 'cocoapods-podspec-binary/mbuild/mbuild_project'
5
+ require 'cocoapods-podspec-binary/config/mbuild_config'
6
+
7
+ module Pod
8
+ class Command
9
+ # This is an example of a cocoapods plugin adding a top-level subcommand
10
+ # to the 'pod' command.
11
+ #
12
+ # You can also create subcommands of existing or new commands. Say you
13
+ # wanted to add a subcommand to `list` to show newly deprecated pods,
14
+ # (e.g. `pod list deprecated`), there are a few things that would need
15
+ # to change.
16
+ #
17
+ # - move this file to `lib/pod/command/list/deprecated.rb` and update
18
+ # the class to exist in the the Pod::Command::List namespace
19
+ # - change this class to extend from `List` instead of `Command`. This
20
+ # tells the plugin system that it is a subcommand of `list`.
21
+ # - edit `lib/cocoapods_plugins.rb` to require this file
22
+ #
23
+ # @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
24
+ # in the `plugins.json` file, once your plugin is released.
25
+ #
26
+ class MBuild < Command
27
+ self.summary = 'Used to generate binaries via podspec'
28
+ self.abstract_command = false
29
+ self.command = 'mbuild'
30
+ self.description = <<-DESC
31
+ cocoapods binary plugin for iOS code precompilation, supports framework and xcframework
32
+ DESC
33
+
34
+ self.arguments = [
35
+ CLAide::Argument.new('NAME', false)
36
+ ]
37
+
38
+ def initialize(argv)
39
+ @framework = argv.flag?('framework', true)
40
+ @xcframework = argv.flag?('xcframework', false)
41
+ @pod_name = argv.shift_argument
42
+ @pod_version = argv.shift_argument
43
+ @config_instance = MBuildConfig.instance
44
+ @build_dir = @config_instance.mbuild_dir
45
+ @sources = argv.option('sources')
46
+ super
47
+ end
48
+
49
+ def self.options
50
+ [
51
+ ['--framework', 'Used to generate the framework '],
52
+ ['--xcframework', 'Used to generate the xcframework '],
53
+ ['--sources=[sources]', 'The sources from which to pull dependent pods ']
54
+ ].concat(super).reject { |(name, _)| name == 'name' }
55
+ end
56
+
57
+ def run
58
+ prepare
59
+ generate_project
60
+ build_binary
61
+ export_binary
62
+ end
63
+
64
+ def prepare
65
+ init_config
66
+ MBuildFileUtils.create_folder(@build_dir)
67
+ Dir.chdir(@build_dir)
68
+ BuildProject.new.prepare_project
69
+ end
70
+
71
+ def init_config
72
+ mbuild_yml = File.join(Dir.pwd, '.mbuild.yml')
73
+ if File.file?(mbuild_yml)
74
+ @config_instance.load_config
75
+ else
76
+ @config_instance.command_config(@pod_name, @pod_version)
77
+ end
78
+ @config_instance.library_type = @xcframework ? BinaryType::XCFRAMEWORK : BinaryType::FRAMEWORK
79
+ puts "Preparing to generate the binary version of #{@pod_name}:#{@pod_version}."
80
+ return unless @sources
81
+
82
+ @config_instance.sources = @sources
83
+ end
84
+
85
+ def generate_project
86
+ BuildProject.new.generate_project
87
+ end
88
+
89
+ def build_binary
90
+ puts "Commencing the build of #{@pod_name}:#{@pod_version}."
91
+ project_dir = File.join(@build_dir, 'BinaryProj/Example')
92
+ Dir.chdir(project_dir)
93
+ binary_type = @xcframework ? BinaryType::XCFRAMEWORK : BinaryType::FRAMEWORK
94
+ build_binary = BuildBinary.new(binary_type)
95
+ build_binary.build
96
+ puts "The successful build of the #{@pod_name}:#{@pod_version} #{@binary_type}."
97
+ end
98
+
99
+ def export_binary
100
+ puts 'Exporting binary files.'
101
+ export_dir = @config_instance.root_dir
102
+ FileUtils.cp_r("#{@build_dir}/#{@pod_name}-#{@pod_version}", export_dir)
103
+ FileUtils.rm_rf("#{@build_dir}/#{@pod_name}-#{@pod_version}")
104
+ puts 'Task execution completed.'
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ # import
4
+ require 'cocoapods-podspec-binary/command/mbuild'
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'singleton'
4
+ require 'yaml'
5
+
6
+ # Plugin configuration
7
+ class MBuildConfig
8
+ include Singleton
9
+
10
+ attr_reader :mbuild_dir, :root_dir
11
+ attr_accessor :pod_name, :pod_version, :swift, :sources, :library_type
12
+
13
+ def initialize
14
+ @root_dir = Dir.pwd
15
+ @mbuild_dir = File.join(Dir.home, '.mbuild')
16
+ end
17
+
18
+ def load_config
19
+ mbuild_yml = File.join(@root_dir, '.mbuild.yml')
20
+ return unless File.file?(mbuild_yml)
21
+
22
+ mbuild_params = YAML.load_file(mbuild_yml)
23
+ validate_required_config(mbuild_params, 'pod_name', 'pod_version')
24
+ @pod_name = mbuild_params['program']['pod_name']
25
+ @pod_version = mbuild_params['program']['pod_version']
26
+ end
27
+
28
+ def command_config(pod_name, pod_version)
29
+ @pod_name = pod_name
30
+ @pod_version = pod_version
31
+ end
32
+
33
+ private
34
+
35
+ def validate_required_config(data, *keys)
36
+ raise ArgumentError, 'program is required in the configuration file.' unless data['program']
37
+
38
+ config = data['program']
39
+ keys.each do |key|
40
+ raise ArgumentError, "#{key} is required in the configuration file." unless config[key]
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module CocoapodsPodspecBinary
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Build binary types enumeration
4
+ module BinaryType
5
+ FRAMEWORK = 'framework'
6
+ XCFRAMEWORK = 'xcframework'
7
+ STATIC_LIBRARY = 'static_library'
8
+ end
9
+
10
+ # Class build framework
11
+ class BuildBinary
12
+ def initialize(binary_type)
13
+ @config_instance = MBuildConfig.instance
14
+ @binary_type = binary_type
15
+ @pod_name = @config_instance.pod_name
16
+ @pod_version = @config_instance.pod_version
17
+ end
18
+
19
+ def build
20
+ clean
21
+ Dir.chdir('Pods') do
22
+ build_iphoneos_framework
23
+ build_iphonesimulator_framework
24
+ end
25
+ framework = create_universal_framework
26
+ generate_final_binary(framework)
27
+ generate_cache_file
28
+ end
29
+
30
+ def clean
31
+ binary_dir = "#{@config_instance.mbuild_dir}/#{@pod_name}"
32
+ FileUtils.rm_rf(binary_dir) if Dir.exist?(binary_dir)
33
+ clean_cmd = 'xcodebuild clean'
34
+ system clean_cmd
35
+ end
36
+
37
+ def build_iphoneos_framework
38
+ build_cmd = "xcodebuild build -target #{@pod_name} -sdk iphoneos -arch arm64 -quiet"
39
+ system build_cmd
40
+ end
41
+
42
+ def build_iphonesimulator_framework
43
+ build_cmd = "xcodebuild build -target #{@pod_name} -sdk iphonesimulator -arch x86_64 -quiet"
44
+ system build_cmd
45
+ end
46
+
47
+ def create_universal_framework
48
+ iphoneos_framework = "./build/Release-iphoneos/#{@pod_name}/#{@pod_name}.framework"
49
+ simulator_framework = iphoneos_framework.gsub('iphoneos', 'iphonesimulator')
50
+ if @binary_type == BinaryType::FRAMEWORK
51
+ build_framework(iphoneos_framework, simulator_framework)
52
+ else
53
+ build_xcframework(iphoneos_framework, simulator_framework)
54
+ end
55
+ iphoneos_framework.gsub("#{@pod_name}.framework", '')
56
+ end
57
+
58
+ def generate_final_binary(framework)
59
+ binary_dir = "#{@config_instance.mbuild_dir}/#{@pod_name}-#{@pod_version}"
60
+ Dir.mkdir(binary_dir) unless Dir.exist? binary_dir
61
+ FileUtils.cp_r(framework, binary_dir)
62
+ podspec_file = "#{Dir.pwd}/#{@pod_name}.podspec.json"
63
+ FileUtils.cp_r(podspec_file, binary_dir)
64
+ end
65
+
66
+ def generate_cache_file
67
+ binary_dir = "#{@config_instance.mbuild_dir}/#{@pod_name}-#{@pod_version}/Podfile.lock"
68
+ FileUtils.cp_r("#{@config_instance.mbuild_dir}/BinaryProj/Example/Podfile.lock", binary_dir)
69
+ end
70
+
71
+ private
72
+
73
+ def build_framework(iphoneos_framework, simulator_framework)
74
+ iphoneos_binary = "#{iphoneos_framework}/#{@pod_name}"
75
+ output_framework = iphoneos_binary
76
+ simulator_binary = "#{simulator_framework}/#{@pod_name}"
77
+ lipo_cmd = "ipo -create #{iphoneos_binary} #{simulator_binary} -output #{output_framework}"
78
+ system lipo_cmd
79
+ output_framework
80
+ end
81
+
82
+ def build_xcframework(iphoneos_framework, simulator_framework)
83
+ output_xcframework = iphoneos_framework.gsub('.framework', '.xcframework')
84
+ xcbuild = "xcodebuild -create-xcframework -framework #{iphoneos_framework}"
85
+ build_xcframework = "#{xcbuild} -framework #{simulator_framework} -output #{output_xcframework}"
86
+ system build_xcframework
87
+ output_xcframework
88
+ end
89
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/object/duplicable'
4
+
5
+ # Plugins/custom_plugin.rb
6
+
7
+ module Pod
8
+ module Downloader
9
+ # class
10
+ class Request
11
+ old_method = instance_method(:validate!)
12
+ define_method(:validate!) do
13
+ pod_name = MBuildConfig.instance.pod_name
14
+ pod_version = MBuildConfig.instance.pod_version
15
+ if spec.name == pod_name && spec.version.to_s == pod_version
16
+ podspec_hash = spec.attributes_hash.deep_dup
17
+ Pod::MbuildPodspec.new(podspec_hash).generate_podspec
18
+ end
19
+ old_method.bind(self).call
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ # Returns a deep copy of hash.
26
+ class Object
27
+ def deep_dup
28
+ duplicable? ? dup : self
29
+ end
30
+ end
31
+
32
+ # Returns a deep copy of Array.
33
+ class Array
34
+ def deep_dup
35
+ map(&:deep_dup)
36
+ end
37
+ end
38
+
39
+ # Returns a deep copy of hash.
40
+ class Hash
41
+ def deep_dup
42
+ hash = dup
43
+ each_pair do |key, value|
44
+ if key.is_a?(::String) || key.is_a?(::Symbol)
45
+ hash[key] = value.deep_dup
46
+ else
47
+ hash.delete(key)
48
+ hash[key.deep_dup] = value.deep_dup
49
+ end
50
+ end
51
+ hash
52
+ end
53
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+
5
+ module Pod
6
+ # generate podspec
7
+ class MbuildPodspec
8
+ def initialize(podspec_hash)
9
+ @binary_type = MBuildConfig.instance.library_type == BinaryType::FRAMEWORK ? 'framework' : 'xcframework'
10
+ @config_instance = MBuildConfig.instance
11
+ @pod_name = MBuildConfig.instance.pod_name
12
+ @pod_version = MBuildConfig.instance.pod_version
13
+ @podspec_hash = podspec_hash
14
+ end
15
+
16
+ def generate_podspec
17
+ binary_spec_version
18
+ binary_spec_source
19
+ binary_spec_framework
20
+ binary_spec_lib
21
+ binary_spec_public_header_files
22
+ binary_private_header_files
23
+ write_podspec_to_file
24
+ end
25
+
26
+ private
27
+
28
+ def write_podspec_to_file
29
+ podspec_file = "#{Dir.pwd}/#{@pod_name}.podspec.json"
30
+ podspec_json = JSON.pretty_generate(@podspec_hash)
31
+ File.write(podspec_file, podspec_json)
32
+ end
33
+
34
+ def binary_spec_source
35
+ @podspec_hash['source'] = { 'http': 'The location where files are stored' }
36
+ end
37
+
38
+ def binary_spec_version
39
+ @podspec_hash['version'] = @pod_version
40
+ end
41
+
42
+ def binary_spec_framework
43
+ vendored_frameworks_array = []
44
+ vendored_frameworks_array << "#{@pod_name}/*.#{@binary_type}"
45
+ @podspec_hash['vendored_frameworks'] = vendored_frameworks_array
46
+ end
47
+
48
+ def binary_private_header_files
49
+ return unless @podspec_hash['private_header_files']
50
+
51
+ @podspec_hash['private_header_files'] =
52
+ if @binary_type == 'xcframework'
53
+ "#{@pod_name}/*.#{@binary_type}/ios-arm64/*.framework/privateHeaders/*.h"
54
+ else
55
+ "#{@pod_name}/*.#{@binary_type}/privateHeaders/*.h"
56
+ end
57
+ end
58
+
59
+ def binary_spec_lib
60
+ return unless @podspec_hash['libraries']
61
+
62
+ @podspec_hash['libraries'] = Array(@podspec_hash['libraries'])
63
+ end
64
+
65
+ def binary_spec_public_header_files
66
+ @podspec_hash.delete('default_subspecs') if @podspec_hash.key?('default_subspecs')
67
+ @podspec_hash.delete('source_files') if @podspec_hash.key?('source_files')
68
+ @podspec_hash.delete('public_header_files') if @podspec_hash.key?('public_header_files')
69
+ @podspec_hash['public_header_files'] = "#{@pod_name}/Headers/*.h"
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cocoapods'
4
+
5
+ # Class prepare project
6
+ class BuildProject
7
+ def initialize
8
+ @config_instance = MBuildConfig.instance
9
+ @project_dir = File.join(MBuildConfig.instance.mbuild_dir, 'BinaryProj/Example')
10
+ end
11
+
12
+ def prepare_project
13
+ example_dir = File.join(MBuildConfig.instance.mbuild_dir, 'BinaryProj')
14
+ if File.directory?(example_dir)
15
+ Git.open(example_dir).reset_hard
16
+ Git.open(example_dir).clean(force: true)
17
+ Git.open(example_dir).pull
18
+ else
19
+ MBuildFileUtils.create_folder(@project_dir)
20
+ example_url = 'git@github.com:HuolalaTech/hll-cocoapods-podspec-binary.git'
21
+ Git.clone(example_url, example_dir)
22
+ end
23
+ end
24
+
25
+ def generate_project
26
+ config_instance = MBuildConfig.instance
27
+ add_build_settings if config_instance.swift
28
+ update_podfile
29
+ project_install
30
+ end
31
+
32
+ def update_podfile
33
+ podfile_path = File.join(@project_dir, 'Podfile')
34
+ podfile_content = File.read(podfile_path)
35
+ pod_name = @config_instance.pod_name
36
+ pod_version = @config_instance.pod_version
37
+ new_content = podfile_content.gsub('BINARY_NAME', pod_name).gsub('BINARY_VERSION', pod_version)
38
+ if @config_instance.sources
39
+ new_content.prepend(@config_instance.sources.split(',').map { |it| "source \"#{it.strip}\"\n" }.join)
40
+ end
41
+
42
+ File.open(podfile_path, 'w') { |file| file.puts new_content }
43
+ end
44
+
45
+ def project_install
46
+ Dir.chdir(@project_dir) do
47
+ update_argv = []
48
+ update_command = Pod::Command::Update.new(CLAide::ARGV.new(update_argv))
49
+ update_command.run
50
+ end
51
+ end
52
+
53
+ def add_build_settings
54
+ File.open('Podfile', 'a+') do |podfile|
55
+ podfile.puts build_settings_code
56
+ end
57
+ end
58
+
59
+ def build_settings_code
60
+ <<~CODE
61
+ post_install do |installer|
62
+ installer.pods_project.targets.each do |target|
63
+ target.build_configurations.each do |config|
64
+ config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
65
+ end
66
+ end
67
+ end
68
+ CODE
69
+ end
70
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zlib'
4
+
5
+ # FileUtils: A utility class for file operations.
6
+ class MBuildFileUtils
7
+ def self.create_folder(folder_path)
8
+ return if File.directory?(folder_path)
9
+
10
+ begin
11
+ Dir.mkdir(folder_path)
12
+ rescue SystemCallError => e
13
+ puts "Error creating folder: #{e.message}"
14
+ end
15
+ end
16
+
17
+ def self.compress_file(input_file, output_file)
18
+ File.open(input_file, 'rb') do |input|
19
+ Zlib::GzipWriter.open(output_file) do |output|
20
+ output.write(input.read)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'git'
4
+
5
+ # git utils
6
+ class GitUtils
7
+ # git utils
8
+ def initialize(repository_path)
9
+ @repository = open_git_repository(repository_path)
10
+ end
11
+
12
+ def open_git_repository(repository_path)
13
+ Git.open(repository_path)
14
+ end
15
+
16
+ def clone(remote_url, destination_path)
17
+ Git.clone(remote_url, destination_path)
18
+ end
19
+
20
+ def pull
21
+ @repository.pull
22
+ end
23
+
24
+ def commit(message)
25
+ @repository.add(all: true)
26
+ @repository.commit(message)
27
+ end
28
+
29
+ def push(remote_name = 'origin', branch_name = 'master')
30
+ @repository.push(remote_name, branch_name)
31
+ end
32
+
33
+ def status
34
+ @repository.status
35
+ end
36
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ # impoart
4
+ require 'cocoapods-podspec-binary/gem_version'
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # impoart
4
+ require 'cocoapods-podspec-binary'
5
+ require 'cocoapods-podspec-binary/command/mbuild'
6
+ require 'cocoapods-podspec-binary/mbuild/mbuild_hook'
7
+ require 'cocoapods-podspec-binary/mbuild/mbuild_podspec'
8
+ require 'cocoapods-podspec-binary/utils/file_utils'
9
+ require 'cocoapods-podspec-binary/utils/git_utils'
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-podspec-binary
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - pengpeng.dai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-03-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A short description of cocoapods-podspec-binary.
42
+ email:
43
+ - pengpeng.dai@huolala.cn
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/cocoapods-podspec-binary.rb
49
+ - lib/cocoapods-podspec-binary/command.rb
50
+ - lib/cocoapods-podspec-binary/command/mbuild.rb
51
+ - lib/cocoapods-podspec-binary/config/mbuild_config.rb
52
+ - lib/cocoapods-podspec-binary/gem_version.rb
53
+ - lib/cocoapods-podspec-binary/mbuild/mbuild_binary.rb
54
+ - lib/cocoapods-podspec-binary/mbuild/mbuild_hook.rb
55
+ - lib/cocoapods-podspec-binary/mbuild/mbuild_podspec.rb
56
+ - lib/cocoapods-podspec-binary/mbuild/mbuild_project.rb
57
+ - lib/cocoapods-podspec-binary/utils/file_utils.rb
58
+ - lib/cocoapods-podspec-binary/utils/git_utils.rb
59
+ - lib/cocoapods_plugin.rb
60
+ homepage: https://github.com/EXAMPLE/cocoapods-podspec-binary
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubygems_version: 3.4.6
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: A longer description of cocoapods-podspec-binary.
83
+ test_files: []