Build
=====

General
-------

We tend to primarily develop by building rpms and installing them rather
than 'make install'. The make install method should work but it isn't
tested extensively.

The spec files within this repo are similar but not the same as in the
Fedora or RHEL repo.

Details about build system can be found in the `V4/Build system
refactoring <V4/Build_system_refactoring>`__ design page.



The VERSION file
----------------

The version of IPA is mostly controlled in the file VERSION.m4 in the
root of the IPA git repo. This file is generally self-explanatory but it
does distinguish between developer builds and final releases. This is
really only important if you are building RPMs, it puts the GIT version
into the release so you can easily tell where in the revision history
you are working from.

To build a release, define ``IPA_VERSION_IS_GIT_SNAPSHOT`` as ``no`` in
VERSION.m4 file before you execute the build.


Building from the git
---------------------

FreeIPA git repository is using another project as a git submodule to store
the source code for its new webui. The submodule is available at
`freeipa-webui <https://github.com/freeipa/freeipa-webui>`__ and
installed in the directory ``install/freeipa-webui``.

To ensure the specfile is up to date with webui dependencies, it's usually
good idea to run the following command from the install/webui directory:

::

    $ ./fix-spec.sh -i

In order to get more familiar with git submodule concepts, you can read
`git submodules <https://git-scm.com/book/en/v2/Git-Tools-Submodules>`__.

You can clone the FreeIPA repository and its submodules using the following
command:

``$ git clone --recurse-submodules https://codeberg.org/freeipa/freeipa.git``

Next, we will install all packages needed to build FreeIPA as they do
not have to be installed on your system. You can install them easily by
following instructions:

::

    $ cd freeipa
    $ cp freeipa.spec.in freeipa-builddep.spec # this is workaround for yum-builddep: file name has to end with ".spec"
    $ sudo yum-builddep freeipa-builddep.spec

or with dnf (and builddep plugin from ``dnf-plugins-core``:

::

    $ sudo dnf install rpm-build
    $ sudo dnf builddep -D "with_wheels 1" -D "with_lint 1" --spec \
        freeipa.spec.in --best --allowerasing --setopt=install_weak_deps=False

A dose of ``--enablerepo=updates-testing`` may at times be needed.

Depending on the git branch which we want to build, Fedora official
repositories don't always contain versions of packages required for the
build and installation. These requirements are located in
`COPR <https://copr.fedoraproject.org/>`__ repositories. Current ones
are:

-  master branch:
   `@freeipa/freeipa-master <https://copr.fedorainfracloud.org/coprs/g/freeipa/freeipa-master/>`__

To use the repo run (requires **dnf-plugins-core** package installed):

``$ sudo dnf copr enable @freeipa/freeipa-master``

When all packages required for the build are installed, you can start
building FreeIPA. The result will be a tarball with sources, SRPM and
RPMs that can be installed on a system:

::

    $ ./makerpms.sh
    $ sudo yum localinstall dist/rpms/*.rpm

or with dnf

``$ sudo dnf install dist/rpms/*.rpm``

Sometimes the build can fail because of garbage from branch switching or
previous builds. To avoid that, clean the git repository, but make sure
that all your changes are committed.

``$ git clean -dfx``



Running FreeIPA In-tree
-----------------------

If you have IPA installed on your development system you can do some
limited in-tree development of management plugins. To do this:

Server setup:

-  As root user, install IPA using ipa-server-install
-  Create ~/.ipa/alias/.pwd and enter the admin password
-  Run kinit admin
-  To run the server, execute python lite-server.py

Client setup:

-  Copy /etc/ipa/default.conf into ~/.ipa/default.conf
-  Replace xmlrpc_uri with http://127.0.0.1:8888/ipa/xml
-  To run the CLI, execute ./ipa

FreeIPA will detect that it is running in-tree and will use the port and
XML-RPC location that ``lite-server.py`` is listening only. If you make
changes to the server-side of a plugin you'll need to restart
``lite-server.py``.

`Category:ImproveOrRemove <Category:ImproveOrRemove>`__
