|
39 | 39 | end |
40 | 40 |
|
41 | 41 | # 3. Add Source Files |
42 | | -# Assumes files are in [ProjectRoot]/[ExtensionName] |
43 | | -extension_group_path = File.join(project_root, extension_target_name) |
44 | | -extension_rel_path = extension_target_name # Relative to project root |
| 42 | +# Calculate relative path from .xcodeproj folder to Extension folder |
| 43 | +# We know project_root is where extension folder lives. |
| 44 | +# We know project_path is the .xcodeproj file. |
| 45 | +require 'pathname' |
| 46 | +project_dir_path = File.dirname(project_path) |
| 47 | +extension_dir_path = File.join(project_root, extension_target_name) |
| 48 | + |
| 49 | +# Make sure extension directory exists |
| 50 | +unless File.directory?(extension_dir_path) |
| 51 | + puts "Error: Extension directory not found at #{extension_dir_path}" |
| 52 | + exit 1 |
| 53 | +end |
| 54 | + |
| 55 | +# Calculate relative path: e.g. ../../../AgoraBCExtension |
| 56 | +# This path is what we put in the PBXGroup so it resolves correctly relative to the project. |
| 57 | +relative_group_path = Pathname.new(extension_dir_path).relative_path_from(Pathname.new(project_dir_path)).to_s |
| 58 | +puts "Extension Relative Path: #{relative_group_path}" |
45 | 59 |
|
46 | | -# Xcodeproj has group[] access via [name], but find_sub_group isn't standard in older versions or some forks? |
47 | | -# Standard Xcodeproj::Project::Object::PBXGroup usage: |
| 60 | +# Get or Create Group |
48 | 61 | extension_group = project.main_group.find_subpath(extension_target_name) || project.main_group[extension_target_name] |
49 | 62 |
|
50 | 63 | unless extension_group |
51 | | - # If the folder exists on disk, we can add it |
52 | | - if File.directory?(extension_group_path) |
53 | | - extension_group = project.main_group.new_group(extension_target_name, extension_rel_path) |
| 64 | + # Create group with the relative path |
| 65 | + extension_group = project.main_group.new_group(extension_target_name, relative_group_path) |
| 66 | + |
54 | 67 | # Add files recursively |
55 | | - Dir.glob(File.join(extension_group_path, "*")).each do |file_path| |
| 68 | + Dir.glob(File.join(extension_dir_path, "*")).each do |file_path| |
56 | 69 | next if file_path.include?(".DS_Store") |
57 | 70 | file_name = File.basename(file_path) |
| 71 | + |
| 72 | + # For files inside the folder, we can add them to the group. |
| 73 | + # If the group has a path set, new_reference(file_name) adds it relative to the group path. |
58 | 74 | file_ref = extension_group.new_reference(file_name) |
59 | 75 |
|
60 | | - if file_name.end_with?(".h", ".m", ".swift", ".c", ".cpp") |
| 76 | + if file_name.end_with?(".h", ".m", ".swift", ".c", ".cpp", ".mm") |
61 | 77 | extension_target.add_file_references([file_ref]) |
62 | 78 | elsif file_name.end_with?(".plist") |
63 | 79 | # Plist doesn't go to compile sources |
64 | 80 | end |
65 | 81 | end |
66 | | - else |
67 | | - puts "Warning: Extension directory #{extension_group_path} does not exist." |
68 | | - end |
69 | 82 | end |
70 | 83 |
|
71 | 84 | # 4. Configure Build Settings |
| 85 | + |
| 86 | +# Retrieve Main Target Signing Info |
| 87 | +main_dev_team = "" |
| 88 | +# main_sign_identity = "" |
| 89 | +# main_prov_profile = "" |
| 90 | +unless main_target.build_configurations.empty? |
| 91 | + main_config = main_target.build_configurations.first |
| 92 | + main_dev_team = main_config.build_settings['DEVELOPMENT_TEAM'] |
| 93 | + # main_sign_identity = main_config.build_settings['CODE_SIGN_IDENTITY'] |
| 94 | +end |
| 95 | + |
72 | 96 | extension_target.build_configurations.each do |config| |
73 | 97 | config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = extension_bundle_id |
74 | | - # Assuming Info.plist is at [ExtensionName]/Info.plist relative to project file or project root? |
75 | | - # Xcodeproj paths are relative to project file usually. |
76 | | - # If project file is in [Root]/Intermediate/ProjectFiles/..., and source is in [Root]/Extension... |
77 | | - config.build_settings['INFOPLIST_FILE'] = "$(PROJECT_DIR)/../../#{extension_target_name}/Info.plist" |
78 | | - # Adjust this path logic based on where .xcodeproj is vs where source files are |
79 | 98 |
|
| 99 | + # Info.plist path relative to the PROJECT FILE (not the group) |
| 100 | + config.build_settings['INFOPLIST_FILE'] = "#{relative_group_path}/Info.plist" |
| 101 | + |
| 102 | + config.build_settings['PRODUCT_NAME'] = extension_target_name |
80 | 103 | config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0' |
81 | 104 | config.build_settings['SKIP_INSTALL'] = 'YES' |
82 | | -end |
83 | | - |
84 | | -# 5. Add Frameworks |
85 | | -# Framework path: [ProjectRoot]/IOSFramework/AgoraReplayKitExtension.framework |
86 | | -framework_root = File.join(project_root, "IOSFramework") |
87 | | -framework_name = "AgoraReplayKitExtension.framework" |
88 | | -framework_path = File.join(framework_root, framework_name) |
89 | | - |
90 | | -if File.exist?(framework_path) |
91 | | - # framework_group = project.main_group.find_sub_group("IOSFramework") |
92 | | - framework_group = project.main_group.find_subpath("IOSFramework") || project.main_group["IOSFramework"] |
93 | | - unless framework_group |
94 | | - framework_group = project.main_group.new_group("IOSFramework", "IOSFramework") # path relative to project root usually |
95 | | - end |
96 | | - |
97 | | - framework_ref = framework_group.find_file_by_path(framework_name) |
98 | | - unless framework_ref |
99 | | - framework_ref = framework_group.new_reference(framework_name) |
100 | | - end |
101 | | - |
102 | | - # Add to Extension Frameworks Build Phase |
103 | | - unless extension_target.frameworks_build_phase.files_references.include?(framework_ref) |
104 | | - extension_target.frameworks_build_phase.add_file_reference(framework_ref) |
105 | | - puts "Added framework to extension target." |
106 | | - end |
| 105 | + config.build_settings['TARGETED_DEVICE_FAMILY'] = "1,2" # iPhone, iPad |
107 | 106 |
|
108 | | - # Add Framework Search Paths |
109 | | - extension_target.build_configurations.each do |config| |
110 | | - paths = config.build_settings['FRAMEWORK_SEARCH_PATHS'] |
111 | | - paths = [paths] if paths.is_a?(String) |
112 | | - paths = [] if paths.nil? |
113 | | - |
114 | | - # Add path relative to project or absolute |
115 | | - new_path = "$(PROJECT_DIR)/../../IOSFramework" |
116 | | - unless paths.include?(new_path) |
117 | | - paths << new_path |
118 | | - config.build_settings['FRAMEWORK_SEARCH_PATHS'] = paths |
119 | | - end |
| 107 | + # Apply Main Target Signing |
| 108 | + if main_dev_team && !main_dev_team.empty? |
| 109 | + config.build_settings['DEVELOPMENT_TEAM'] = main_dev_team |
| 110 | + config.build_settings['CODE_SIGN_STYLE'] = 'Automatic' |
| 111 | + else |
| 112 | + config.build_settings['CODE_SIGN_STYLE'] = 'Automatic' |
120 | 113 | end |
121 | | -else |
122 | | - puts "Warning: Framework not found at #{framework_path}" |
123 | 114 | end |
124 | 115 |
|
| 116 | +puts "Skipping Framework addition as requested." |
| 117 | +# (Framework logic removed) |
| 118 | + |
| 119 | + |
125 | 120 |
|
126 | 121 | # 6. Add Dependency to Main Target |
127 | 122 | unless main_target.dependencies.any? { |dep| dep.target == extension_target } |
128 | 123 | main_target.add_dependency(extension_target) |
129 | 124 | puts "Added dependency to main target" |
130 | 125 | end |
131 | | - |
| 126 | +# 6. Add Extension to Main Target's Embed App Extensions Phase |
| 127 | +# Build Phase: Copy Files (PlugIns) |
132 | 128 | # 7. Embed Extension in Main App |
133 | 129 | # Look for 'Embed App Extensions' phase or create it |
134 | 130 | # symbol_dst_subfolder_spec :plugins is 13 |
|
0 commit comments