82 lines
3.2 KiB
Ruby
82 lines
3.2 KiB
Ruby
#!/usr/bin/env ruby
|
|
# configure_xcode.rb — stamped fresh from template on every build (see gitea.service.ts)
|
|
# Handles all Xcode project modifications at build time:
|
|
# 1. Adds GoogleService-Info.plist to the App target if present
|
|
# 2. Scans Swift sources for Firebase imports and links matching SPM products
|
|
|
|
require 'xcodeproj'
|
|
|
|
PROJECT_PATH = 'ios/App/App.xcodeproj'
|
|
TARGET_NAME = 'App'
|
|
PLIST_SRC = 'ios/App/App/GoogleService-Info.plist'
|
|
|
|
project = Xcodeproj::Project.open(PROJECT_PATH)
|
|
target = project.targets.find { |t| t.name == TARGET_NAME }
|
|
abort "Target '#{TARGET_NAME}' not found in #{PROJECT_PATH}" unless target
|
|
|
|
# ── 1. GoogleService-Info.plist ───────────────────────────────────────────────
|
|
if File.exist?(PLIST_SRC)
|
|
app_group = project.main_group['App']
|
|
unless app_group&.files&.find { |f| f.path == 'GoogleService-Info.plist' }
|
|
file_ref = app_group.new_reference('GoogleService-Info.plist')
|
|
target.resources_build_phase.add_file_reference(file_ref)
|
|
puts "Added GoogleService-Info.plist to target"
|
|
end
|
|
end
|
|
|
|
# ── 2. Scan Swift sources for Firebase imports ────────────────────────────────
|
|
swift_files = Dir['ios/App/App/**/*.swift']
|
|
firebase_imports = swift_files
|
|
.flat_map { |f| File.readlines(f) rescue [] }
|
|
.grep(/^\s*import\s+Firebase\w+/)
|
|
.map { |l| l.strip.split(/\s+/).last }
|
|
.uniq
|
|
.sort
|
|
|
|
if firebase_imports.empty?
|
|
puts "No Firebase imports found — skipping SPM linking"
|
|
project.save
|
|
exit 0
|
|
end
|
|
|
|
puts "Firebase imports detected: #{firebase_imports.join(', ')}"
|
|
|
|
# ── 3. Find firebase-ios-sdk package reference ────────────────────────────────
|
|
firebase_pkg = project.root_object.package_references.find do |p|
|
|
p.respond_to?(:repositoryURL) && p.repositoryURL.to_s.include?('firebase-ios-sdk')
|
|
end
|
|
|
|
unless firebase_pkg
|
|
warn "WARNING: firebase-ios-sdk not registered in project — cannot auto-link products"
|
|
project.save
|
|
exit 0
|
|
end
|
|
|
|
# ── 4. Link helper ────────────────────────────────────────────────────────────
|
|
def link_spm_product(project, target, package_ref, product_name)
|
|
return if target.package_product_dependencies.any? { |d| d.product_name == product_name }
|
|
|
|
dep = project.new(Xcodeproj::Project::Object::XCSwiftPackageProductDependency)
|
|
dep.product_name = product_name
|
|
dep.package = package_ref
|
|
target.package_product_dependencies << dep
|
|
|
|
build_file = project.new(Xcodeproj::Project::Object::PBXBuildFile)
|
|
build_file.product_ref = dep
|
|
target.frameworks_build_phase.files << build_file
|
|
|
|
puts "Linked #{product_name}"
|
|
end
|
|
|
|
# FirebaseCore is a prerequisite for all other Firebase products
|
|
link_spm_product(project, target, firebase_pkg, 'FirebaseCore')
|
|
|
|
firebase_imports.each do |product|
|
|
next if product == 'FirebaseCore' # already linked above
|
|
next if product == 'Firebase' # umbrella import, not a linkable product
|
|
link_spm_product(project, target, firebase_pkg, product)
|
|
end
|
|
|
|
project.save
|
|
puts "Xcode project configured"
|