Class: Tdfire::BinarySpecificationRefactor

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-tdfire-binary/binary_specification_refactor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_spec) ⇒ BinarySpecificationRefactor

Returns a new instance of BinarySpecificationRefactor.



42
43
44
# File 'lib/cocoapods-tdfire-binary/binary_specification_refactor.rb', line 42

def initialize(target_spec)
	@target_spec = target_spec
end

Instance Attribute Details

#target_specObject

Returns the value of attribute target_spec.



40
41
42
# File 'lib/cocoapods-tdfire-binary/binary_specification_refactor.rb', line 40

def target_spec
  @target_spec
end

Instance Method Details

#configure_binary_default_subspec_with_reference_spec(spec) ⇒ Object

——————————————————————–# 生成default subspec TdfireBinary ,并将源码依赖时的配置转移到此 subspec 上



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/cocoapods-tdfire-binary/binary_specification_refactor.rb', line 48

def configure_binary_default_subspec_with_reference_spec(spec)
	default_subspec = "TdfireBinary"
	target_spec.subspec default_subspec do |ss|
		subspec_refactor = BinarySpecificationRefactor.new(ss)
		subspec_refactor.configure_binary_with_reference_spec(spec)
	end

	# 创建源码依赖时的 subspec,并且设置所有的 subspec 依赖 default_subspec
	spec.subspecs.each do |s|
		target_spec.subspec s.base_name do |ss|
			ss.dependency "#{target_spec.root.name}/#{default_subspec}"
		end
	end

	target_spec.default_subspec = default_subspec
	target_spec.default_subspec = default_subspec

	Pod::UI.message "Tdfire: subspecs for #{target_spec.name}: #{target_spec.subspecs.map(&:name).join(', ')}"
end

#configure_binary_with_reference_spec(spec) ⇒ Object

——————————————————————–# spec 是二进制依赖时的配置



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/cocoapods-tdfire-binary/binary_specification_refactor.rb', line 70

def configure_binary_with_reference_spec(spec)
	# 组件 frameworks 的依赖
	target_spec.vendored_frameworks = "#{target_spec.root.name}.framework"
	# target_spec.source_files = "#{target_spec.root.name}.framework/Headers/*"
	# target_spec.public_header_files = "#{target_spec.root.name}.framework/Headers/*"

	# 保留对 frameworks lib 的依赖
    %w[frameworks libraries weak_frameworks].each do |name|
      target_spec.store_array_value_with_attribute_and_reference_spec(name, spec)
    end

    # 保留对其他组件的依赖
    target_spec.store_hash_value_with_attribute_and_reference_spec('dependencies', spec) do |name|
		# 去除对自身子组件的依赖
		name.split('/').first != target_spec.root.name
	end

	Pod::UI.message "Tdfire: dependencies for #{target_spec.name}: #{target_spec.dependencies.map(&:name).join(', ')}"
end

#set_framework_download_scriptObject

——————————————————————–#



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/cocoapods-tdfire-binary/binary_specification_refactor.rb', line 117

def set_framework_download_script
	download_url = BinaryUrlManager.pull_url_for_pod_version(target_spec.root.name, target_spec.version)

	download_script = <<-EOF
      #!/bin/sh

      if [[ -d #{framework_name} ]]; then
        echo "Tdfire: #{framework_name} is not empty"
        exit 0
      fi

      if [[ ! -d tdfire_download_temp ]]; then
        mkdir tdfire_download_temp
      fi

      cd tdfire_download_temp

      curl --fail -O -J -v #{download_url}

      if [[ -f #{framework_name}.zip ]]; then
        echo "Tdfire: copying #{framework_name} ..."

        unzip #{framework_name}.zip
        cp -fa #{framework_name} ../
      fi

      cd ..
      rm -fr tdfire_download_temp

      echo "pod cache path for #{target_spec.root.name}: $(pwd)"
    EOF

    combined_download_script = %Q[echo '#{download_script}' > download.sh && sh download.sh && rm download.sh]
    combined_download_script += " && " << target_spec.prepare_command unless target_spec.prepare_command.nil?

    target_spec.prepare_command = combined_download_script
end

#set_preserve_paths_with_reference_spec(spec) ⇒ Object

——————————————————————–# spec 是源码依赖时的配置



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/cocoapods-tdfire-binary/binary_specification_refactor.rb', line 92

def set_preserve_paths_with_reference_spec(spec)
	# 源码、资源文件
    source_files = spec.all_array_value_for_attribute('source_files')
    resources = spec.all_array_value_for_attribute('resources')
    resource_bundles = spec.all_hash_value_for_attribute('resource_bundles')
    source_preserve_paths = source_files + resources + resource_bundles.values.flatten

    # 二进制文件
    framework_preserve_paths = [framework_name]
    preserve_paths = source_preserve_paths + framework_preserve_paths

    # 保留原有的 preserve_paths
    preserve_paths += target_spec.attributes_hash['preserve_paths'] unless target_spec.attributes_hash['preserve_paths'].nil?
    target_spec.preserve_paths = preserve_paths.uniq

    Pod::UI.message "Tdfire: preserve paths for #{target_spec.name}: #{preserve_paths.join(', ')}"
end

#set_use_static_frameworkObject

——————————————————————–#



112
113
114
# File 'lib/cocoapods-tdfire-binary/binary_specification_refactor.rb', line 112

def set_use_static_framework
	target_spec.static_framework = true
end