From 4bbe0879032b3cc6b6660093599da07bdece8b08 Mon Sep 17 00:00:00 2001 From: Ben Whitley Date: Mon, 13 Jul 2020 16:03:11 -0400 Subject: [PATCH 1/2] setup script renamed; new setup script for all versions of xcode but 11 --- setup-xcode11.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ setup.sh | 37 +++++++++++++---------------- 2 files changed, 76 insertions(+), 21 deletions(-) create mode 100644 setup-xcode11.sh diff --git a/setup-xcode11.sh b/setup-xcode11.sh new file mode 100644 index 0000000..92a253e --- /dev/null +++ b/setup-xcode11.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash + +set -o xtrace + +################### +# DEFINITIONS +################### + +service='Xcode' +plugins_dir=~/Library/Developer/Xcode/Plug-ins/ + +################### +# SHUT DOWN XCODE IF IT'S RUNNING +################### + +if pgrep -xq -- "${service}"; then + echo "Xcode is running. Attempt to shut down? y/n" + read answer + if [ "$answer" = "y" ]; then + echo "Shutting down Xcode" + pkill -x $service + else + echo "Xcode needs to be closed" + exit 1 + fi +fi + +################### +# DELETE EXISTING PLUG-IN +################### + +if [ -d "${plugins_dir}Kotlin.ideplugin/" ]; then + echo "Plugins directory and Kotlin plugin found..." + defaults delete com.apple.dt.Xcode DVTPlugInManagerNonApplePlugIns-Xcode-$(xcodebuild -version | grep Xcode | cut -d ' ' -f 2) +fi + +################### +# CREATE PLUG-IN +################### + +echo "Creating plugins directory" +mkdir -p $plugins_dir +cp -r Kotlin.ideplugin $plugins_dir + +################### +# LLDB DEFINITIONS +################### + +lldb_config="command script import ~/Library/Developer/Xcode/Plug-ins/Kotlin.ideplugin/Contents/Resources/konan_lldb_config.py" +lldb_format="command script import ~/Library/Developer/Xcode/Plug-ins/Kotlin.ideplugin/Contents/Resources/konan_lldb.py" + +if grep --quiet -s konan_lldb ~/.lldbinit-Xcode +then + # code if found + echo "konan_lldb.py found in ~/.lldbinit-Xcode" +else + # code if not found + echo $lldb_config >> ~/.lldbinit-Xcode + echo $lldb_format >> ~/.lldbinit-Xcode +fi diff --git a/setup.sh b/setup.sh index eb70ef9..cf586bd 100755 --- a/setup.sh +++ b/setup.sh @@ -1,33 +1,21 @@ #!/usr/bin/env bash -################### -# DEFINITIONS -################### +# Use this script for versions of Xcode other than Xcode 11. -service='Xcode' -plugins_dir=~/Library/Developer/Xcode/Plug-ins/ +set -o xtrace ################### -# SHUT DOWN XCODE IF IT'S RUNNING +# DEFINITIONS ################### -if pgrep -xq -- "${service}"; then - echo "Xcode is running. Attempt to shut down? y/n" - read answer - if [ "$answer" = "y" ]; then - echo "Shutting down Xcode" - pkill -x $service - else - echo "Xcode needs to be closed" - exit 1 - fi -fi +plugins_dir=~/Library/Developer/Xcode/Plug-ins +spec_dir=~/Library/Developer/Xcode/Specifications ################### -# DELETE EXISTING PLUG-IN +# FORGET EXISTING PLUG-IN ################### -if [ -d "${plugins_dir}Kotlin.ideplugin/" ]; then +if [ ! -d "$plugins_dir/Kotlin.ideplugin/" ]; then echo "Plugins directory and Kotlin plugin found..." defaults delete com.apple.dt.Xcode DVTPlugInManagerNonApplePlugIns-Xcode-$(xcodebuild -version | grep Xcode | cut -d ' ' -f 2) fi @@ -40,6 +28,14 @@ echo "Creating plugins directory" mkdir -p $plugins_dir cp -r Kotlin.ideplugin $plugins_dir +################### +# CREATE SPECS DIR +################### + +if [ ! -d "$spec_dir" ]; then + mkdir $spec_dir +fi + ################### # LLDB DEFINITIONS ################### @@ -55,5 +51,4 @@ else # code if not found echo $lldb_config >> ~/.lldbinit-Xcode echo $lldb_format >> ~/.lldbinit-Xcode -fi - +fi \ No newline at end of file From 827d54614993a0f5e00600fcc9c4052ffb1617aa Mon Sep 17 00:00:00 2001 From: Ben Whitley Date: Wed, 15 Jul 2020 09:44:10 -0400 Subject: [PATCH 2/2] setup scripts improved; color setup script renamed; README updated --- README.md | 48 ++++++++++---------------- colorsetup.sh => colorsetup-xcode11.sh | 0 setup-xcode11.sh | 13 +++---- setup.sh | 37 +++++++++++++++----- 4 files changed, 54 insertions(+), 44 deletions(-) rename colorsetup.sh => colorsetup-xcode11.sh (100%) diff --git a/README.md b/README.md index 31dbe33..a2ca9d6 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,39 @@ # Kotlin Native Xcode Support -Plugin to facilitate debugging iOS applications using Kotlin Native in Xcode. -Defines Kotlin files as source code, with basic highlighting. Allows you to -set breakpoints and includes llvm support to view data in the debug window. +Plugin to facilitate debugging iOS applications using Kotlin Native in Xcode. Defines Kotlin files as source code, with basic highlighting. Allows you to set breakpoints and includes llvm support to view data in the debug window. Xcode does not officially support custom language definitions, but they also don't explicitly block them. > ## **We're Hiring!** > -> Touchlab is looking for Android-focused mobile engineers, experienced with Kotlin and -> looking to get involved with Kotlin Multiplatorm in the near future. [More info here](https://on.touchlab.co/2P94J5q). - -# Xcode 11+ - -Xcode does not officially support custom language definitions, but they also don't explicitly block them. However, -Xcode 11 introduced several breaking changes from earlier versions, and some resolutions are still outstanding. - -## Xcode <= 10.x - -For earlier versions, please see [xcode10 branch](https://github.com/touchlab/xcode-kotlin/tree/xcode10). Life moves on, -and we'll only be supporting Xcode 11+. +> Touchlab is looking for Android-focused mobile engineers, experienced with Kotlin and looking to get involved with Kotlin Multiplatorm in the near future. [More info here](https://on.touchlab.co/2P94J5q). ## Installation There are 2 parts to Kotlin support: 1) debugging support and 2) language color and style formatting. -### Step 1: Debugging Support +You need to tell Xcode that `*.kt` files are source files, and run an lldb formatter script when debugging starts. Advanced users may want to do this manually, but if you have Xcode installed in the default place, you can run the setup script. + +### Xcode 11 -You need to tell Xcode that `*.kt` files are source files, and run an lldb formatter script when debugging starts. -Advanced users may want to do this manually, but if you have Xcode installed in the default place, you can run the -setup script. +For debugging support in Xcode 11, run the installation script: ``` -./setup.sh +./setup-xcode11.sh ``` -### Step 2: Formatting Support + Xcode 11 introduced several breaking changes from earlier versions, and some resolutions are still outstanding. If you're using Xcode 11, you need to move some files into a protected area. Some users may not want to do this, and may possibly not have permissions to do this. You'll need to run the formatting support script with sufficient permissions, which generally means `sudo`. -In Xcode 11, you need to move some files into a protected area. Some users may not want to do this, and may possibly -not have permissions to do this. You'll need to run the script with sufficient permissions, which generally means -`sudo`. +``` +sudo ./colorsetup-xcode11.sh +``` *You can still debug Kotlin without formatting support, just FYI. This step is not required.* +### All Other Xcode Versions + +For all other versions of Xcode, the following script will install both debugging and formatting support: + ``` -sudo ./colorsetup.sh +./setup.sh ``` ## Kotlin 1.3.6x Issue @@ -70,12 +61,9 @@ The [Droidcon NYC](https://github.com/touchlab/DroidconKotlin/) app has both the ### Sources -Setting up the Plugin has been an amalgam of various source projects, as Xcode "Plugins" -are undocumented. The most significant piece, the language color file, came from other color -files shipped with Xcode. Xcode plugin file from [GraphQL](https://github.com/apollographql/xcode-graphql/blob/master/GraphQL.ideplugin/Contents/Resources/GraphQL.xcplugindata) +Setting up the Plugin has been an amalgam of various source projects, as Xcode "Plugins" are undocumented. The most significant piece, the language color file came from other color files shipped with Xcode. Xcode plugin file from [GraphQL](https://github.com/apollographql/xcode-graphql/blob/master/GraphQL.ideplugin/Contents/Resources/GraphQL.xcplugindata) -LLDB formatting originally comes from the Kotlin/Native project, source [konan_lldb.py](https://github.com/JetBrains/kotlin-native/blob/dbb162a4b523071f31913e888e212df344a1b61e/llvmDebugInfoC/src/scripts/konan_lldb.py), although the way data is grabbed has been heavily modified to better -support an interactive debugger. +LLDB formatting originally comes from the Kotlin/Native project, source [konan_lldb.py](https://github.com/JetBrains/kotlin-native/blob/dbb162a4b523071f31913e888e212df344a1b61e/llvmDebugInfoC/src/scripts/konan_lldb.py), although the way data is grabbed has been heavily modified to better support an interactive debugger. ## Possible Future Stuff diff --git a/colorsetup.sh b/colorsetup-xcode11.sh similarity index 100% rename from colorsetup.sh rename to colorsetup-xcode11.sh diff --git a/setup-xcode11.sh b/setup-xcode11.sh index 92a253e..0d4d46e 100644 --- a/setup-xcode11.sh +++ b/setup-xcode11.sh @@ -1,13 +1,13 @@ #!/usr/bin/env bash -set -o xtrace +# Use this script for Xcode 11. ################### # DEFINITIONS ################### service='Xcode' -plugins_dir=~/Library/Developer/Xcode/Plug-ins/ +plugins_dir=~/Library/Developer/Xcode/Plug-ins ################### # SHUT DOWN XCODE IF IT'S RUNNING @@ -26,11 +26,12 @@ if pgrep -xq -- "${service}"; then fi ################### -# DELETE EXISTING PLUG-IN +# FORGET EXISTING PLUG-IN ################### -if [ -d "${plugins_dir}Kotlin.ideplugin/" ]; then - echo "Plugins directory and Kotlin plugin found..." +if [ -d "${plugins_dir}/Kotlin.ideplugin/" ]; then + echo "Kotlin plugin found. Deleting and forgetting..." + rm -rf "$plugins_dir/Kotlin.ideplugin/" defaults delete com.apple.dt.Xcode DVTPlugInManagerNonApplePlugIns-Xcode-$(xcodebuild -version | grep Xcode | cut -d ' ' -f 2) fi @@ -38,7 +39,7 @@ fi # CREATE PLUG-IN ################### -echo "Creating plugins directory" +echo "Creating new Kotlin plugin" mkdir -p $plugins_dir cp -r Kotlin.ideplugin $plugins_dir diff --git a/setup.sh b/setup.sh index cf586bd..2211cfc 100755 --- a/setup.sh +++ b/setup.sh @@ -2,21 +2,42 @@ # Use this script for versions of Xcode other than Xcode 11. -set -o xtrace - ################### # DEFINITIONS ################### +service='Xcode' plugins_dir=~/Library/Developer/Xcode/Plug-ins spec_dir=~/Library/Developer/Xcode/Specifications +################### +# SHUT DOWN XCODE IF IT'S RUNNING +################### + +if pgrep -xq -- "${service}"; then + echo "Xcode is running. Attempt to shut down? y/n" + read answer + if [ "$answer" = "y" ]; then + echo "Shutting down Xcode..." + pkill -x $service + else + echo "Xcode needs to be closed" + exit 1 + fi +fi + ################### # FORGET EXISTING PLUG-IN ################### -if [ ! -d "$plugins_dir/Kotlin.ideplugin/" ]; then - echo "Plugins directory and Kotlin plugin found..." +if [ -d "$spec_dir/Kotlin.xclangspec" ]; then + echo "Kotlin language spec found. Deleting..." + rm "$spec_dir/Kotlin.xclangspec" +fi + +if [ -d "$plugins_dir/Kotlin.ideplugin/" ]; then + echo "Kotlin plugin found. Deleting and forgetting..." + rm -rf "$plugins_dir/Kotlin.ideplugin/" defaults delete com.apple.dt.Xcode DVTPlugInManagerNonApplePlugIns-Xcode-$(xcodebuild -version | grep Xcode | cut -d ' ' -f 2) fi @@ -24,7 +45,7 @@ fi # CREATE PLUG-IN ################### -echo "Creating plugins directory" +echo "Creating new Kotlin plugin" mkdir -p $plugins_dir cp -r Kotlin.ideplugin $plugins_dir @@ -32,9 +53,9 @@ cp -r Kotlin.ideplugin $plugins_dir # CREATE SPECS DIR ################### -if [ ! -d "$spec_dir" ]; then - mkdir $spec_dir -fi +echo "Creating new Kotlin language spec" +mkdir -p $spec_dir +cp Kotlin.xclangspec $spec_dir ################### # LLDB DEFINITIONS