cocoapods-bazel 0.1.1 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +2 -2
- data/.gitignore +5 -0
- data/CHANGELOG.md +19 -1
- data/README.md +29 -7
- data/bin/pod_install_bazel_build +1 -1
- data/cocoapods-bazel.gemspec +0 -2
- data/lib/cocoapods/bazel/config.rb +62 -2
- data/lib/cocoapods/bazel/target.rb +106 -22
- data/lib/cocoapods/bazel/util.rb +12 -0
- data/lib/cocoapods/bazel/version.rb +1 -1
- data/lib/cocoapods/bazel/xcconfig_resolver.rb +4 -9
- data/lib/cocoapods/bazel.rb +45 -5
- metadata +3 -6
- data/Gemfile.lock +0 -145
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3286b561998f4b34e299da4b3d8214ff2fe4d81446c1fc7ec71752a2c992052d
|
4
|
+
data.tar.gz: 969cb842bba28405f2d0c9450eaccf6e7914925754ccb6e5b40e55ee890f28a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b004b7b58351034111a546e53f0884257511de7ba3506c7e711000ea860e0e16d95bfd85b5091fc369eed434c7d32e102e4216b65fdaca6c17bae54da226795
|
7
|
+
data.tar.gz: 90bc0315f257f0157c17c0f1da74edea822e8593a81f4ef786adef96c2059f78f5e2e91525a79a488029791d614838a83062f4eb083509e5e784108b44074eb0
|
data/.github/workflows/tests.yml
CHANGED
@@ -12,8 +12,8 @@ jobs:
|
|
12
12
|
runs-on: macos-latest
|
13
13
|
steps:
|
14
14
|
- uses: actions/checkout@v1
|
15
|
-
- name:
|
16
|
-
run: sudo xcode-select -
|
15
|
+
- name: Print Xcode version
|
16
|
+
run: sudo xcode-select -p
|
17
17
|
- uses: actions/setup-ruby@v1
|
18
18
|
with:
|
19
19
|
ruby-version: "2.x" # Version range or exact version of a Ruby version to use, using semvers version range syntax.
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
0.1.4
|
2
|
+
|
3
|
+
* Fix issues with glob evaluation (#64, #65)
|
4
|
+
* Get specs running on M1 hardware (#73)
|
5
|
+
* Expose CocoaPods environment variables PODS_ROOT and PODS_TARGET_SRCROOT (#67)
|
6
|
+
* Mark app specs with public visibility for usage as test apps (#77)
|
7
|
+
* README updates for buildifier option and link fixing (#69, #78)
|
8
|
+
* Remove non-existent globs to support using --incompatible_disallow_empty_glob (#80, #79)
|
9
|
+
|
10
|
+
0.1.3
|
11
|
+
|
12
|
+
* Add ability to insert a docstring at top of generated build files (#58)
|
13
|
+
* Remove expand_directories for resource_bundle (#48)
|
14
|
+
|
15
|
+
0.1.2
|
16
|
+
|
17
|
+
* Generate empty BUILD.bazel file at sandbox root (Pods/) during build file generation stage
|
18
|
+
|
1
19
|
0.1.1
|
2
20
|
|
3
|
-
* Raise error and offer suggestion if pod path is outside of current workspace
|
21
|
+
* Raise error and offer suggestion if pod path is outside of current workspace
|
data/README.md
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|

|
3
3
|
|
4
4
|
|
5
|
-
Cocoapods::Bazel is a Cocoapods plugin that makes it easy to use [Bazel](https://bazel.build) instead of Xcode to build your iOS project. It automatically generates Bazel's `BUILD
|
5
|
+
Cocoapods::Bazel is a Cocoapods plugin that makes it easy to use [Bazel](https://bazel.build) instead of Xcode to build your iOS project. It automatically generates Bazel's `BUILD` files.
|
6
|
+
|
7
|
+
`cocoapods-bazel` can be setup to translate CocoaPod targets to provided Bazel rules. For example, you can use `cocaopods-bazel` to load framework targets using [rules_ios](https://github.com/bazel-ios/rules_ios). It's also flexible enough to allow users to use their own custom rules if needed.
|
6
8
|
|
7
9
|
> :warning: **This is alpha software.** We are developing this plugin in the open so you should only use it if you know what you are doing and are willing to help develop it.
|
8
10
|
|
@@ -16,19 +18,23 @@ gem 'cocoapods-bazel'
|
|
16
18
|
|
17
19
|
And then execute:
|
18
20
|
|
19
|
-
|
21
|
+
```sh
|
22
|
+
bundle install
|
23
|
+
```
|
20
24
|
|
21
25
|
Or install it yourself as:
|
22
26
|
|
23
|
-
|
27
|
+
```sh
|
28
|
+
gem install cocoapods-bazel
|
29
|
+
```
|
24
30
|
|
25
31
|
## Usage
|
26
32
|
|
27
|
-
This plugin will run extra steps after post_install to generate BUILD
|
33
|
+
This plugin will run extra steps after post_install to generate `BUILD` files for Bazel.
|
28
34
|
|
29
|
-
To enable the plugin,
|
35
|
+
To enable the plugin, you can add something like the following section to your `Podfile`:
|
30
36
|
|
31
|
-
```
|
37
|
+
```ruby
|
32
38
|
plugin 'cocoapods-bazel', {
|
33
39
|
rules: {
|
34
40
|
'apple_framework' => { load: '@build_bazel_rules_ios//rules:framework.bzl', rule: 'apple_framework' }.freeze,
|
@@ -44,9 +50,25 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
44
50
|
|
45
51
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
46
52
|
|
53
|
+
## Experimental Features
|
54
|
+
|
55
|
+
There are some experimental features that are opt-in and can be enabled adding the plugin to the `Podfile`. Some of these features intentionally break the contract with the `.podspecs` specification in order to create `BUILD` files that are easier to maintain and/or evolve using Bazel features that don't have a direct relationship with what cocoapods does. You'll find the keys to enable such features and a brief explanation/motivation for each in `Bazel::Config::EXPERIMENTAL_FEATURES` (`lib/cocoapods/bazel/config.rb`).
|
56
|
+
|
57
|
+
Note that tests for the experimental features are located under `spec/integration/experimental_features` and these should mostly replicate the tests under `spec/integration/monorepo` but with the features on. Also it's a place to create tests specific to a experimental feature that not necessarily will affect the default usage of `cocoapods-bazel`.
|
58
|
+
|
59
|
+
## BUILD file formatting
|
60
|
+
|
61
|
+
When the `BUILD.bazel` files are generated you may choose to have `cocoapods-bazel` format the files using [buildifier](https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md). This formatting is enabled by default if a `buildifier` executable is found using `which buildifier`.
|
62
|
+
|
63
|
+
You can disable buildifier formatting with `buildifier: false` in the options of the `cocoapods-bazel` plugin.
|
64
|
+
|
65
|
+
Additionally, if you'd like to use a custom `buildifier` executable you can provide the `cocoapods-bazel` plugin options with an array of arguments to execute to format files.
|
66
|
+
|
67
|
+
For example, if you have `buildifier` runnable target you've defined in Bazel with the name `buildifier` you can run this specific version with: `buildifier: ['bazel', 'run', 'buildifier', '--']`. (Note the `--` allows bazel to forward arguments to the buildifier target).
|
68
|
+
|
47
69
|
## Contributing
|
48
70
|
|
49
|
-
Bug reports and pull requests are welcome on GitHub
|
71
|
+
Bug reports and pull requests are welcome on GitHub [here](https://github.com/bazel-ios/cocoapods-bazel).
|
50
72
|
|
51
73
|
## License
|
52
74
|
|
data/bin/pod_install_bazel_build
CHANGED
@@ -23,4 +23,4 @@ ARGV.replace %w[install]
|
|
23
23
|
|
24
24
|
load Gem.bin_path('cocoapods', 'pod')
|
25
25
|
|
26
|
-
exec 'bazelisk', '--ignore_all_rc_files', 'build', '--verbose_failures', '...'
|
26
|
+
exec 'bazelisk', '--ignore_all_rc_files', 'build', '--verbose_failures', '--cpu=ios_x86_64', '--experimental_worker_allow_json_protocol', '...'
|
data/cocoapods-bazel.gemspec
CHANGED
@@ -12,8 +12,6 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.homepage = 'https://github.com/ob/cocoapods-bazel'
|
13
13
|
spec.license = 'apache2'
|
14
14
|
|
15
|
-
spec.metadata['allowed_push_host'] = "https://rubygems.org/"
|
16
|
-
|
17
15
|
spec.metadata['homepage_uri'] = spec.homepage
|
18
16
|
spec.metadata['source_code_uri'] = spec.homepage
|
19
17
|
spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
|
@@ -4,6 +4,44 @@ module Pod
|
|
4
4
|
module Bazel
|
5
5
|
class Config
|
6
6
|
PLUGIN_KEY = 'cocoapods-bazel'
|
7
|
+
EXPERIMENTAL_FEATURES = [
|
8
|
+
# When enabled cocoapods-bazel will add one additional config_setting for the 'deps' attribute only
|
9
|
+
# containing both 'debug' and 'release' dependencies.
|
10
|
+
#
|
11
|
+
# In other works when this flag is active cocoapods-bazel will continue to create these:
|
12
|
+
#
|
13
|
+
# - //Pods/cocoapods-bazel:debug
|
14
|
+
# - //Pods/cocoapods-bazel:release
|
15
|
+
#
|
16
|
+
# and generate the same 'select()' statements for all attributes but 'deps'.
|
17
|
+
#
|
18
|
+
# Additionaly these new config_setting values will be created:
|
19
|
+
#
|
20
|
+
# - //Pods/cocoapods-bazel:deps_debug
|
21
|
+
# - //Pods/cocoapods-bazel:deps_release
|
22
|
+
# - //Pods/cocoapods-bazel:deps_debug_and_release
|
23
|
+
#
|
24
|
+
# and used only in the 'deps' attribute.
|
25
|
+
#
|
26
|
+
# This effectively decouple 'deps' from the other attributes from a configuration perspective and allow one to build
|
27
|
+
# with different combinations of these settings. One example of a use case is generating release builds with 'debug' dependencies
|
28
|
+
# available so debug-only features can be used to inspect/validate behaviour in a release build (some call these "dogfood" builds).
|
29
|
+
#
|
30
|
+
# From a conceptual perspective this will generate BUILD files with "all" states and allow one to use bazel features to 'select()' the desired ones.
|
31
|
+
# This intentionally breaks the contract with the .podspec specification since cocoapods does not have the concept of 'select()'-ing configurations.
|
32
|
+
#
|
33
|
+
# Still in the context of the use case above ('dogfood' builds), without this experimental feature one would have to
|
34
|
+
# change the configurations in the .podspec file from:
|
35
|
+
# `s.dependency 'Foo', configurations: %w[Debug]`
|
36
|
+
# to:
|
37
|
+
# `s.dependency 'Foo', configurations: %w[Debug Release]`
|
38
|
+
# and re-run cocoapods-bazel to generate the desired type of build and then re-run it again to go back to the previous state.
|
39
|
+
#
|
40
|
+
# This might be ok for some teams but it prevents others that are interested in using cocoapods-bazel to migrate to Bazel and eventually stop
|
41
|
+
# depending on cocoapods. If the generated BUILD files don't contain "all" states and a 'pod install' is always required it's not trivial how to eventually treat the
|
42
|
+
# BUILD files as source of truth.
|
43
|
+
:experimental_deps_debug_and_release
|
44
|
+
].freeze
|
7
45
|
private_constant :PLUGIN_KEY
|
8
46
|
DEFAULTS = {
|
9
47
|
rules: {
|
@@ -13,8 +51,13 @@ module Pod
|
|
13
51
|
}.freeze,
|
14
52
|
overrides: {}.freeze,
|
15
53
|
buildifier: true,
|
16
|
-
default_xcconfigs: {}.freeze
|
54
|
+
default_xcconfigs: {}.freeze,
|
55
|
+
build_file_doc: '',
|
56
|
+
features: {
|
57
|
+
experimental_deps_debug_and_release: false
|
58
|
+
}
|
17
59
|
}.with_indifferent_access.freeze
|
60
|
+
|
18
61
|
private_constant :DEFAULTS
|
19
62
|
|
20
63
|
attr_reader :to_h
|
@@ -30,7 +73,7 @@ module Pod
|
|
30
73
|
end
|
31
74
|
|
32
75
|
def self.from_podfile_options(options)
|
33
|
-
new(DEFAULTS.merge(options) do |_key, old_val, new_val|
|
76
|
+
config = new(DEFAULTS.merge(options) do |_key, old_val, new_val|
|
34
77
|
case old_val
|
35
78
|
when Hash
|
36
79
|
old_val.merge(new_val) # intentionally only 1 level deep of merging
|
@@ -38,6 +81,15 @@ module Pod
|
|
38
81
|
new_val
|
39
82
|
end
|
40
83
|
end)
|
84
|
+
|
85
|
+
# Validating if only supported/valid experimental features
|
86
|
+
# exist in the Podfile (only applies if :features is not empty)
|
87
|
+
features = config.to_h[:features] || {}
|
88
|
+
features.keys.map(&:to_sym).each do |key|
|
89
|
+
raise "Unrecognized experimental feature '#{key}' in Podfile. Available options are: #{EXPERIMENTAL_FEATURES}" unless EXPERIMENTAL_FEATURES.include?(key)
|
90
|
+
end
|
91
|
+
|
92
|
+
config
|
41
93
|
end
|
42
94
|
|
43
95
|
def initialize(to_h)
|
@@ -55,6 +107,14 @@ module Pod
|
|
55
107
|
def default_xcconfigs
|
56
108
|
to_h[:default_xcconfigs]
|
57
109
|
end
|
110
|
+
|
111
|
+
def experimental_deps_debug_and_release
|
112
|
+
to_h[:features][:experimental_deps_debug_and_release]
|
113
|
+
end
|
114
|
+
|
115
|
+
def build_file_doc
|
116
|
+
to_h[:build_file_doc]
|
117
|
+
end
|
58
118
|
end
|
59
119
|
end
|
60
120
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'set'
|
4
|
+
|
3
5
|
require_relative 'xcconfig_resolver'
|
4
6
|
|
5
7
|
module Pod
|
@@ -27,10 +29,10 @@ module Pod
|
|
27
29
|
|
28
30
|
include XCConfigResolver
|
29
31
|
|
30
|
-
attr_reader :installer, :pod_target, :file_accessors, :non_library_spec, :label, :package, :default_xcconfigs, :resolved_xconfig_by_config
|
31
|
-
private :installer, :pod_target, :file_accessors, :non_library_spec, :label, :package, :default_xcconfigs, :resolved_xconfig_by_config
|
32
|
+
attr_reader :installer, :pod_target, :file_accessors, :non_library_spec, :label, :package, :default_xcconfigs, :resolved_xconfig_by_config, :relative_sandbox_root
|
33
|
+
private :installer, :pod_target, :file_accessors, :non_library_spec, :label, :package, :default_xcconfigs, :resolved_xconfig_by_config, :relative_sandbox_root
|
32
34
|
|
33
|
-
def initialize(installer, pod_target, non_library_spec = nil, default_xcconfigs = {})
|
35
|
+
def initialize(installer, pod_target, non_library_spec = nil, default_xcconfigs = {}, experimental_deps_debug_and_release = false)
|
34
36
|
@installer = installer
|
35
37
|
@pod_target = pod_target
|
36
38
|
@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? }
|
@@ -40,6 +42,8 @@ module Pod
|
|
40
42
|
@package = installer.sandbox.pod_dir(pod_target.pod_name).relative_path_from(installer.config.installation_root).to_s
|
41
43
|
@default_xcconfigs = default_xcconfigs
|
42
44
|
@resolved_xconfig_by_config = {}
|
45
|
+
@experimental_deps_debug_and_release = experimental_deps_debug_and_release
|
46
|
+
@relative_sandbox_root = installer.sandbox.root.relative_path_from(installer.config.installation_root).to_s
|
43
47
|
end
|
44
48
|
|
45
49
|
def bazel_label(relative_to: nil)
|
@@ -54,7 +58,6 @@ module Pod
|
|
54
58
|
end
|
55
59
|
|
56
60
|
def build_settings_label(config)
|
57
|
-
relative_sandbox_root = @installer.sandbox.root.relative_path_from(@installer.config.installation_root).to_s
|
58
61
|
cocoapods_bazel_path = File.join(relative_sandbox_root, 'cocoapods-bazel')
|
59
62
|
|
60
63
|
"//#{cocoapods_bazel_path}:#{config}"
|
@@ -66,7 +69,7 @@ module Pod
|
|
66
69
|
end
|
67
70
|
|
68
71
|
app_spec, app_target = *app_host_info
|
69
|
-
Target.new(installer, app_target, app_spec)
|
72
|
+
Target.new(installer, app_target, app_spec, {}, @experimental_deps_debug_and_release)
|
70
73
|
end
|
71
74
|
|
72
75
|
def type
|
@@ -473,8 +476,14 @@ module Pod
|
|
473
476
|
labels_by_config = {}
|
474
477
|
|
475
478
|
if !sorted_debug_labels.empty? || !sorted_release_labels.empty?
|
476
|
-
|
477
|
-
|
479
|
+
if @experimental_deps_debug_and_release
|
480
|
+
labels_by_config[build_settings_label(:deps_debug)] = sorted_debug_labels
|
481
|
+
labels_by_config[build_settings_label(:deps_release)] = sorted_release_labels
|
482
|
+
labels_by_config[build_settings_label(:deps_debug_and_release)] = sorted_debug_labels + sorted_release_labels
|
483
|
+
else
|
484
|
+
labels_by_config[build_settings_label(:debug)] = sorted_debug_labels
|
485
|
+
labels_by_config[build_settings_label(:release)] = sorted_release_labels
|
486
|
+
end
|
478
487
|
end
|
479
488
|
|
480
489
|
if labels_by_config.empty? # no per-config dependency
|
@@ -514,55 +523,125 @@ module Pod
|
|
514
523
|
def expand_glob(glob, extensions: nil, expand_directories: false)
|
515
524
|
if (m = glob.match(/\{([^\{\}]+)\}/))
|
516
525
|
m[1].split(',').flat_map do |alt|
|
517
|
-
expand_glob("#{m.pre_match}#{alt}#{m.post_match}")
|
526
|
+
expand_glob("#{m.pre_match}#{alt.strip}#{m.post_match}", extensions: extensions, expand_directories: expand_directories)
|
518
527
|
end.uniq
|
519
528
|
elsif (m = glob.match(/\[([^\[\]]+)\]/))
|
520
529
|
m[1].each_char.flat_map do |alt|
|
521
|
-
expand_glob("#{m.pre_match}#{alt}#{m.post_match}")
|
530
|
+
expand_glob("#{m.pre_match}#{alt.strip}#{m.post_match}", extensions: extensions, expand_directories: expand_directories)
|
522
531
|
end.uniq
|
523
532
|
elsif extensions && File.extname(glob).empty?
|
524
533
|
glob = glob.chomp('**/*') # If we reach here and the glob ends with **/*, we need to avoid duplicating it (we do not want to end up with **/*/**/*)
|
525
534
|
if File.basename(glob) == '*'
|
526
|
-
extensions.map
|
535
|
+
extensions.map do |ext|
|
536
|
+
combined = "#{glob}.#{ext}"
|
537
|
+
combined if Dir.glob(File.join(@package_dir, combined)).any?
|
538
|
+
end.compact
|
527
539
|
else
|
528
540
|
extensions.map do |ext|
|
529
|
-
File.join(glob, '**', "*.#{ext}")
|
530
|
-
|
541
|
+
combined = File.join(glob, '**', "*.#{ext}")
|
542
|
+
combined if Dir.glob(File.join(@package_dir, combined)).any?
|
543
|
+
end.compact
|
531
544
|
end
|
532
545
|
elsif expand_directories
|
533
546
|
if glob.end_with?('/**/*')
|
534
|
-
|
547
|
+
glob_with_valid_matches(glob)
|
535
548
|
elsif glob.end_with?('/*')
|
536
549
|
[glob.sub(%r{/\*$}, '/**/*')]
|
550
|
+
elsif should_skip_directory_expansion(glob)
|
551
|
+
glob_with_valid_matches(glob)
|
537
552
|
else
|
538
|
-
[glob
|
553
|
+
[glob.chomp('/') + '/**/*']
|
539
554
|
end
|
540
555
|
else
|
541
|
-
|
556
|
+
glob_with_valid_matches(glob)
|
542
557
|
end
|
543
558
|
end
|
544
559
|
|
560
|
+
# Returns `[glob]` if the given pattern has at least 1 match on disk, otherwise returns an empty array
|
561
|
+
def glob_with_valid_matches(glob)
|
562
|
+
Dir.glob(File.join(@package_dir, glob)).any? ? [glob] : []
|
563
|
+
end
|
564
|
+
|
565
|
+
# We should expand only folder globs, not expand file globs.
|
566
|
+
# E.g., xib files glob "*.xib" should not be expanded to "*.xib/**/*", otherise nothing will be matched
|
567
|
+
def should_skip_directory_expansion(glob)
|
568
|
+
extension = File.extname(glob)
|
569
|
+
expansion_extentions = Set['.xcassets', '.xcdatamodeld', '.lproj']
|
570
|
+
!expansion_extentions.include?(extension)
|
571
|
+
end
|
572
|
+
|
573
|
+
def rules_ios_platform_name(platform)
|
574
|
+
name = platform.string_name.downcase
|
575
|
+
return 'macos' if name == 'osx'
|
576
|
+
|
577
|
+
name
|
578
|
+
end
|
579
|
+
|
545
580
|
def framework_kwargs
|
581
|
+
library_spec = pod_target.file_accessors.find { |fa| fa.spec.library_specification? }.spec
|
546
582
|
{
|
547
583
|
visibility: ['//visibility:public'],
|
548
|
-
|
584
|
+
bundle_id: resolved_value_by_build_setting('PRODUCT_BUNDLE_IDENTIFIER'),
|
585
|
+
infoplists_by_build_setting: pod_target_infoplists_by_build_setting,
|
586
|
+
infoplists: common_pod_target_infoplists(additional_plist: nil_if_empty(library_spec.consumer(pod_target.platform).info_plist)),
|
587
|
+
platforms: { rules_ios_platform_name(pod_target.platform) => build_os_version || pod_target.platform.deployment_target.to_s }
|
549
588
|
}
|
550
589
|
end
|
551
590
|
|
552
591
|
def test_kwargs
|
553
592
|
{
|
554
593
|
bundle_id: resolved_value_by_build_setting('PRODUCT_BUNDLE_IDENTIFIER'),
|
555
|
-
env: pod_target.scheme_for_spec(non_library_spec).fetch(:environment_variables, {}),
|
594
|
+
env: resolve_env(pod_target.scheme_for_spec(non_library_spec).fetch(:environment_variables, {})),
|
556
595
|
infoplists_by_build_setting: pod_target_infoplists_by_build_setting,
|
557
596
|
infoplists: common_pod_target_infoplists(additional_plist: nil_if_empty(non_library_spec.consumer(pod_target.platform).info_plist)),
|
558
|
-
minimum_os_version: pod_target.deployment_target_for_non_library_spec(non_library_spec),
|
597
|
+
minimum_os_version: build_os_version || pod_target.deployment_target_for_non_library_spec(non_library_spec),
|
559
598
|
test_host: test_host&.bazel_label(relative_to: package) || file_accessors.any? { |fa| fa.spec_consumer.requires_app_host? } || nil
|
560
599
|
}
|
561
600
|
end
|
562
601
|
|
602
|
+
# Resolves the given environment by resolving CocoaPod specific environment variables.
|
603
|
+
# Given an environment with unresolved env values, this function resolves them and returns the new env.
|
604
|
+
def resolve_env(env)
|
605
|
+
# These environment variables are resolved by CocoaPods, they tend to be used in tests and other
|
606
|
+
# scripts, as such we must resolve them before translating the targets environment.
|
607
|
+
resolved_cocoapods_env = {
|
608
|
+
'PODS_ROOT' => "//#{relative_sandbox_root}",
|
609
|
+
'PODS_TARGET_SRCROOT' => ':'
|
610
|
+
}.freeze
|
611
|
+
|
612
|
+
# Removes the : bazel prefix for current directory.
|
613
|
+
sub_prefix = ->(s) { s.sub(%r{\A:/}, '') }
|
614
|
+
|
615
|
+
env.each_with_object({}) do |(k, v), resolved_env|
|
616
|
+
resolved_val = Pod::Bazel::Util.resolve_value(v, resolved_values: resolved_cocoapods_env)
|
617
|
+
resolved_env[k] = sub_prefix[resolved_val]
|
618
|
+
end
|
619
|
+
end
|
620
|
+
|
621
|
+
def build_os_version
|
622
|
+
# If there's a SWIFT_DEPLOYMENT_TARGET version set, use that for the
|
623
|
+
# minimum version. It's not currently supported or desirable in rules_ios to have
|
624
|
+
# these distinct, however xcconfig supports that.
|
625
|
+
swift_deployment_target = resolved_value_by_build_setting('SWIFT_DEPLOYMENT_TARGET')
|
626
|
+
|
627
|
+
llvm_target_triple_os_version = resolved_value_by_build_setting('LLVM_TARGET_TRIPLE_OS_VERSION')
|
628
|
+
if llvm_target_triple_os_version
|
629
|
+
# For clang this is set ios9.0: take everything after the os name
|
630
|
+
version_number = llvm_target_triple_os_version.match(/\d.*/)
|
631
|
+
clang_build_os_version = version_number.to_s if version_number
|
632
|
+
end
|
633
|
+
if !swift_deployment_target.nil? && !clang_build_os_version.nil?
|
634
|
+
raise "warning: had different os versions #{swift_deployment_target} #{clang_build_os_version}" if swift_deployment_target != clang_build_os_version
|
635
|
+
end
|
636
|
+
swift_deployment_target || clang_build_os_version
|
637
|
+
end
|
638
|
+
|
563
639
|
def app_kwargs
|
564
640
|
# maps to kwargs listed for https://github.com/bazelbuild/rules_apple/blob/master/doc/rules-ios.md#ios_application
|
565
|
-
|
641
|
+
|
642
|
+
platform_target = pod_target.deployment_target_for_non_library_spec(non_library_spec)
|
643
|
+
|
644
|
+
kwargs = {
|
566
645
|
app_icons: [],
|
567
646
|
bundle_id: resolved_value_by_build_setting('PRODUCT_BUNDLE_IDENTIFIER') || "org.cocoapods.#{label}",
|
568
647
|
bundle_name: nil,
|
@@ -576,14 +655,19 @@ module Pod
|
|
576
655
|
ipa_post_processor: nil,
|
577
656
|
launch_images: [],
|
578
657
|
launch_storyboard: nil,
|
579
|
-
minimum_os_version:
|
658
|
+
minimum_os_version: build_os_version || platform_target,
|
580
659
|
provisioning_profile: nil,
|
581
660
|
resources: [],
|
582
661
|
settings_bundle: [],
|
583
662
|
strings: [],
|
584
663
|
version: [],
|
585
|
-
watch_application: []
|
664
|
+
watch_application: [],
|
665
|
+
visibility: ['//visibility:public']
|
586
666
|
}
|
667
|
+
|
668
|
+
# If the user has set a different build os set that here
|
669
|
+
kwargs[:minimum_deployment_os_version] = platform_target if build_os_version
|
670
|
+
kwargs
|
587
671
|
end
|
588
672
|
|
589
673
|
def app_targeted_device_families
|
@@ -607,7 +691,7 @@ module Pod
|
|
607
691
|
'slices' => xcframework.slices.map do |slice|
|
608
692
|
{
|
609
693
|
'identifier' => slice.identifier,
|
610
|
-
'platform' => slice.platform
|
694
|
+
'platform' => rules_ios_platform_name(slice.platform),
|
611
695
|
'platform_variant' => slice.platform_variant.to_s,
|
612
696
|
'supported_archs' => slice.supported_archs,
|
613
697
|
'path' => slice.path.relative_path_from(@package_dir).to_s,
|
data/lib/cocoapods/bazel/util.rb
CHANGED
@@ -10,6 +10,18 @@ module Pod
|
|
10
10
|
sort_keys.sort_by { |k| [k.phase, k.split, k.value, k.original_index] }.map(&:value)
|
11
11
|
end
|
12
12
|
|
13
|
+
# Recursively resolves the variables in string with the given resolved values.
|
14
|
+
#
|
15
|
+
# Example: Given string = "${PODS_ROOT}/Foo", resolved_values = {"PODS_ROOT": "//Pods"}
|
16
|
+
# this function returns "//Pods/Foo".
|
17
|
+
def resolve_value(string, resolved_values:)
|
18
|
+
return string unless string =~ /\$(?:\{([_a-zA-Z0-0]+?)\}|\(([_a-zA-Z0-0]+?)\))/
|
19
|
+
|
20
|
+
match, key = Regexp.last_match.values_at(0, 1, 2).compact
|
21
|
+
sub = resolved_values.fetch(key, '')
|
22
|
+
resolve_value(string.gsub(match, sub), resolved_values: resolved_values)
|
23
|
+
end
|
24
|
+
|
13
25
|
class SortKey
|
14
26
|
attr_reader :phase, :split, :value, :original_index
|
15
27
|
|
@@ -8,8 +8,10 @@ module Pod
|
|
8
8
|
def resolved_build_setting_value(setting, settings:)
|
9
9
|
return unless (value = settings[setting])
|
10
10
|
|
11
|
+
# Removes the : bazel prefix for current directory.
|
11
12
|
sub_prefix = ->(s) { s.sub(%r{\A:/}, '') }
|
12
|
-
|
13
|
+
|
14
|
+
resolved = Pod::Bazel::Util.resolve_value(value, resolved_values: settings)
|
13
15
|
if Pod::Target::BuildSettings::PLURAL_SETTINGS.include?(setting)
|
14
16
|
resolved.shellsplit.reject(&:empty?).map(&sub_prefix)
|
15
17
|
else
|
@@ -17,20 +19,13 @@ module Pod
|
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
def resolve_string_with_build_settings(string, settings:)
|
21
|
-
return string unless string =~ /\$(?:\{([_a-zA-Z0-0]+?)\}|\(([_a-zA-Z0-0]+?)\))/
|
22
|
-
|
23
|
-
match, key = Regexp.last_match.values_at(0, 1, 2).compact
|
24
|
-
sub = settings.fetch(key, '')
|
25
|
-
resolve_string_with_build_settings(string.gsub(match, sub), settings: settings)
|
26
|
-
end
|
27
|
-
|
28
22
|
UNRESOLVED_SETTINGS = [
|
29
23
|
'CONFIGURATION', # not needed, only used to help resolve other settings that may use it in substitutions
|
30
24
|
'HEADER_SEARCH_PATHS', # serialized into copts, handled natively by Xcode instead of via xcspecs
|
31
25
|
'OTHER_CFLAGS', # serialized separately as objc_copts
|
32
26
|
'OTHER_SWIFT_FLAGS', # serialized separately as swift_copts
|
33
27
|
'OTHER_LDFLAGS', # serialized separately as linkopts
|
28
|
+
'PODS_ROOT', # not needed, used to help resolve the Pods root path relative to the current package
|
34
29
|
'PODS_TARGET_SRCROOT', # not needed, used to help resolve file references relative to the current package
|
35
30
|
'SDKROOT', # not needed since the SDKROOT gets propagated via the apple configuration transition
|
36
31
|
'SRCROOT', # not needed, used to help resolve file references relative to the current workspace
|
data/lib/cocoapods/bazel.rb
CHANGED
@@ -19,6 +19,10 @@ module Pod
|
|
19
19
|
UI.titled_section 'Generating Bazel files' do
|
20
20
|
workspace = installer.config.installation_root
|
21
21
|
sandbox = installer.sandbox
|
22
|
+
|
23
|
+
# Ensure we declare the sandbox (Pods/) as a package so each Pod (as a package) belongs to sandbox root package instead
|
24
|
+
FileUtils.touch(File.join(installer.config.sandbox_root, 'BUILD.bazel'))
|
25
|
+
|
22
26
|
build_files = Hash.new { |h, k| h[k] = StarlarkCompiler::BuildFile.new(workspace: workspace, package: k) }
|
23
27
|
installer.pod_targets.each do |pod_target|
|
24
28
|
package = sandbox.pod_dir(pod_target.pod_name).relative_path_from(workspace).to_s
|
@@ -34,8 +38,25 @@ module Pod
|
|
34
38
|
|
35
39
|
build_file = build_files[package]
|
36
40
|
|
37
|
-
|
38
|
-
|
41
|
+
targets_without_library_specification = pod_target.file_accessors.reject { |fa| fa.spec.library_specification? }.map do |fa|
|
42
|
+
Target.new(
|
43
|
+
installer,
|
44
|
+
pod_target,
|
45
|
+
fa.spec,
|
46
|
+
default_xcconfigs,
|
47
|
+
config.experimental_deps_debug_and_release
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
default_target = Target.new(
|
52
|
+
installer,
|
53
|
+
pod_target,
|
54
|
+
nil,
|
55
|
+
default_xcconfigs,
|
56
|
+
config.experimental_deps_debug_and_release
|
57
|
+
)
|
58
|
+
|
59
|
+
bazel_targets = [default_target] + targets_without_library_specification
|
39
60
|
|
40
61
|
bazel_targets.each do |t|
|
41
62
|
load = config.load_for(macro: t.type)
|
@@ -46,6 +67,13 @@ module Pod
|
|
46
67
|
|
47
68
|
build_files.each_value(&:save!)
|
48
69
|
format_files(build_files: build_files, buildifier: config.buildifier, workspace: workspace)
|
70
|
+
unless config.build_file_doc.empty?
|
71
|
+
build_files.each_key.each do |key|
|
72
|
+
path = File.join(workspace, key, 'BUILD.bazel')
|
73
|
+
content = File.read(path)
|
74
|
+
File.write(path, "\"\"\"\n#{config.build_file_doc}\n\"\"\"\n\n" + content)
|
75
|
+
end
|
76
|
+
end
|
49
77
|
|
50
78
|
cocoapods_bazel_path = File.join(sandbox.root, 'cocoapods-bazel')
|
51
79
|
FileUtils.mkdir_p cocoapods_bazel_path
|
@@ -60,11 +88,23 @@ module Pod
|
|
60
88
|
|
61
89
|
cocoapods_bazel_pkg = Pathname.new(path).relative_path_from Pathname.new(workspace)
|
62
90
|
configs_build_file = StarlarkCompiler::BuildFile.new(workspace: workspace, package: cocoapods_bazel_pkg)
|
63
|
-
|
64
91
|
configs_build_file.add_load(of: 'string_flag', from: '@bazel_skylib//rules:common_settings.bzl')
|
65
92
|
configs_build_file.add_target StarlarkCompiler::AST::FunctionCall.new('string_flag', name: 'config', build_setting_default: 'debug', visibility: ['//visibility:public'])
|
66
|
-
configs_build_file.add_target StarlarkCompiler::AST::FunctionCall.new('config_setting', name: 'debug', flag_values: { ':config' => 'debug' })
|
67
|
-
configs_build_file.add_target StarlarkCompiler::AST::FunctionCall.new('config_setting', name: 'release', flag_values: { ':config' => 'release' })
|
93
|
+
configs_build_file.add_target StarlarkCompiler::AST::FunctionCall.new('config_setting', name: 'debug', flag_values: { ':config' => 'debug' }, visibility: ['//visibility:public'])
|
94
|
+
configs_build_file.add_target StarlarkCompiler::AST::FunctionCall.new('config_setting', name: 'release', flag_values: { ':config' => 'release' }, visibility: ['//visibility:public'])
|
95
|
+
|
96
|
+
if config.experimental_deps_debug_and_release
|
97
|
+
configs_build_file.add_target StarlarkCompiler::AST::FunctionCall.new('string_flag', name: 'deps_config', build_setting_default: 'deps_debug', visibility: ['//visibility:public'])
|
98
|
+
configs_build_file.add_target StarlarkCompiler::AST::FunctionCall.new(
|
99
|
+
'config_setting', name: 'deps_debug', flag_values: { ':deps_config' => 'deps_debug' }, visibility: ['//visibility:public']
|
100
|
+
)
|
101
|
+
configs_build_file.add_target StarlarkCompiler::AST::FunctionCall.new(
|
102
|
+
'config_setting', name: 'deps_release', flag_values: { ':deps_config' => 'deps_release' }, visibility: ['//visibility:public']
|
103
|
+
)
|
104
|
+
configs_build_file.add_target StarlarkCompiler::AST::FunctionCall.new(
|
105
|
+
'config_setting', name: 'deps_debug_and_release', flag_values: { ':deps_config' => 'deps_debug_and_release' }, visibility: ['//visibility:public']
|
106
|
+
)
|
107
|
+
end
|
68
108
|
|
69
109
|
configs_build_file.save!
|
70
110
|
format_files(build_files: { cocoapods_bazel_pkg => configs_build_file }, buildifier: config.buildifier, workspace: workspace)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocoapods-bazel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shawn Chen
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-11-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -55,7 +55,6 @@ files:
|
|
55
55
|
- ".rubocop_todo.yml"
|
56
56
|
- CHANGELOG.md
|
57
57
|
- Gemfile
|
58
|
-
- Gemfile.lock
|
59
58
|
- LICENSE.txt
|
60
59
|
- README.md
|
61
60
|
- Rakefile
|
@@ -76,7 +75,6 @@ homepage: https://github.com/ob/cocoapods-bazel
|
|
76
75
|
licenses:
|
77
76
|
- apache2
|
78
77
|
metadata:
|
79
|
-
allowed_push_host: https://rubygems.org/
|
80
78
|
homepage_uri: https://github.com/ob/cocoapods-bazel
|
81
79
|
source_code_uri: https://github.com/ob/cocoapods-bazel
|
82
80
|
changelog_uri: https://github.com/ob/cocoapods-bazel/blob/master/CHANGELOG.md
|
@@ -95,8 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
93
|
- !ruby/object:Gem::Version
|
96
94
|
version: '0'
|
97
95
|
requirements: []
|
98
|
-
|
99
|
-
rubygems_version: 2.7.7
|
96
|
+
rubygems_version: 3.1.6
|
100
97
|
signing_key:
|
101
98
|
specification_version: 4
|
102
99
|
summary: A plugin for CocoaPods that generates Bazel build files for pods
|
data/Gemfile.lock
DELETED
@@ -1,145 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
cocoapods-bazel (0.1.1)
|
5
|
-
starlark_compiler (~> 0.3)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
CFPropertyList (3.0.3)
|
11
|
-
activesupport (5.2.4.4)
|
12
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
-
i18n (>= 0.7, < 2)
|
14
|
-
minitest (~> 5.1)
|
15
|
-
tzinfo (~> 1.1)
|
16
|
-
addressable (2.7.0)
|
17
|
-
public_suffix (>= 2.0.2, < 5.0)
|
18
|
-
algoliasearch (1.27.5)
|
19
|
-
httpclient (~> 2.8, >= 2.8.3)
|
20
|
-
json (>= 1.5.1)
|
21
|
-
ast (2.4.0)
|
22
|
-
atomos (0.1.3)
|
23
|
-
bacon (1.2.0)
|
24
|
-
claide (1.0.3)
|
25
|
-
clintegracon (0.9.0)
|
26
|
-
colored2 (~> 3.1)
|
27
|
-
diffy
|
28
|
-
cocoapods (1.10.1)
|
29
|
-
addressable (~> 2.6)
|
30
|
-
claide (>= 1.0.2, < 2.0)
|
31
|
-
cocoapods-core (= 1.10.1)
|
32
|
-
cocoapods-deintegrate (>= 1.0.3, < 2.0)
|
33
|
-
cocoapods-downloader (>= 1.4.0, < 2.0)
|
34
|
-
cocoapods-plugins (>= 1.0.0, < 2.0)
|
35
|
-
cocoapods-search (>= 1.0.0, < 2.0)
|
36
|
-
cocoapods-trunk (>= 1.4.0, < 2.0)
|
37
|
-
cocoapods-try (>= 1.1.0, < 2.0)
|
38
|
-
colored2 (~> 3.1)
|
39
|
-
escape (~> 0.0.4)
|
40
|
-
fourflusher (>= 2.3.0, < 3.0)
|
41
|
-
gh_inspector (~> 1.0)
|
42
|
-
molinillo (~> 0.6.6)
|
43
|
-
nap (~> 1.0)
|
44
|
-
ruby-macho (~> 1.4)
|
45
|
-
xcodeproj (>= 1.19.0, < 2.0)
|
46
|
-
cocoapods-core (1.10.1)
|
47
|
-
activesupport (> 5.0, < 6)
|
48
|
-
addressable (~> 2.6)
|
49
|
-
algoliasearch (~> 1.0)
|
50
|
-
concurrent-ruby (~> 1.1)
|
51
|
-
fuzzy_match (~> 2.0.4)
|
52
|
-
nap (~> 1.0)
|
53
|
-
netrc (~> 0.11)
|
54
|
-
public_suffix
|
55
|
-
typhoeus (~> 1.0)
|
56
|
-
cocoapods-deintegrate (1.0.4)
|
57
|
-
cocoapods-downloader (1.4.0)
|
58
|
-
cocoapods-plugins (1.0.0)
|
59
|
-
nap
|
60
|
-
cocoapods-search (1.0.0)
|
61
|
-
cocoapods-trunk (1.5.0)
|
62
|
-
nap (>= 0.8, < 2.0)
|
63
|
-
netrc (~> 0.11)
|
64
|
-
cocoapods-try (1.2.0)
|
65
|
-
colored2 (3.1.2)
|
66
|
-
concurrent-ruby (1.1.8)
|
67
|
-
diff-lcs (1.3)
|
68
|
-
diffy (3.3.0)
|
69
|
-
escape (0.0.4)
|
70
|
-
ethon (0.12.0)
|
71
|
-
ffi (>= 1.3.0)
|
72
|
-
ffi (1.14.2)
|
73
|
-
fourflusher (2.3.1)
|
74
|
-
fuzzy_match (2.0.4)
|
75
|
-
gh_inspector (1.1.3)
|
76
|
-
httpclient (2.8.3)
|
77
|
-
i18n (1.8.8)
|
78
|
-
concurrent-ruby (~> 1.0)
|
79
|
-
jaro_winkler (1.5.4)
|
80
|
-
json (2.5.1)
|
81
|
-
minitest (5.14.3)
|
82
|
-
molinillo (0.6.6)
|
83
|
-
nanaimo (0.3.0)
|
84
|
-
nap (1.1.0)
|
85
|
-
netrc (0.11.0)
|
86
|
-
parallel (1.19.1)
|
87
|
-
parser (2.6.5.0)
|
88
|
-
ast (~> 2.4.0)
|
89
|
-
prettybacon (0.0.2)
|
90
|
-
bacon (~> 1.2)
|
91
|
-
public_suffix (4.0.6)
|
92
|
-
rainbow (3.0.0)
|
93
|
-
rake (12.3.3)
|
94
|
-
rspec (3.9.0)
|
95
|
-
rspec-core (~> 3.9.0)
|
96
|
-
rspec-expectations (~> 3.9.0)
|
97
|
-
rspec-mocks (~> 3.9.0)
|
98
|
-
rspec-core (3.9.0)
|
99
|
-
rspec-support (~> 3.9.0)
|
100
|
-
rspec-expectations (3.9.0)
|
101
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
102
|
-
rspec-support (~> 3.9.0)
|
103
|
-
rspec-mocks (3.9.0)
|
104
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
105
|
-
rspec-support (~> 3.9.0)
|
106
|
-
rspec-support (3.9.0)
|
107
|
-
rubocop (0.78.0)
|
108
|
-
jaro_winkler (~> 1.5.1)
|
109
|
-
parallel (~> 1.10)
|
110
|
-
parser (>= 2.6)
|
111
|
-
rainbow (>= 2.2.2, < 4.0)
|
112
|
-
ruby-progressbar (~> 1.7)
|
113
|
-
unicode-display_width (>= 1.4.0, < 1.7)
|
114
|
-
ruby-macho (1.4.0)
|
115
|
-
ruby-progressbar (1.10.1)
|
116
|
-
starlark_compiler (0.3.0)
|
117
|
-
thread_safe (0.3.6)
|
118
|
-
typhoeus (1.4.0)
|
119
|
-
ethon (>= 0.9.0)
|
120
|
-
tzinfo (1.2.9)
|
121
|
-
thread_safe (~> 0.1)
|
122
|
-
unicode-display_width (1.6.0)
|
123
|
-
xcodeproj (1.19.0)
|
124
|
-
CFPropertyList (>= 2.3.3, < 4.0)
|
125
|
-
atomos (~> 0.1.3)
|
126
|
-
claide (>= 1.0.2, < 2.0)
|
127
|
-
colored2 (~> 3.1)
|
128
|
-
nanaimo (~> 0.3.0)
|
129
|
-
|
130
|
-
PLATFORMS
|
131
|
-
ruby
|
132
|
-
|
133
|
-
DEPENDENCIES
|
134
|
-
bacon (~> 1.2)
|
135
|
-
bundler (>= 2.1)
|
136
|
-
clintegracon (~> 0.9.0)
|
137
|
-
cocoapods (~> 1.9)
|
138
|
-
cocoapods-bazel!
|
139
|
-
prettybacon (~> 0.0.2)
|
140
|
-
rake (~> 12.3)
|
141
|
-
rspec (~> 3.9)
|
142
|
-
rubocop (~> 0.78)
|
143
|
-
|
144
|
-
BUNDLED WITH
|
145
|
-
2.2.8
|