Passa al contenuto

Compilalo


Compilare Kate dal codice sorgente in Linux

In questo momento il codice sorgente di Kate si trova nell'istanza Gitlab invent.kde.org. Questa esercitazione spiega come compilare Kate senza toccare l'installazione globale.

Tutte le cose avverranno in una cartella di sviluppo aggiuntiva. Questo non richiede l'uso i permessi di amministratore, e permette di ripiegare sulla versione di Kate installata globalmente se quella compilata non funziona correttamente.

Poiché questa esercitazione introdurrà una configurazione che consente di sviluppare anche altre parti della pila del software KDE, parleremo di seguito della creazione di un ambiente di sviluppo KDE. I framework di KDE richiesti verranno compilati in aggiunta alle parti dell'applicazione Kate. Ciò facilita la contribuzione a tutti i livelli della pila del software di KDE.

Scegli la cartella per sviluppare Kate e KDE

Scegli tu stesso un percorso in cui dovrebbero finire tutte le cose per lo sviluppo di Kate e di KDE. Oltre ai file di configurazione locale dell'utente, nulla al di fuori di questa directory verrà inquinato. Puoi riutilizzarlo per lo sviluppo di qualsiasi parte della pila del software di KDE.

Per le parti rimanenti di questa descrizione usiamo

~/projects/kde

Sentiti libero di personalizzarla.

Installa kdesrc-build

L'installazione è più o meno la semplice clonazione della versione corrente

mkdir -p ~/projects/kde/src
cd ~/projects/kde/src
git clone https://invent.kde.org/sdk/kdesrc-build.git

Per una facilità di uso futura è meglio collegare simbolicamente lo script di kdesrc-build con qualche cartella all'interno del tuo path, ad esempio se hai delle local bin utente:

ln -s ~/projects/kde/src/kdesrc-build/kdesrc-build ~/bin

Configurazione di kdesrc-build

kdesrc-build ha dei passaggi di configurazione che possono configurare le cose per te, vedi questa introduzione.

Qui mostriamo semplicemente una ~/.config/kdesrc-buildrc che è sufficiente per le necessità dello sviluppo di Kate.

Puoi semplicemente copiare la variante sotto nella tua cartella home come ~/.config/kdesrc-buildrc e adattare il percorso alle tue necessità. Se ti attieni al percorso ~/projects/kde che abbiamo scelto sopra, questo dovrebbe essere usabile 1:1.

global
    # usa l'ultimo software basato su KF6 e Qt6.
    branch-group kf6-qt6

    # we want .kateproject files with ninja, turn off some Qt 5 things to have less dependencies
    cmake-options -G "Kate - Ninja" -DBUILD_WITH_QT6=ON -DQT_MAJOR_VERSION=6 -DPHONON_BUILD_QT5=OFF -DBUILD_QT5=OFF

    # strumenti clangd
    compile-commands-export yes
    compile-commands-linking yes

    # flat structure
    directory-layout flat

    # Installa la cartella per il software di KDE
    install-dir ~/projects/kde/usr

    # Cartella per il codice sorgente scaricato
    source-dir ~/projects/kde/src

    # Directory to build KDE into before installing relative to source-dir by default
    build-dir ~/projects/kde/build
end global

include ${module-definitions-dir}/kf6-qt6.ksb

The important lines to have a good experience developing Kate (or other KDE stuff) with Kate are described below in detail.

Crea i file .kateproject

# vogliamo i file .kateproject con ninja
cmake-options -G "Kate - Ninja"

This ensures you get not only Ninja build files (nifty as this will e.g. automatically use multiple cores for compiles) but in addition .kateproject files inside the build directories for later use, too. With these files, the project plugin of Kate will know what to do, e.g. where the source directory for the compile is and which build commands it should use for the build plugin.

Assicurati che l'integrazione con LSP funzioni

# strumenti clangd
compile-commands-export yes
compile-commands-linking yes

