Skip to content

Commit 8bf62f2

Browse files
chore(*): add diagnosis
1 parent c4ba4b3 commit 8bf62f2

File tree

10 files changed

+138
-9
lines changed

10 files changed

+138
-9
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module PodPrebuild
2+
class BaseDiagnosis
3+
def initialize(options)
4+
@cache_validation = options[:cache_validation]
5+
@standard_sandbox = options[:standard_sandbox]
6+
end
7+
end
8+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require_relative "base"
2+
require_relative "integration"
3+
4+
module PodPrebuild
5+
class Diagnosis
6+
def initialize(options)
7+
@diagnosers = [
8+
IntegrationDiagnosis
9+
].map { |klazz| klazz.new(options) }
10+
end
11+
12+
def run
13+
@diagnosers.each(&:run)
14+
end
15+
end
16+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require_relative "base"
2+
3+
module PodPrebuild
4+
class IntegrationDiagnosis < BaseDiagnosis
5+
def run
6+
integrated = @standard_sandbox.root.glob("*/*.framework").map { |p| p.dirname.basename.to_s }
7+
should_be_integrated = if Pod::Podfile::DSL.prebuild_job? \
8+
then @cache_validation.hit + @cache_validation.missed \
9+
else @cache_validation.hit \
10+
end
11+
should_be_integrated = should_be_integrated.map { |name| name.split("/")[0] }
12+
unintegrated = (should_be_integrated - integrated)
13+
Pod::UI.puts "🚩 Unintegrated frameworks: #{unintegrated}".yellow unless unintegrated.empty?
14+
end
15+
end
16+
end

lib/cocoapods-binary-cache/env.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module PodPrebuild
2+
class Env
3+
@stage_idx = 0
4+
5+
class << self
6+
def reset!
7+
@stage_idx = 0
8+
@stages = nil
9+
end
10+
11+
def next_stage!
12+
@stage_idx += 1 if @stage_idx < stages.count - 1
13+
end
14+
15+
def stages
16+
@stages ||= Pod::Podfile::DSL.prebuild_job? ? [:prebuild, :integration] : [:integration]
17+
end
18+
19+
def current_stage
20+
stages[@stage_idx]
21+
end
22+
23+
def prebuild_stage?
24+
current_stage == :prebuild
25+
end
26+
27+
def integration_stage?
28+
current_stage == :integration
29+
end
30+
end
31+
end
32+
end

lib/cocoapods-binary-cache/hooks/post_install.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,28 @@ def initialize(installer_context)
55
end
66

77
def run
8+
edit_scheme_for_code_coverage if PodPrebuild::Env.prebuild_stage?
9+
diagnose if PodPrebuild::Env.integration_stage?
10+
end
11+
12+
private
13+
14+
def diagnose
15+
Pod::UI.section("Diagnosing cocoapods-binary-cache") do
16+
PodPrebuild::Diagnosis.new(
17+
cache_validation: PodPrebuild::StateStore.cache_validation,
18+
standard_sandbox: @installer_context.sandbox
19+
).run
20+
end
21+
end
22+
23+
def edit_scheme_for_code_coverage
824
return unless Pod::Podfile::DSL.dev_pods_enabled && @installer_context.sandbox.instance_of?(Pod::PrebuildSandbox)
925

1026
# Modify pods scheme to support code coverage
1127
# If we don't prebuild dev pod -> no need to care about this in Pod project
1228
# because we setup in the main project (ex. DriverCI scheme)
13-
SchemeEditor.edit_to_support_code_coverage(@installer_context.sandbox) if Pod.is_prebuild_stage
29+
SchemeEditor.edit_to_support_code_coverage(@installer_context.sandbox)
1430
end
1531
end
1632
end

lib/cocoapods-binary-cache/hooks/pre_install.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ def initialize(installer_context)
1313
end
1414

1515
def run
16+
return if @installer_context.sandbox.is_a?(Pod::PrebuildSandbox)
17+
1618
require_relative "../pod-binary/helper/feature_switches"
17-
return if Pod.is_prebuild_stage
1819

