|
| 1 | +# Building |
| 2 | + |
| 3 | +The xcode-kotlin plugin is written in **Kotlin**. It uses |
| 4 | +[Kotlin/Native](https://kotlinlang.org/docs/native-overview.html) for compiling Kotlin code to native binaries. |
| 5 | + |
| 6 | +Building environment: **IntelliJ IDEA** |
| 7 | + |
| 8 | + |
| 9 | +## Libraries |
| 10 | + |
| 11 | +- [kotlinx-cli](org.jetbrains.kotlinx:kotlinx-cli) - a generic command-line parser used to create user-friendly and flexible command-line interfaces |
| 12 | +- [kotlinx-serialization-json](https://kotlinlang.org/docs/serialization.html) - JSON serialization for Kotlin projects |
| 13 | +- [kotlinx-coroutines](https://github.com/Kotlin/kotlinx.coroutines) - library support for Kotlin coroutines with multiplatform support |
| 14 | +- [Kermit](https://github.com/touchlab/Kermit) - logging utility with composable log outputs |
| 15 | + |
| 16 | +## Project structure |
| 17 | + |
| 18 | +In the `command` directory the commands users can call are implemented: *info*, *install*, *sync* and *uninstall*. |
| 19 | +Each has an `execute` function with the implementation, that calls classes like `Installer` or `Uninstaller`. |
| 20 | +- `BaseXcodeListSubcommand` is an abstract class overriden by the following classes (Info, Install and Sync). It |
| 21 | +provides them with a protected method for getting a list of Xcode installations. |
| 22 | +- `Info` checks for an available update or if the plugin is not yet installed, writes information about the plugin to |
| 23 | +the console, such as installed and bundles versions, if Language spec and LLDB is installed and if LLDB for Xcode has |
| 24 | +been initialized, also Xcode version and the plugin compatibility. |
| 25 | +- `Install` checks for current version and offers updating, reinstalling or downgrading if it is already installed or |
| 26 | +installs it if not. |
| 27 | +- `Sync` adds IDs of Xcode installations to the currently installed Xcode Kotlin plugin. |
| 28 | +- `Uninstall` uninstalls the plugin. |
| 29 | + |
| 30 | +In the `util` directory are, as the name suggests, util classes. |
| 31 | +- `Console` provides convenience functions for prompting user for confirmation or value and printing output to the |
| 32 | +console. |
| 33 | +- `CrashHelper` provides functions for logging, capturing and uploading errors (crash reports). |
| 34 | +- `File` is a class for holding a file path and providing methods for working with a file. |
| 35 | +- `Path` holds a string value and provides methods for appending and deleting path components and resolving sym links. |
| 36 | +It also provides convenience methods for creating Paths to home, work, binary and data directories in its companion |
| 37 | +object. |
| 38 | +- `PropertyList` is a class for converting to and from Swift classes. |
| 39 | +- `Shell` is a helper for executing shell tasks. |
| 40 | + |
| 41 | +The other classes in the `cli` directory are mainly managers and helpers that provide methods for installing and |
| 42 | +uninstalling various parts of the plugin. |
| 43 | +- `Installer` has an `installAll` method for calling install on all the managers. |
| 44 | +- `LangSpecManager` provides `install` and `uninstall` methods and `isInstalled` check for the Kotlin.xclangspec. |
| 45 | +- `LLDBInitManager` provides `install` and `uninstall` methods and `isInstalled` and `sourcesMainLlvmInit` checks for |
| 46 | +the LLDB init. |
| 47 | +- `PluginManager` provides `install`, `sync` and `uninstall` methods,`isInstalled` check and `bundledVersion`, |
| 48 | +`installedVersion` and `targetSupportedXcodeUUIds` properties for the plugin. |
| 49 | +- `Uninstaller` has an `uninstallAll` method for calling uninstall on all the managers. |
| 50 | +- `XcodeHelper` provides methods for interacting with Xcode installations: `ensureXcodeNotRunning` to check and |
| 51 | +optionally shut down running Xcode instances, `allXcodeInstallations` that returns a list of found Xcode installations, |
| 52 | +`addKotlinPluginToDefaults` for adding a plugin to allowed list in Xcode defaults and `removeKotlinPluginFromDefaults` |
| 53 | +for removing it. |
| 54 | + |
| 55 | +In `build.gradle` there are two gradle tasks added: `assembleReleaseExecutableMacos` for building a universal macOS |
| 56 | +binary and `preparePlugin` for preparing the plugin and language specification to build dir. |
| 57 | + |
| 58 | +This project uses Object classes instead of dependency injection (DI) because of its small size. |
0 commit comments