Skip to content

Commit c84bc31

Browse files
Merge branch 'chris.thuyen/test/pod_cache_validator_2' into 'master'
chore(*): add test for PodCacheValidator + lint fixes See merge request mobile/dax-ios/cocoapods-binary-cache!16
2 parents 6c2b118 + 82b2a00 commit c84bc31

File tree

7 files changed

+37
-31
lines changed

7 files changed

+37
-31
lines changed

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ inherit_from:
33

44
AllCops:
55
Exclude:
6+
- 'PodBinaryCacheExample/**/*'
67
- 'lib/cocoapods-binary-cache/pod-binary/**/*'
78
- 'lib/cocoapods-binary-cache/pod-rome/**/*'

lib/cocoapods-binary-cache/prebuild_config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Use of this source code is governed by an MIT-style license that can be found in the LICENSE file
33

44
class PrebuildConfig
5-
@CONFIGURATION = "Debug"
5+
@CONFIGURATION = 'Debug'
66

77
class << self
88
attr_accessor :CONFIGURATION

lib/cocoapods-binary-cache/prebuild_output.rb

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
require_relative 'helper/path_utils'
55

66
class PrebuildOutput
7-
def initialize(prebuildSandbox)
8-
@sandbox = prebuildSandbox
7+
def initialize(prebuild_sandbox)
8+
@sandbox = prebuild_sandbox
99
end
1010

1111
def delta_dir
12-
return "#{@sandbox.root}/../_Prebuild_delta"
12+
"#{@sandbox.root}/../_Prebuild_delta"
1313
end
1414

1515
def delta_file_path
16-
return "#{delta_dir}/changes.txt"
16+
"#{delta_dir}/changes.txt"
1717
end
1818

1919
def clean_delta_file
2020
puts "clean_delta_file: #{delta_file_path}"
21-
FileUtils.remove_entry(delta_file_path, force=true)
21+
FileUtils.remove_entry(delta_file_path, force = true)
2222
end
2323

2424
def create_dir_if_needed(dir)
@@ -36,7 +36,7 @@ def write_delta_file(updated, deleted)
3636
end
3737
puts "Pod prebuild changes were writen to file: #{file_path}"
3838
else
39-
puts "No changes in prebuild"
39+
puts 'No changes in prebuild'
4040
end
4141
end
4242

@@ -47,22 +47,20 @@ def process_prebuilt_dev_pods
4747

4848
# Inject project path (where the framework is built) to support generating code coverage later
4949
project_root = PathUtils.remove_last_path_component(@sandbox.standard_sanbox_path.to_s)
50-
template_file_path = devpod_output_path + "prebuilt_map"
50+
template_file_path = devpod_output_path + 'prebuilt_map'
5151
File.open(template_file_path, 'w') do |file|
5252
file.write(project_root)
5353
end
5454

5555
Pod::Prebuild::CacheInfo.cache_miss_dev_pods_dic.each do |name, hash|
5656
puts "Output dev pod lib: #{name} hash: #{hash}"
5757
built_lib_path = @sandbox.framework_folder_path_for_target_name(name)
58-
if File.directory?(built_lib_path)
59-
FileUtils.cp(template_file_path, "#{built_lib_path}/#{name}.framework")
58+
next unless File.directory?(built_lib_path)
6059

61-
target_dir = "#{devpod_output_path}#{name}_#{hash}"
62-
puts "From: #{built_lib_path} -> #{target_dir}"
63-
FileUtils.cp_r(built_lib_path, target_dir)
64-
end
60+
FileUtils.cp(template_file_path, "#{built_lib_path}/#{name}.framework")
61+
target_dir = "#{devpod_output_path}#{name}_#{hash}"
62+
puts "From: #{built_lib_path} -> #{target_dir}"
63+
FileUtils.cp_r(built_lib_path, target_dir)
6564
end
66-
6765
end
68-
end
66+
end

lib/cocoapods-binary-cache/scheme_editor.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
require 'rexml/document'
55

