XCTest invocation contains unnecessary library/framework search paths

Originator:JSM_2001
Number:rdar://7249507 Date Originated:Sep 11, 2019
Status:Open Resolved:
Product:Xcode Product Version:11.0
Classification:Suggestion Reproducible:Always
 
Please describe the issue:
We are hitting system limits on ARG_MAX for number of parameters that can be passed to an invocation. This is causing issues with scalability as we modularize our codebase. We are currently at a point where we can't run our unit tests (300+ modules).

XCTest invocation contains unnecessary library/framework search paths when `CONFIGURATION_BUILD_DIR` has been set to be unique on targets (for isolation purposes). The unnecessary paths are ones that don't contain any dynamic libraries and frameworks.

Repro:
1. Download the sample project (NOTE: It has a custom `CONFIGURATION_BUILD_DIR` option for each target)
2. Invoke the build with args `xcodebuild -project asfasf.xcodeproj -scheme "run-all-tests" -destination "OS=13.0" -only-testing "FrameworkATests" build-for-testing`
3. Open xctestrun file from built products root directory

Expected:
* Shouldn't contain any extra DYLD flags for search paths, because all targets compiled into `CONFIGURATION_BUILD_DIR` are static (no dynamic libraries or frameworks to be linked)

Actual:
* Lots of unnecessary DYLD flags being supplied that cause overflowing of ARG_MAX when on the scale of 300-400 module dependencies.

NOTE:  Related to FB7122062, but that ticket is tracking the xctestrun containing paths unrelated to the target being compiled (all paths for all targets in a scheme). This ticket is referring to paths for dependencies of the target being compiled, but aren't useful to include as the folders don't contain dynamic libraries or frameworks.
Please list the steps you took to reproduce the issue:

What did you expect to happen?
Only module `CONFIGURATION_BUILD_DIR` related to selected test targets should appear in the xctestrun file. Even better would be only including the `CONFIGURATION_BUILD_DIR` if they're necessary for dynamic frameworks.

As a bonus, it appears like only the `__XPC_DYLD_*` flags in the xctestrun file generated are necessary. It'd be great to remove the `DYLD_LIBRARY_PATH` and `DYLD_FRAMEWORK_PATH` unused variables.

Comments

Project attachment: https://github.com/justinseanmartin/apple_feedback/tree/master/FB7122062


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!