Class: Jxedt::Prebuild

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-jxedt/binary/prebuild.rb

Instance Method Summary collapse

Constructor Details

#initialize(source_installer) ⇒ Prebuild



70
71
72
# File 'lib/cocoapods-jxedt/binary/prebuild.rb', line 70

def initialize(source_installer)
    @source_installer = source_installer
end

Instance Method Details

#buildObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/cocoapods-jxedt/binary/prebuild.rb', line 98

def build
    check_sandbox = Jxedt::Sandbox.from_sandbox(@source_installer.sandbox)
    existed_target_names = check_sandbox.target_paths.map { |pair| pair.basename.to_s }
    targets = targets_to_prebuild.reject { |target| existed_target_names.include?(target.name.to_s) }

    Pod::UI.puts "Prebuild total count: #{targets.size}"
    Pod::UI.puts "Prebuild targets: #{ targets.map(&:name)}"
    return if targets.empty?

    require_relative 'pod-room/xcodebuild_command'

    clear_output_path
    case targets[0].platform.name
    when :ios, :tvos, :watchos
        Jxedt.config.support_configurations.each do |configuration|
            Pod::UI.puts "Prebuild configuration: #{configuration}"
            options = make_options
            options[:configuration] = configuration
            options[:targets] = targets
            options[:output_path] = output_path + configuration
            Jxedt::XcodebuildCommand.new(options).run
        end
    when :osx
        Jxedt.config.support_configurations.each do |configuration|
            Pod::UI.puts "Prebuild configuration: #{configuration}"
            options = make_options
            xcodebuild(
                sandbox: options[:sandbox],
                targets: targets,
                configuration: configuration,
                sdk: "macosx",
                args: options[:args]
            )
        end
    else
        raise "Unsupported platform for '#{targets[0].name}': '#{targets[0].platform.name}'"
    end

    make_prebuild(targets)
    clear_output_path
end

#build_dirObject



195
196
197
198
# File 'lib/cocoapods-jxedt/binary/prebuild.rb', line 195

def build_dir
    sandbox = @source_installer.sandbox
    sandbox.root.parent + "build"
end

#clear_output_pathObject



205
206
207
208
# File 'lib/cocoapods-jxedt/binary/prebuild.rb', line 205

def clear_output_path
    path = output_path
    path.rmtree if path.exist?
end

#make_optionsObject



180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/cocoapods-jxedt/binary/prebuild.rb', line 180

def make_options
    options = {}
    options[:sandbox] = @source_installer.sandbox
    options[:build_dir] = build_dir
    options[:output_path] = output_path
    options[:clean_build] = Jxedt.config.clean_build?
    options[:bitcode_enabled] = Jxedt.config.bitcode_enabled?
    options[:device_build_enabled] = Jxedt.config.device_build_enabled?
    options[:simulator_build_enabled] = Jxedt.config.simulator_build_enabled?
    options[:disable_dsym] = Jxedt.config.disable_dsym?
    options[:log_path] = Jxedt.config.build_log_path
    options[:args] = Jxedt.config.build_args
    options
end

#make_prebuild(targets) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/cocoapods-jxedt/binary/prebuild.rb', line 140

def make_prebuild(targets)
    lockfile = @source_installer.lockfile
    checksums = lockfile.internal_data["SPEC CHECKSUMS"] || {}
    checkout_options = lockfile.internal_data["CHECKOUT OPTIONS"] || {}
    
    # 目标binary路径
    binary_path = output_path.parent
    prebuild_targets = targets.map(&:name).to_a
    prebuild_targets.map {|target_name| 
        target_path = binary_path + target_name
        target_path.rmtree if target_path.exist?
    }

    # make prebuild files
    configurations = Jxedt.config.support_configurations
    Jxedt.config.support_configurations.each do |configuration|
        configuration_path = output_path + configuration
        next unless configuration_path.exist?
        
        configuration_path.children().each do |child|
            if child.directory? and (not child.children.empty?)
                name = child.basename.to_s
                next unless prebuild_targets.include?(name)

                target_path = binary_path + name
                target_path += configuration if configurations.size > 1
                target_path.mkpath unless target_path.exist?
                command = "cp -r #{child}/ #{target_path}"
                `#{command}`
                
                # touch checksum
                checksum = nil
                checksum = checkout_options[name][:commit] unless checkout_options[name].nil? # commitid有值则使用commitid
                checksum = checksums[name] if checksum.nil?
                `echo #{command} "\n" >> #{binary_path}/#{name}/#{checksum}.checksum` unless checksum.nil?
            end
        end
    end
end

#output_pathObject



200
201
202
203
# File 'lib/cocoapods-jxedt/binary/prebuild.rb', line 200

def output_path
    sandbox = @source_installer.sandbox
    sandbox.root + Jxedt.config.binary_dir + "GeneratedFrameworks"
end

#pods_to_prebuildObject



94
95
96
# File 'lib/cocoapods-jxedt/binary/prebuild.rb', line 94

def pods_to_prebuild
    targets_to_prebuild.map(&:name).to_a
end

#targets_to_prebuildObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/cocoapods-jxedt/binary/prebuild.rb', line 74

def targets_to_prebuild
    explicit_prebuild_pod_names = @source_installer.aggregate_targets.flat_map { |target| 
        target.target_definition.explicit_prebuild_pod_names
    }.uniq

    reject_prebuild_pod_names = @source_installer.aggregate_targets.flat_map { |target| 
        target.target_definition.reject_prebuild_pod_names 
    }.uniq
    
    targets = @source_installer.pod_targets.select { |target|
        next unless target.should_build?
        next unless target.name == target.pod_name
        next if reject_prebuild_pod_names.include?(target.pod_name)
        explicit_prebuild_pod_names.include?(target.pod_name) || Jxedt.config.all_binary_enabled?
    }
    targets.reject! { |target| @source_installer.sandbox.local?(target.pod_name) } unless Jxedt.config.dev_pods_enabled?
    targets.reject! { |target| Jxedt.config.excluded_pods.include?(target.pod_name) }
    targets
end