66
class SchemeEditor
7-
87
def self.edit_to_support_code_coverage(sandbox)
9-
108
pod_proj_path = sandbox.project_path
119
puts "Modify schemes of pod project to support code coverage of prebuilt local pod: #{pod_proj_path}"
1210
scheme_files = Dir["#{pod_proj_path}/**/*.xcscheme"]
@@ -24,12 +22,14 @@ def self.edit_to_support_code_coverage(sandbox)
2422
test_action.add_attribute('codeCoverageEnabled', 'YES')
2523
test_action.add_attribute('onlyGenerateCoverageForSpecifiedTargets', 'YES')
2624
coverage_targets = REXML::Element.new('CodeCoverageTargets')
27-
buildable_ref = scheme.elements['BuildAction'].elements['BuildActionEntries'].elements['BuildActionEntry'].elements['BuildableReference']
25+
buildable_ref = scheme.elements['BuildAction'] \
26+
.elements['BuildActionEntries'] \
27+
.elements['BuildActionEntry'] \
28+
.elements['BuildableReference']
2829
new_buildable_ref = buildable_ref.clone # Need to clone, otherwise the original one will be move to new place
2930
coverage_targets.add_element(new_buildable_ref)
3031
test_action.add_element(coverage_targets)
3132
File.open(file_path, 'w') { |f| doc.write(f) }
3233
end
3334
end
34-
35-
end
35+
end

lib/cocoapods_plugin.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# Use of this source code is governed by an MIT-style license that can be found in the LICENSE file
33

44
require 'cocoapods-binary-cache/main'
5-
require 'command/binary_cache'
5+
require 'command/binary_cache'

lib/command/binary_cache.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Command
88
class BinaryCache < Command
99
include Command::ProjectDirectory
1010

11-
self.summary = "Pod Binary Cache commands"
11+
self.summary = 'Pod Binary Cache commands'
1212

1313
self.description = <<-DESC
1414
Fetch/Prebuild pod frameworks
@@ -24,7 +24,7 @@ def initialize(argv)
2424
@podspec_name = argv.shift_argument
2525
@cmd = argv.option('cmd', nil)
2626
@push_vendor_pods = argv.option('push_vendor_pods', nil)
27-
puts "BinaryCache run: #{@cmd}"
27+
Pod::UI.puts "BinaryCache run: #{@cmd}"
2828
super
2929
end
3030

@@ -34,20 +34,19 @@ def run
3434
dep_graph = DependenciesGraph.new(config.lockfile)
3535
fmt = 'png'
3636
name = 'graph'
37-
dep_graph.write_graphic_file(fmt, filename=name, highlight_nodes=Set[])
37+
dep_graph.write_graphic_file(fmt, filename = name, highlight_nodes = Set[])
3838
system("open #{name}.#{fmt}")
3939
return
4040
end
4141

4242
config_file_path = "#{config.installation_root}/PodBinaryCacheConfig.json"
43-
if not File.exists?(config_file_path)
44-
raise "#{config_file_path} not exist"
45-
end
43+
raise "#{config_file_path} not exist" unless File.exist?(config_file_path)
44+
4645
py_cmd = []
47-
py_cmd << "python3" << "#{__dir__}/PythonScripts/prebuild_lib_cli.py"
46+
py_cmd << 'python3' << "#{__dir__}/PythonScripts/prebuild_lib_cli.py"
4847
py_cmd << "--cmd #{@cmd}" << "--config_path #{config_file_path}"
4948
py_cmd << "--push_vendor_pods #{@push_vendor_pods}" unless @push_vendor_pods.nil?
50-
system py_cmd.join(" ")
49+
system py_cmd.join(' ')
5150
end
5251
end
5352
end

spec/pod_cache_validator_spec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,20 @@
2424

2525
context 'some cache miss due to not present' do
2626
let(:pod_lockfile) { gen_lockfile(pods: pods.merge('D' => '0.0.5')) }
27-
it 'returns some missed, some hit', :skip do
27+
it 'returns some missed, some hit' do
2828
skip 'code does not pass this test' # TODO (thuyen): Fix code
2929

3030
expect(@missed).to eq(['D'].to_set)
3131
expect(@hit).to eq(pods.keys.to_set)
3232
end
3333
end
34+
35+
context 'no cache due to no pod_bin_lockfile' do
36+
let(:pod_bin_lockfile) { nil }
37+
it 'returns all missed' do
38+
expect(@missed).to eq(pods.keys.to_set)
39+
expect(@hit).to be_empty
40+
end
41+
end
3442
end
3543
end

0 commit comments

Comments
 (0)