require 'json' require 'tmpdir' module PodBuilder class Configuration # Remember to update README.md accordingly DEFAULT_BUILD_SETTINGS = { "ENABLE_BITCODE" => "NO", "GCC_OPTIMIZATION_LEVEL" => "s", "SWIFT_OPTIMIZATION_LEVEL" => "-Osize", "SWIFT_COMPILATION_MODE" => "wholemodule", "CODE_SIGN_IDENTITY" => "", "CODE_SIGNING_REQUIRED" => "NO", "CODE_SIGN_ENTITLEMENTS" => "", "CODE_SIGNING_ALLOWED" => "NO" }.freeze DEFAULT_SPEC_OVERRIDE = { "Google-Mobile-Ads-SDK" => { "module_name": "GoogleMobileAds" }, "React-jsiexecutor" => { "remove_module_maps": ["glog"] }, "React-Core" => { "remove_module_maps": ["glog"] }, "React-Core/Default" => { "public_headers": "React/**/*.{h}" }, "React-jsi" => { "remove_module_maps": ["glog"] }, "React-cxxreact" => { "remove_module_maps": ["glog"] }, "Folly" => { "remove_module_maps": ["glog"] } }.freeze DEFAULT_SKIP_PODS = ["GoogleMaps"] DEFAULT_FORCE_PREBUILD_PODS = ["GoogleTagManager"] DEFAULT_BUILD_SYSTEM = "Legacy".freeze # either Latest (New build system) or Legacy (Standard build system) DEFAULT_LIBRARY_EVOLUTION_SUPPORT = false DEFAULT_PLATFORMS = ["iphoneos", "iphonesimulator", "appletvos", "appletvsimulator"].freeze DEFAULT_BUILD_FOR_APPLE_SILICON = false DEFAULT_BUILD_USING_REPO_PATHS = false private_constant :DEFAULT_BUILD_SETTINGS private_constant :DEFAULT_BUILD_SYSTEM private_constant :DEFAULT_LIBRARY_EVOLUTION_SUPPORT class < exception raise "\n\n#{File.basename(config_path)} is an invalid JSON\n".red end if value = json["spec_overrides"] if value.is_a?(Hash) && value.keys.count > 0 Configuration.spec_overrides = value end end if value = json["skip_licenses"] if value.is_a?(Array) Configuration.skip_licenses = value end end if value = json["skip_pods"] if value.is_a?(Array) Configuration.skip_pods = value end end if value = json["force_prebuild_pods"] if value.is_a?(Array) Configuration.force_prebuild_pods = value end end if value = json["build_settings"] if value.is_a?(Hash) && value.keys.count > 0 Configuration.build_settings = value end end if value = json["build_settings_overrides"] if value.is_a?(Hash) && value.keys.count > 0 Configuration.build_settings_overrides = value end end if value = json["build_system"] if value.is_a?(String) && ["Latest", "Legacy"].include?(value) Configuration.build_system = value end end if value = json["library_evolution_support"] if [TrueClass, FalseClass].include?(value.class) Configuration.library_evolution_support = value end end if value = json["license_filename"] if value.is_a?(String) && value.length > 0 Configuration.license_filename = value end end if value = json["subspecs_to_split"] if value.is_a?(Array) && value.count > 0 Configuration.subspecs_to_split = value end end if value = json["project_name"] if value.is_a?(String) && value.length > 0 Configuration.project_name = value end end if value = json["restore_enabled"] if [TrueClass, FalseClass].include?(value.class) Configuration.restore_enabled = value end end if value = json["allow_building_development_pods"] if [TrueClass, FalseClass].include?(value.class) Configuration.allow_building_development_pods = value end end if value = json["use_bundler"] if [TrueClass, FalseClass].include?(value.class) Configuration.use_bundler = value end end if value = json["deterministic_build"] if [TrueClass, FalseClass].include?(value.class) Configuration.deterministic_build = value end end if value = json["build_for_apple_silicon"] if [TrueClass, FalseClass].include?(value.class) Configuration.build_for_apple_silicon = value end end if value = json["build_using_repo_paths"] if [TrueClass, FalseClass].include?(value.class) Configuration.build_using_repo_paths = value end end if value = json["react_native_project"] if [TrueClass, FalseClass].include?(value.class) Configuration.react_native_project = value end end Configuration.build_settings.freeze sanity_check() end dev_pods_configuration_path = File.join(Configuration.base_path, Configuration.dev_pods_configuration_filename) if File.exist?(dev_pods_configuration_path) begin json = JSON.parse(File.read(dev_pods_configuration_path)) rescue => exception raise "\n\n#{File.basename(dev_pods_configuration_path)} is an invalid JSON\n".red end Configuration.development_pods_paths = json || [] Configuration.development_pods_paths.freeze end if !deterministic_build build_path = "#{build_base_path}#{(Time.now.to_f * 1000).to_i}" lockfile_path = File.join(PodBuilder::home, lockfile_name) end end def self.write config = {} config["project_name"] = Configuration.project_name config["spec_overrides"] = Configuration.spec_overrides config["skip_licenses"] = Configuration.skip_licenses config["skip_pods"] = Configuration.skip_pods config["force_prebuild_pods"] = Configuration.force_prebuild_pods config["build_settings"] = Configuration.build_settings config["build_settings_overrides"] = Configuration.build_settings_overrides config["build_system"] = Configuration.build_system config["library_evolution_support"] = Configuration.library_evolution_support config["license_filename"] = Configuration.license_filename config["subspecs_to_split"] = Configuration.subspecs_to_split config["restore_enabled"] = Configuration.restore_enabled config["allow_building_development_pods"] = Configuration.allow_building_development_pods config["use_bundler"] = Configuration.use_bundler config["deterministic_build"] = Configuration.deterministic_build config["build_for_apple_silicon"] = Configuration.build_for_apple_silicon config["build_using_repo_paths"] = Configuration.build_using_repo_paths config["react_native_project"] = Configuration.react_native_project File.write(config_path, JSON.pretty_generate(config)) end private def self.sanity_check Configuration.skip_pods.each do |pod| if Configuration.force_prebuild_pods.include?(pod) puts "PodBuilder.json contains '#{pod}' both in `force_prebuild_pods` and `skip_pods`. Will force prebuilding.".yellow end end end def self.config_path unless path = podbuilder_path return nil end return File.join(path, Configuration.configuration_filename) end def self.podbuilder_path paths = Dir.glob("#{PodBuilder::home}/**/.pod_builder") paths.reject! { |t| t.match(/pod-builder-.*\/Example\/#{File.basename(Configuration.base_path)}\/\.pod_builder$/i) } raise "\n\nToo many .pod_builder found `#{paths.join("\n")}`\n".red if paths.count > 1 return paths.count > 0 ? File.dirname(paths.first) : nil end end end