Module: Pod::Bazel
- Defined in:
- lib/cocoapods/bazel.rb,
lib/cocoapods/bazel/util.rb,
lib/cocoapods/bazel/config.rb,
lib/cocoapods/bazel/target.rb,
lib/cocoapods/bazel/version.rb,
lib/cocoapods/bazel/xcconfig_resolver.rb
Defined Under Namespace
Modules: Util, XCConfigResolver Classes: Config, Target
Constant Summary collapse
- VERSION =
'0.1.7.1'
Class Method Summary collapse
- .format_files(build_files:, buildifier:, workspace:) ⇒ Object
- .post_install(installer:) ⇒ Object
- .write_cocoapods_bazel_build_file(path, workspace, config) ⇒ Object
- .write_non_empty_default_xcconfigs(path, default_xcconfigs) ⇒ Object
Class Method Details
.format_files(build_files:, buildifier:, workspace:) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/cocoapods/bazel.rb', line 134 def self.format_files(build_files:, buildifier:, workspace:) return if build_files.empty? args = [] case buildifier when true return unless Pod::Executable.which('buildifier') args = ['buildifier'] when String, Array args = Array(buildifier) else return end args += %w[-type build] executable, *args = args Pod::Executable.execute_command executable, args + build_files.each_key.map { |d| File.join workspace, d, 'BUILD.bazel' }, true end |
.post_install(installer:) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cocoapods/bazel.rb', line 11 def self.post_install(installer:) return unless (config = Config.from_podfile(installer.podfile)) default_xcconfigs = config.default_xcconfigs.transform_values do |xcconfig| _name, xcconfig = XCConfigResolver.resolve_xcconfig(xcconfig) xcconfig end UI.titled_section 'Generating Bazel files' do workspace = installer.config.installation_root sandbox = installer.sandbox # Ensure we declare the sandbox (Pods/) as a package so each Pod (as a package) belongs to sandbox root package instead FileUtils.touch(File.join(installer.config.sandbox_root, 'BUILD.bazel')) 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?('..') raise Informative, " Bazel does not support Pod located outside of current workspace: \\\"\#{package}\\\".\n To fix this, you can move the Pod into workspace,\n or you can symlink the Pod inside the workspace by running `ln -s <path_to_pod> .` at workspace root\n Then change path declared in Podfile to `./<pod_name>`\n Current workspace: \#{workspace}\n MSG\n end\n\n build_file = build_files[package]\n\n targets_without_library_specification = pod_target.file_accessors.reject { |fa| fa.spec.library_specification? }.map do |fa|\n Target.new(\n installer,\n pod_target,\n fa.spec,\n default_xcconfigs,\n config.experimental_deps_debug_and_release,\n config.xcframework_excluded_platforms,\n config.enable_add_testonly\n )\n end\n\n default_target = Target.new(\n installer,\n pod_target,\n nil,\n default_xcconfigs,\n config.experimental_deps_debug_and_release,\n config.xcframework_excluded_platforms,\n config.enable_add_testonly\n )\n\n bazel_targets = [default_target] + targets_without_library_specification\n\n bazel_targets.each do |t|\n load = config.load_for(macro: t.type)\n build_file.add_load(of: load[:rule], from: load[:load])\n build_file.add_target StarlarkCompiler::AST::FunctionCall.new(load[:rule], **t.to_rule_kwargs)\n end\n end\n\n build_files.each_value(&:save!)\n format_files(build_files: build_files, buildifier: config.buildifier, workspace: workspace)\n unless config.build_file_doc.empty?\n build_files.each_key.each do |key|\n path = File.join(workspace, key, 'BUILD.bazel')\n content = File.read(path)\n File.write(path, \"\\\"\\\"\\\"\\n\#{config.build_file_doc}\\n\\\"\\\"\\\"\\n\\n\" + content)\n end\n end\n\n cocoapods_bazel_path = File.join(sandbox.root, 'cocoapods-bazel')\n FileUtils.mkdir_p cocoapods_bazel_path\n\n write_cocoapods_bazel_build_file(cocoapods_bazel_path, workspace, config)\n write_non_empty_default_xcconfigs(cocoapods_bazel_path, default_xcconfigs)\n end\nend\n" |
.write_cocoapods_bazel_build_file(path, workspace, config) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/cocoapods/bazel.rb', line 90 def self.write_cocoapods_bazel_build_file(path, workspace, config) FileUtils.touch(File.join(path, 'BUILD.bazel')) cocoapods_bazel_pkg = Pathname.new(path).relative_path_from Pathname.new(workspace) configs_build_file = StarlarkCompiler::BuildFile.new(workspace: workspace, package: cocoapods_bazel_pkg) configs_build_file.add_load(of: 'string_flag', from: '@bazel_skylib//rules:common_settings.bzl') configs_build_file.add_target StarlarkCompiler::AST::FunctionCall.new('string_flag', name: 'config', build_setting_default: 'debug', visibility: ['//visibility:public']) configs_build_file.add_target StarlarkCompiler::AST::FunctionCall.new('config_setting', name: 'debug', flag_values: { ':config' => 'debug' }, visibility: ['//visibility:public']) configs_build_file.add_target StarlarkCompiler::AST::FunctionCall.new('config_setting', name: 'release', flag_values: { ':config' => 'release' }, visibility: ['//visibility:public']) if config.experimental_deps_debug_and_release configs_build_file.add_target StarlarkCompiler::AST::FunctionCall.new('string_flag', name: 'deps_config', build_setting_default: 'deps_debug', visibility: ['//visibility:public']) configs_build_file.add_target StarlarkCompiler::AST::FunctionCall.new( 'config_setting', name: 'deps_debug', flag_values: { ':deps_config' => 'deps_debug' }, visibility: ['//visibility:public'] ) configs_build_file.add_target StarlarkCompiler::AST::FunctionCall.new( 'config_setting', name: 'deps_release', flag_values: { ':deps_config' => 'deps_release' }, visibility: ['//visibility:public'] ) configs_build_file.add_target StarlarkCompiler::AST::FunctionCall.new( 'config_setting', name: 'deps_debug_and_release', flag_values: { ':deps_config' => 'deps_debug_and_release' }, visibility: ['//visibility:public'] ) end configs_build_file.save! format_files(build_files: { cocoapods_bazel_pkg => configs_build_file }, buildifier: config.buildifier, workspace: workspace) end |
.write_non_empty_default_xcconfigs(path, default_xcconfigs) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/cocoapods/bazel.rb', line 117 def self.write_non_empty_default_xcconfigs(path, default_xcconfigs) return if default_xcconfigs.empty? hash = StarlarkCompiler::AST.new(toplevel: [StarlarkCompiler::AST::Dictionary.new(default_xcconfigs)]) File.open(File.join(path, 'default_xcconfigs.bzl'), 'w') do |f| f << " \"\"\"\n Default xcconfigs given as options to cocoapods-bazel.\n \"\"\"\n\n STARLARK\n f << 'DEFAULT_XCCONFIGS = '\n StarlarkCompiler::Writer.write(ast: hash, io: f)\n end\nend\n" |