Skip to content

Commit 102bdb3

Browse files
authored
Add enable_add_testonly flag to help opt out the new feature added in 0.1.5 (#95)
1 parent 85ca1d9 commit 102bdb3

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
0.1.7
2+
* Adding `testonly` to targets that link with XCTest becomes an opt-in with config `enable_add_testonly`
3+
14
0.1.6
25
* New xcframework_excluded_platforms option
36
* Add .ruby-version file, update github action code

lib/cocoapods/bazel.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def self.post_install(installer:)
4545
fa.spec,
4646
default_xcconfigs,
4747
config.experimental_deps_debug_and_release,
48-
config.xcframework_excluded_platforms
48+
config.xcframework_excluded_platforms,
49+
config.enable_add_testonly
4950
)
5051
end
5152

@@ -55,7 +56,8 @@ def self.post_install(installer:)
5556
nil,
5657
default_xcconfigs,
5758
config.experimental_deps_debug_and_release,
58-
config.xcframework_excluded_platforms
59+
config.xcframework_excluded_platforms,
60+
config.enable_add_testonly
5961
)
6062

6163
bazel_targets = [default_target] + targets_without_library_specification

lib/cocoapods/bazel/config.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class Config
5656
features: {
5757
experimental_deps_debug_and_release: false
5858
},
59-
xcframework_excluded_platforms: [].freeze
59+
xcframework_excluded_platforms: [].freeze,
60+
enable_add_testonly: false
6061
}.with_indifferent_access.freeze
6162

6263
private_constant :DEFAULTS
@@ -120,6 +121,10 @@ def build_file_doc
120121
def xcframework_excluded_platforms
121122
to_h[:xcframework_excluded_platforms]
122123
end
124+
125+
def enable_add_testonly
126+
to_h[:enable_add_testonly]
127+
end
123128
end
124129
end
125130
end

lib/cocoapods/bazel/target.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def add(name, value, defaults: nil)
3535
private :installer, :pod_target, :file_accessors, :non_library_spec, :label, :package, :default_xcconfigs, :resolved_xconfig_by_config, :relative_sandbox_root
3636
# rubocop:enable Style/AccessModifierDeclarations
3737

38-
def initialize(installer, pod_target, non_library_spec = nil, default_xcconfigs = {}, experimental_deps_debug_and_release = false, xcframework_excluded_platforms = [])
38+
def initialize(installer, pod_target, non_library_spec = nil, default_xcconfigs = {}, experimental_deps_debug_and_release = false,
39+
xcframework_excluded_platforms = [], enable_add_testonly = false)
3940
@installer = installer
4041
@pod_target = pod_target
4142
@file_accessors = non_library_spec ? pod_target.file_accessors.select { |fa| fa.spec == non_library_spec } : pod_target.file_accessors.select { |fa| fa.spec.library_specification? }
@@ -47,6 +48,7 @@ def initialize(installer, pod_target, non_library_spec = nil, default_xcconfigs
4748
@resolved_xconfig_by_config = {}
4849
@experimental_deps_debug_and_release = experimental_deps_debug_and_release
4950
@xcframework_excluded_platforms = xcframework_excluded_platforms
51+
@enable_add_testonly = enable_add_testonly
5052
@relative_sandbox_root = installer.sandbox.root.relative_path_from(installer.config.installation_root).to_s
5153
end
5254

@@ -378,10 +380,10 @@ def to_rule_kwargs
378380
kwargs[:runtime_deps] = []
379381
kwargs[:sdk_dylibs] = file_accessors.flat_map { |fa| fa.spec_consumer.libraries }.sort.uniq
380382
kwargs[:sdk_frameworks] = file_accessors.flat_map { |fa| fa.spec_consumer.frameworks }.sort.uniq
381-
kwargs[:testonly] = true if kwargs[:sdk_frameworks].include? 'XCTest'
383+
kwargs[:testonly] = true if (kwargs[:sdk_frameworks].include? 'XCTest') && @enable_add_testonly
382384
kwargs[:sdk_includes] = []
383385
kwargs[:weak_sdk_frameworks] = file_accessors.flat_map { |fa| fa.spec_consumer.weak_frameworks }.sort.uniq
384-
kwargs[:testonly] = true if kwargs[:weak_sdk_frameworks].include? 'XCTest'
386+
kwargs[:testonly] = true if (kwargs[:weak_sdk_frameworks].include? 'XCTest') && @enable_add_testonly
385387

386388
kwargs[:vendored_static_frameworks] = glob(attr: :vendored_static_frameworks, return_files: true)
387389
kwargs[:vendored_dynamic_frameworks] = glob(attr: :vendored_dynamic_frameworks, return_files: true)

lib/cocoapods/bazel/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module Pod
44
module Bazel
5-
VERSION = '0.1.6'
5+
VERSION = '0.1.7'
66
end
77
end

0 commit comments

Comments
 (0)