vinivendra / Gryphon

The Swift to Kotlin translator.
https://vinivendra.github.io/Gryphon/
Other
609 stars 46 forks source link

Fail to do an init for Xcode project which uses SPM because UseModernBuildSystem is hardcoded to NO #112

Open kyzmitch opened 2 years ago

kyzmitch commented 2 years ago

https://github.com/vinivendra/Gryphon/blob/5bf69a6d33839a7b9db3d82283b6c2bff878eeac/Sources/GryphonLib/Driver.swift#L786

It seems when Xcode project uses Swift Package Manager it must use New Build System, but this setting is hardcoded (see code above). UseModernBuildSystem should be possible to set to YES.

Tried to set it in console with bash variable but it shouldn't help, because it is hardcoded in your script. Also, wasn't possible to set it using:

$ defaults write com.apple.dt.Xcode UseModernBuildSystem YES

Xcode project uses it, I checked in Workspace settings.

Full error:

$ gryphon init App.xcodeproj/ --target=HttpKit
Error running xcodebuild:
Command line invocation:
    /Applications/Xcode-13.2.0-beta.app/Contents/Developer/usr/bin/xcodebuild -UseModernBuildSystem=NO -project App.xcodeproj -target HttpKit -dry-run

User defaults from command line:
    IDEPackageSupportUseBuiltinSCM = YES
    UseModernBuildSystem = NO

Resolve Package Graph
Packages are not supported when using the legacy build system.
Resolved source packages:
  AlamofireImage: https://github.com/Alamofire/AlamofireImage.git @ 4.2.0
  Alamofire: https://github.com/Alamofire/Alamofire.git @ 5.5.0

xcodebuild: error: Could not resolve package dependencies:
  Packages are not supported when using the legacy build system.
vinivendra commented 2 years ago

Hey @kyzmitch, thanks for opening this issue. I didn't know we had this problem with the new build system, but I guess it was bound to happen someday.

I see you already started working on a fix, so let me give you some background that might help you out.

The only reason (as far as I remember) why Gryphon runs xcodebuild is because it needs to know every argument that the Swift compiler needs for a successful compilation of the app. The xcodebuild command compiles the whole app, which includes calling the Swift compiler, and prints those commands to the terminal, which means Gryphon can read that and get all the arguments it needs.

Because Gryphon only needs to know what the compilation command is (but doesn't need to actually run it) it tries to call xcodebuild with the -dry-run option to save time, which means forcing xcodebuild to use the legacy system. That said, in a situation where the new build system is needed, I agree that it would be better to take longer but work correctly than to not work at all. I would, however, add a warning telling the user about the extra time it'll take, just so that they know what they're getting into.

I'll try to add a few comments to your PR to try to steer you in the right direction when I have time, but all in all it looks like a great start 😄