1920
log_section "🚀 Prebuild frameworks"
2021
ensure_valid_podfile
@@ -25,6 +26,8 @@ def run
2526
Pod::UI.section("Validate prebuilt cache") { validate_cache }
2627
prebuild! if Pod::Podfile::DSL.prebuild_job?
2728
reset_environment
29+
30+
PodPrebuild::Env.next_stage!
2831
log_section "🤖 Resume pod installation"
2932
require_relative "../pod-binary/integration"
3033
end
@@ -54,7 +57,6 @@ def ensure_valid_podfile
5457

5558
def prepare_environment
5659
Pod::UI.puts "Prepare environment"
57-
Pod.is_prebuild_stage = true
5860
Pod::Podfile::DSL.enable_prebuild_patch true # enable sikpping for prebuild targets
5961
Pod::Installer.force_disable_integration true # don't integrate targets
6062
Pod::Config.force_disable_write_lockfile true # disbale write lock file for perbuild podfile
@@ -63,7 +65,6 @@ def prepare_environment
6365

6466
def reset_environment
6567
Pod::UI.puts "Reset environment"
66-
Pod.is_prebuild_stage = false
6768
Pod::Installer.force_disable_integration false
6869
Pod::Podfile::DSL.enable_prebuild_patch false
6970
Pod::Config.force_disable_write_lockfile false

lib/cocoapods-binary-cache/main.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
require_relative "helper/lockfile"
1010
require_relative "helper/path_utils"
1111
require_relative "helper/podspec"
12+
require_relative "env"
1213
require_relative "state_store"
1314
require_relative "hooks/post_install"
1415
require_relative "hooks/pre_install"
@@ -19,3 +20,4 @@
1920
require_relative "prebuild_output/metadata"
2021
require_relative "prebuild_output/output"
2122
require_relative "scheme_editor"
23+
require_relative "diagnosis/diagnosis"

lib/cocoapods-binary-cache/pod-binary/helper/feature_switches.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
require_relative "prebuild_sandbox"
33

44
module Pod
5-
6-
# a flag that indicate stages
7-
class_attr_accessor :is_prebuild_stage
8-
95
# a switch for the `pod` DSL to make it only valid for ':binary => true'
106
class Podfile
117
module DSL

lib/cocoapods-binary-cache/pod-binary/prebuild.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def collect_metadata(target, output_path)
218218
old_method2 = instance_method(:run_plugins_post_install_hooks)
219219
define_method(:run_plugins_post_install_hooks) do
220220
old_method2.bind(self).call
221-
prebuild_frameworks! if Pod.is_prebuild_stage && Pod::Podfile::DSL.prebuild_job?
221+
prebuild_frameworks! if PodPrebuild::Env.prebuild_stage?
222222
end
223223
end
224224
end

spec/env/env_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
describe "PodPrebuild::Env" do
2+
describe "stages" do
3+
let(:prebuild_job) { false }
4+
before do
5+
PodPrebuild::Env.reset!
6+
allow(Pod::Podfile::DSL).to receive(:prebuild_job?).and_return(prebuild_job)
7+
end
8+
9+
def expect_current_stage_as(stage)
10+
expect(PodPrebuild::Env.current_stage).to eq(stage)
11+
expect(PodPrebuild::Env.prebuild_stage?).to be(stage == :prebuild)
12+
expect(PodPrebuild::Env.integration_stage?).to be(stage == :integration)
13+
end
14+
15+
context "in a prebuild job" do
16+
let(:prebuild_job) { true }
17+
18+
it "has 2 stages: prebuild and integration" do
19+
expect(PodPrebuild::Env.stages).to eq([:prebuild, :integration])
20+
end
21+
22+
it "initially lands on prebuild stage" do
23+
expect_current_stage_as(:prebuild)
24+
end
25+
26+
it "transits to integration stage on next" do
27+
PodPrebuild::Env.next_stage!
28+
expect_current_stage_as(:integration)
29+
end
30+
end
31+
32+
context "in a non-prebuild job" do
33+
it "has only 1 stage: integration" do
34+
expect(PodPrebuild::Env.stages).to eq([:integration])
35+
end
36+
37+
it "initially lands on integration stage" do
38+
expect_current_stage_as(:integration)
39+
end
40+
end
41+
end
42+
end

0 commit comments

Comments
 (0)