Skip to content

Commit 7d22470

Browse files
bopangzzGerrit Code Review
authored and
Gerrit Code Review
committed
Merge "Fix iOSResolver Xcode Project integration to not include unnecessary source files in Pods."
2 parents dffcfbe + f7ae1d0 commit 7d22470

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

source/IOSResolver/src/IOSResolver.cs

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,19 +2188,43 @@ public static void UpdateProjectDeps(
21882188
podPathToProjectPaths[filename.Substring(podsDir.Length + 1)] =
21892189
filename.Substring(pathToBuiltProject.Length + 1);
21902190
}
2191+
2192+
var podsProjectPath = GetProjectPath(podsDir, PODS_PROJECT_NAME);
2193+
UnityEditor.iOS.Xcode.PBXProject podsProject = null;
2194+
2195+
if (File.Exists(podsProjectPath)) {
2196+
podsProject = new UnityEditor.iOS.Xcode.PBXProject();
2197+
podsProject.ReadFromString(File.ReadAllText(podsProjectPath));
2198+
}
2199+
21912200
// Add a reference to each source file in the target project.
21922201
foreach (var podPathProjectPath in podPathToProjectPaths) {
2193-
project.AddFileToBuild(
2194-
target,
2195-
project.AddFile(podPathProjectPath.Value,
2196-
podPathProjectPath.Value,
2197-
UnityEditor.iOS.Xcode.PBXSourceTree.Source));
2198-
// Some source pods (e.g Protobuf) can include files relative to the Pod root,
2199-
// add include paths relative to the Pod's source files for this use case.
2200-
project.UpdateBuildProperty(
2201-
new [] { target }, "USER_HEADER_SEARCH_PATHS",
2202-
new [] { "$(SRCROOT)/" + Path.GetDirectoryName(podPathProjectPath.Value) },
2203-
new string[] {});
2202+
// Get the relative path inside 'Pods/'.
2203+
var sourceFilePathInPod = podPathProjectPath.Value.Substring(PODS_DIR.Length + 1);
2204+
2205+
// Only add source files that are included in the Pod project, this way we
2206+
// can avoid adding source files that are not part of the Pod dependencies.
2207+
if(podsProject != null && podsProject.ContainsFileByRealPath(sourceFilePathInPod,
2208+
UnityEditor.iOS.Xcode.PBXSourceTree.Source))
2209+
{
2210+
Log("Adding source file " + sourceFilePathInPod + " to Xcode project.", true);
2211+
project.AddFileToBuild(
2212+
target,
2213+
project.AddFile(podPathProjectPath.Value,
2214+
podPathProjectPath.Value,
2215+
UnityEditor.iOS.Xcode.PBXSourceTree.Source));
2216+
// Some source pods (e.g Protobuf) can include files relative to the Pod root,
2217+
// add include paths relative to the Pod's source files for this use case.
2218+
project.UpdateBuildProperty(
2219+
new [] { target }, "USER_HEADER_SEARCH_PATHS",
2220+
new [] { "$(SRCROOT)/" + Path.GetDirectoryName(podPathProjectPath.Value) },
2221+
new string[] {});
2222+
}
2223+
else
2224+
{
2225+
Log("Skipping adding source file " + sourceFilePathInPod +
2226+
" to Xcode project due to it is not part of the pod project", true);
2227+
}
22042228
}
22052229

22062230
// Each source pod library target name shares the name of the directory containing
@@ -2348,11 +2372,9 @@ public static void UpdateProjectDeps(
23482372
}
23492373

23502374
// Attempt to read per-file compile / build settings from the Pods
2351-
// project.
2352-
var podsProjectPath = GetProjectPath(podsDir, PODS_PROJECT_NAME);
2353-
if (File.Exists(podsProjectPath)) {
2354-
var podsProject = new UnityEditor.iOS.Xcode.PBXProject();
2355-
podsProject.ReadFromString(File.ReadAllText(podsProjectPath));
2375+
// project. Note that we have a valid podsProject if Pod pbxproj exists.
2376+
// We have a valid podsProject if Pod pbxproj exists.
2377+
if (podsProject != null) {
23562378
foreach (var directory in Directory.GetDirectories(podsDir)) {
23572379
// Each pod will have a top level directory under the pods dir
23582380
// named after the pod. Also, some pods have build targets in

0 commit comments

Comments
 (0)