KDevelop5/Manual/Сеансы и проекты

From KDE UserBase Wiki
Revision as of 14:04, 9 September 2017 by Claus chr (talk | contribs) (Importing a new version from external source)

Сеансы и проекты: основы KDevelop

В этом разделе мы рассмотрим некоторые термины, как KDevelop смотрит на мир и каковы принципы работы с ним. В частности, вводится понятие сеансов и проектов и описание как можно создать проект с которым Вы будете работать в KDevelop.

Терминология

KDevelop придерживается концепции сеансов и проектов. Сеансы содержат все проекты, которые как-то связаны друг с другом. Например предположим, что Вы являетесь разработчиком как некоторой библиотеки, так и приложения, использующего её. К примеру, библиотеки KDE — это первое, а KDevelop — последнее. Другой пример: допустим что Вы хакер ядра Linux, но Вы так же работаете над драйвером устройства для Linux, который не может быть добавлен непосредственно в исходный код ядра.

И так, возьмём последний пример. Вам требуется создать сеанс в KDevelop, который содержит два проекта: ядро Linux и драйвер устройства. Вы желаете объединить их один сеанс (вместо того, чтобы иметь два сеанса с одним проектом на каждый) потому что будет удобнее видеть функции ядра и структуры данных в KDevelop всякий раз, когда Вы пишете код для драйвера. Это даст возможность автодополнения имён функций и переменных ядра, а так же Вы сможете прочитать документацию на функции ядра в процессе написания драйвера устройства.

Теперь представим, что Вы так же являетесь разработчиком KDE. Теперь Вы желаете иметь второй сеанс, который содержит KDE как проект. В принципе можно иметь один сеанс для всех проектов, но нет никаких основательных причин для этого: в Вашей разработке KDE Вам незачем иметь доступ к функциям ядра и драйвера и у Вас не возникает желания иметь автодополнение имён классов KDE когда Вы работаете над ядром Linux. В конечном итоге сборка множества библиотек KDE независима от пересборки ядра Linux (при этом было бы неплохо иметь возможность пересобрать ядро Linux в то время, когда происходит сборка драйвера, если в ядре изменились некоторые заголовочные файлы).

В ином случае можно использовать разные сеансы для различных версий одного проекта. В этом случае Вам будет нежелательно иметь коллизии в различных реализациях одинаковых классов пересекающиеся между ветками одного проекта. Вы просто можете иметь два сеанса с похожим набором проектов, но отличающихся расположением в файловой системе в случае различных веток разработки.

Создание сеанса и импорт существующих проектов

Давайте придерживаться примера Linux-ядра и драйвера устройства. Безусловно, Вы можете использовать в этом примере собственный набор библиотек и проектов. Чтобы создать новый сеанс, который содержит два проекта, перейдите в верхнее левое меню Сеанс -> Запустить новый сеанс (если Вы запустили Kdevelop впервые, то можно использовать сеанс по умолчанию, т.к. он всё равно ещё пустой). Далее мы желаем добавить к сеансу два проекта. На данный момент мы считаем, что эти проекты уже где-то созданы (случай с созданием проектов с нуля описывается в следующих разделах настоящего руководства). Для этого существует два способа, в зависимости от того, где находится проект: существует ли он на локальном диске, либо же должен быть загружен с сервера.

Option 1: Importing a project from a version control system server

Let's first assume that the project we want to set up -- the Linux kernel -- resides in some version control system on a server, but that you haven't checked it out to your local hard drive yet. In this case, go to the Project menu to create the Linux kernel as a project inside the current session and then follow these steps:

  • Go to Projects -> Fetch project to import a project
  • You then have multiple options to start a new project in the current session, depending on where the source files should come from: You can just point KDevelop at an existing directory (see option 2 below), or you can ask KDevelop to get the sources from a repository.
  • Assuming you don't already have a version checked out:
    • In the dialog box, under Select the source, choose to use Subversion, Git, or one of the other choices
    • Choose a working directory as destination into which the sources should be checked out
    • Choose an URL for the location of the repository where the source files can be obtained
    • Hit Get. This can take quite a long while; depending on the speed of your connection and the size of the project. Unfortunately, in KDevelop 4.2.x the progress bar does not actually show anything, but you can track progress by periodically looking at the output of the command line command
      du -sk /path/to/KDevelop/project
      to see how much data has already been downloaded.

Note

The problem with the progress bar has been reported as KDevelop bug 256832.

Note

In this process, I also get the error message You need to specify a valid location for the project which can be safely ignored.


  • It asks you to select a KDevelop project file in this directory. Since you probably don't have one yet, simply hit Next
  • Hit Next again
  • KDevelop will then ask you to choose a project manager. If this project uses standard Unix make files, choose the custom makefile project manager
  • KDevelop will then start to parse the entire project. Again, it will take quite a while to go through all files and index classes etc. At the bottom right of the main window, there is a progress bar that shows how long this process has come along. (If you have several processor cores, you can accelerate this process by going to the Settings -> Configure KDevelop menu item, then selecting Background parser on the left, and increasing the number of threads for background parsing on the right.)

Option 2: Importing a project that is already on your hard drive

Alternatively, if the project you want to work with already exists on your hard drive (for example, because you have downloaded it as a tar file from an FTP server, because you already checked out a version of the project from a version control system, or because it is your own project that exists only on your own hard drive), then use Projects -> Open/Import project and in the dialog box choose the directory in which your project resides.

Setting up an application as a second project

The next thing you want to do is set up other projects in the same session. In the example above, you would want to add the device driver as the second project, which you can do using exactly the same steps.

If you have multiple applications or libraries, simply repeat the steps to add more and more projects to your session.

Creating projects from scratch

There is of course also the possibility that you want to start a new project from scratch. This can be done using the Projects -> New from Template menu item, which presents you with a template selection dialog. Some project templates are provided with KDevelop, but even more are available by installing the KAppTemplate application. Choose the project type and programming language from the dialog, enter a name and location for you project, and click Next.

The second page of the dialog allows you to set up a version control system. Choose the system you wish the use, and fill in the system-specific configuration if needed. If you do not wish to use a version control system, or want to set it up manually later, choose None. When you are happy with your choice, press Finish.

Your project is now created, so you can try building or installing it. Some templates will include comments within the code, or even a separate README file, and it is recommended that you read those first. Then, you can start working on your project, by adding whatever features you want.