xcpretty / xcode-install

🔽 Install and update your Xcodes
https://fastlane.tools
MIT License
2.59k stars 243 forks source link

xcversion doesn't properly handle Xcode versions that can't be run #435

Open grantjbutler opened 3 years ago

grantjbutler commented 3 years ago

System info:

I'm still running Catalina (macOS 10.15) on my laptop, and tried to install Xcode 12.5 (which requires Big Sur/macOS 11). xcode-install allowed the installation of Xcode 12.5, but of course I couldn't run it, so I proceeded to uninstall it. However, xcode-install didn't properly recognize 12.5 as being installed, as it somehow thought that 12.5 was 0.0. I was able to uninstall 12.5 by providing 0.0 to the uninstall command, but it's unclear why xcode-install had this mix up in the first place. I've attached the console output that shows this my process.

A side effect that I didn't realize at the time was that this bricks other installations of Xcode, as it installs versions of the CoreSimulator.framework that can only run on macOS 11. As a result, when launching any other version of Xcode, it tries to load that framework, but then it causes a crash due to it trying to load on the wrong version of Xcode. I was able to resolve this by deleting /Library/Developer and having a version of Xcode that can actually work on Catalina install its additional components (as well as reinstalling the command line tools which, I dunno if that's actually something that broke when installing Xcode 12.5, but was deleted when I deleted /Library/Developer, so I had to reinstall it anyway).

I realize I'm using an older version of xcode-install, but it doesn't look like this issue has been fixed in newer versions, based off of the release notes of the newer versions.

grantbutler@Starbase-173 ~> xcversion uninstall 12.5
Executable requires at least macOS 11.0, but is being run on macOS 10.15.7, and so is exiting.
[!] Version 12.5 is not installed.
grantbutler@Starbase-173 ~ [1]> xcversion installed
Executable requires at least macOS 11.0, but is being run on macOS 10.15.7, and so is exiting.
0.0 (/Applications/Xcode-12.5.app)
12.2    (/Applications/Xcode-12.2.app)
grantbutler@Starbase-173 ~> xcversion uninstall "0.0"
// uninstallation process proceeds
rogerluan commented 3 years ago

Hey @grantjbutler 👋

Thank you for your report! I feel your frustration, especially since it caused so many undesired side effects outside of the installation of Xcode 12.5 😱

Would you say that a good way to fix this (from a user perspective) would be to simply halt the installation of Xcode if we detect the OS version doesn't support it? This sounds like a feasible and simple solution to me. Let me know your thoughts!

grantjbutler commented 3 years ago

Yeah, I think that'd be a good solution. Prevent me from installing it (though you might not know that it can't or shouldn't be installed until the version of Xocde has been downloaded and unarchived), and probably display some kind of informational message saying that this version is unsupported on the version of macOS the user is running.

rogerluan commented 3 years ago

I agree! And I think we can skip/prevent the multiple-gigabyte download if the requirement for the Xcode version is simply hardcoded in the codebase. Although this might not scale, I don't see a way around it. I'm not even sure after the download, when attempting to install it, if there's any information/warning/error we can get (because, clearly, you were able to install it via CLI 🤷 )

grantjbutler commented 3 years ago

There is Xcode Releases which has all its info in a publicly available JSON file, including the minimum required OS version for a version of Xcode. I'm not sure if that's the direction you all would want to go in, but it would give a way of checking whether the user could even run a version of Xcode before downloading it.

rogerluan commented 3 years ago

Ahh that looks awesome! I didn't know about it. If this was an official Apple API, I'd go all in. However, since it isn't, and there's a non-zero chance that this project (thus API) goes under, it stops being a no-brainer hehe. Playing with that scenario, what do you think a user would expect, if the API can't be reached? I see 3 options, but open to hearing more: a) Default to "don't install" unless the user passes an optional "force installation even if we can't determine eligibility" flag; b) Default to "install", taking the risk that it may cause that failure that you experienced; c) Periodically (once or twice a year?) save a local copy of the JSON in the project, and use that as a fallback data source in case the API fails to respond the most up-to-date JSON.

What do you think?

vahotm commented 3 years ago

@rogerluan In my opinion option c would be the most futureproof and can be automated.

thomasMinshull commented 3 years ago

I can confirm that this is still an issue on 2.7.0

thomasMinshull commented 3 years ago

I would be very careful about deleting /Library/Developer I did this and now am unable to open xcode. Even after uninstalling Xcode, and xcversion, and reinstalling several times xcode crashes on launch.

jgongo commented 3 years ago

@thomasMinshull I guess this comes too late, but I was able to fix my machine just deleting /Library/Developer/PrivateFrameworks/CoreSimulator.framework (in fact I moved it to /Library/Developer/PrivateFrameworks/CoreSimulator.bad.framework just in case I needed to rollback). When installing a proper version of Xcode this gets reinstalled and it works again.