This ensures CMake will generate the compile_commands.json files that are required for clangd based LSP integration. Beside just generating them inside the build directory the linking option will symlink them back to your source directories. This allows zero-configuration usage of the LSP plugin inside Kate (and other editors).

Installa le dipendenze richieste (facoltativo)

kdesrc-build provides some initial setup mode to install the needed packages for several common distributions to start developing. This is helpful if you are not sure if all needed development packages are installed on your system and you don't want to take care of this yourself manually. As this will try to install packages for your distribution, this step will require administrator rights for the package installation. To do that, just trigger:

kdesrc-build --initial-setup

We already created a .config/kdesrc-buildrc, that will be left untouched. For the further usage you don't need to modify your shell settings either.

Build Kate & dependencies

Per innescare una compilazione di Kate e di tutte le dipendenze di KDE necessarie, digita semplicemente:

kdesrc-build --include-dependencies kate

Su una macchina recente impiega qualche minuto: giusto il tempo di prendere un caffè, o di pensare a cosa vuoi veramente implementare.

As long as the KF 6 version of our dependencies is not bundled with your distribution, it might make sense to build some more parts to have better styling and a terminal integration:

kdesrc-build --include-dependencies breeze plasma-integration kwayland-integration konsole kate

If you only want to build Kate without the dependencies because you are sure you have recent enough stuff on your system, you can try:

kdesrc-build --no-include-dependencies kate

But given that on modern machines, the compile times are low, it is more convenient to just build all stuff, that ensures you have e.g. the latest and best KSyntaxHighlighting and KTextEditor frameworks around, too!

Given this setup, you are free to build all KDE software parts with a simple:

kdesrc-build

Ricordati: occorrerà del tempo (e dello spazio su disco).

If during the build you see any failures displayed with a red font, follow this guide - How to solve build problems

Come lo uso per compilare le cose?

To launch you local Kate version, you need to setup the environment first properly to ensure the right plugins and stuff is loaded. Fortunately this is very simple:

source ~/projects/kde/build/kate/prefix.sh
kate

A nifty way to wrap this is to e.g. create yourself a small wrapper script to start your master branch version of Kate inside your local bin directory:

#!/bin/bash
source ~/projects/kde/build/kate/prefix.sh
exec kate "$@"

Mantieniti le cose aggiornate

To keep your local version up-to-date, you can just use the above commands again. They will take care of pulling new changes from the KDE repositories and building/installing them into your local prefix.

Sviluppa!

Adesso, la domanda rimanente è: come sviluppare meglio?

Naturally, if you want to hack on Kate, it might make sense to use Kate for that.

Given the above preparations, that is easy to do, just start your new master version of Kate and pass it the build directory:

kate ~/projects/kde/build/kate

Alternatively, you can navigate there in your terminal and startup Kate from there, it will auto-open it:

cd ~/projects/kde/build/kate
kate

To have the best experience with this, ensure you have at least project & LSP plugin enabled. If you like to have some GUI build integration, activate the build plugin, too.

You will end up with a new Kate windows like shown below.

In the lower "Current Project" tool view you have per default two terminals. The first terminal is inside your build directory, here you can e.g. run your ninja and ninja install commands and such. The second terminal is inside your source directory, perfect for e.g. git command line calls.

Given the above setup, the LSP plugin (if you have clangd installed) should work out of the box.

Other nifty stuff like project wide quick open, search & replace and correct build targets should be setup, too.

Contribute back!

Sentiti libero di creare una richiesta di integrazione su invent.kde.org. Per maggiori informazioni, vedi Unisciti.

Come ottenere supporto?

Se hai delle domande puoi farle nella nostra lista di distribuzione kwrite-devel@kde.org, oppure unisciti a #kate su irc.libera.chat.

Per ulteriori informazioni, vedi Ottieni aiuto.

Compilare Kate dal codice sorgente in Windows

Per compilare Kate/KWrite basate su KF5 puoi seguire la guida su KDE in Windows.

Compilare Kate dal codice sorgente in macOS

Per compilare Kate/KWrite basate su KF5 puoi seguire la guida su KDE in macOS.