Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental option to generate dependencies labels against an external repository #51

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/cocoapods/bazel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def self.post_install(installer:)
build_files = Hash.new { |h, k| h[k] = StarlarkCompiler::BuildFile.new(workspace: workspace, package: k) }
installer.pod_targets.each do |pod_target|
package = sandbox.pod_dir(pod_target.pod_name).relative_path_from(workspace).to_s
if package.start_with?('..')
if package.start_with?('..') and not config.external_repository
raise Informative, <<~MSG
Bazel does not support Pod located outside of current workspace: \"#{package}\".
To fix this, you can move the Pod into workspace,
Expand All @@ -44,7 +44,8 @@ def self.post_install(installer:)
pod_target,
fa.spec,
default_xcconfigs,
config.experimental_deps_debug_and_release
config.experimental_deps_debug_and_release,
config.external_repository
)
end

Expand All @@ -53,7 +54,8 @@ def self.post_install(installer:)
pod_target,
nil,
default_xcconfigs,
config.experimental_deps_debug_and_release
config.experimental_deps_debug_and_release,
config.external_repository
)

bazel_targets = [default_target] + targets_without_library_specification
Expand Down
21 changes: 17 additions & 4 deletions lib/cocoapods/bazel/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Config
# When enabled cocoapods-bazel will add one additional config_setting for the 'deps' attribute only
# containing both 'debug' and 'release' dependencies.
#
# In other works when this flag is active cocoapods-bazel will continue to create these:
# In other words when this flag is active cocoapods-bazel will continue to create these:
#
# - //Pods/cocoapods-bazel:debug
# - //Pods/cocoapods-bazel:release
Expand Down Expand Up @@ -40,7 +40,16 @@ class Config
# 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
# 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
# BUILD files as source of truth.
:experimental_deps_debug_and_release
:experimental_deps_debug_and_release,
# When enabled, cocoapods-bazel will generate pod dependencies with labels pointing to an external "Pods" repository
# For Example:
#
# //Pods/SomePod
#
# Becomes
#
# @Pods//SomePod
:external_repository
].freeze
private_constant :PLUGIN_KEY
DEFAULTS = {
Expand All @@ -53,8 +62,9 @@ class Config
buildifier: true,
default_xcconfigs: {}.freeze,
features: {
experimental_deps_debug_and_release: false
}
experimental_deps_debug_and_release: false,
external_repository: false
},
}.with_indifferent_access.freeze

private_constant :DEFAULTS
Expand Down Expand Up @@ -110,6 +120,9 @@ def default_xcconfigs
def experimental_deps_debug_and_release
to_h[:features][:experimental_deps_debug_and_release]
end
def external_repository
to_h[:features][:external_repository]
end
end
end
end
19 changes: 12 additions & 7 deletions lib/cocoapods/bazel/target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def add(name, value, defaults: nil)

include XCConfigResolver

attr_reader :installer, :pod_target, :file_accessors, :non_library_spec, :label, :package, :default_xcconfigs, :resolved_xconfig_by_config
private :installer, :pod_target, :file_accessors, :non_library_spec, :label, :package, :default_xcconfigs, :resolved_xconfig_by_config
attr_reader :installer, :pod_target, :file_accessors, :non_library_spec, :label, :package, :default_xcconfigs, :resolved_xconfig_by_config, :external_repository
private :installer, :pod_target, :file_accessors, :non_library_spec, :label, :package, :default_xcconfigs, :resolved_xconfig_by_config, :external_repository

def initialize(installer, pod_target, non_library_spec = nil, default_xcconfigs = {}, experimental_deps_debug_and_release = false)
def initialize(installer, pod_target, non_library_spec = nil, default_xcconfigs = {}, experimental_deps_debug_and_release = false, external_repository = false)
@installer = installer
@pod_target = pod_target
@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? }
Expand All @@ -41,16 +41,21 @@ def initialize(installer, pod_target, non_library_spec = nil, default_xcconfigs
@default_xcconfigs = default_xcconfigs
@resolved_xconfig_by_config = {}
@experimental_deps_debug_and_release = experimental_deps_debug_and_release
@external_repository = external_repository
end

def bazel_label(relative_to: nil)
package_basename = File.basename(package)
packageName = package
if external_repository
packageName = package.gsub('Pods/', '@Pods//')
end
if package == relative_to
":#{label}"
elsif package_basename == label
"//#{package}"
"#{packageName}"
else
"//#{package}:#{label}"
"#{packageName}:#{label}"
end
end

Expand All @@ -67,7 +72,7 @@ def test_host
end

app_spec, app_target = *app_host_info
Target.new(installer, app_target, app_spec, {}, @experimental_deps_debug_and_release)
Target.new(installer, app_target, app_spec, {}, @experimental_deps_debug_and_release, @external_repository)
end

def type
Expand Down Expand Up @@ -97,7 +102,7 @@ def dependent_targets_by_config
raise "Unhandled: #{non_library_spec.spec_type}"
end

targets.transform_values { |v| v.uniq.map { |target| self.class.new(installer, target) } }
targets.transform_values { |v| v.uniq.map { |target| self.class.new(installer, target, nil, {}, false, @external_repository) } }
end

def product_module_name
Expand Down