14 How to integrate external SCM sources #
Application development usually happens in SCM systems like git, subversion, mercurial and alike. These external sources can be used directly in OBS via source services. OBS will always keep a copy of the sources to guarantee that the build sources are still available even when the external SCM server disappears or get altered.
14.1 How to create a source service #
Let OBS create a tar ball out of an SCM repository. This just creates or extend a _service file with some rules how to download and package sources. The actual work happens on a local build or on a service side build. Please note that you need the obs-service-obs_scm installed for local runs.
# osc add https://SOME_URL.git
The web interface is creating as well a _service file when adding an URL to a SCM system.
14.1.1 Follow upstream branches #
The created _service file is set up to follow latest source submissions on each run and looks like this:
<services>
<service name="obs_scm">
<param name="url">https://github.com/FreeCAD/FreeCAD.git</param>
<param name="scm">git</param>
</service>
<service name="set_version" mode="buildtime"/>
<service name="tar" mode="buildtime"/>
<service name="recompress" mode="buildtime">
<param name="file">*.tar</param>
<param name="compression">xz</param>
</service>
</services>
This will create an obscpio archive via the obs_scm service with the latest sources. This archive will get extracted at build time and be processed via the other services to build a compressed tar ball for rpmbuild. To follow a specific branch and additional parameter for "revision" is needed for the obs_scm service.
14.1.2 Fixed versions #
You may want to build an archive for a fixed version, for example an official release which has been tagged by the upstream project. It is recommend to specify the mode="disabled" and to submit the archive via the following
# osc service runall
# osc ar
# osc commit
commands.
14.1.3 Avoid tar balls #
Tar balls are not a requirement by OBS, but by the packaging tool, for example, rpmbuild. However, you may want to decide not to ship a tar ball inside of the src.rpm. This makes sense for large sources where the compression time and needed disk space is just considered a waste for short living builds and where full source packages are not a requirement. You can simplify your _service file in that case, but you need to help rpmbuild to work directly in the source. Since RPM will not include the OBS provided SCM sources in the src.rpm, it is also a good practice to package the _service file instead of the tar ball to give the user a chance to rebuild the src.rpm as long the external SCM server is providing the sources. The simplified _service file looks like this:
<services>
<service name="obs_scm">
<param name="url">https://github.com/FreeCAD/FreeCAD.git</param>
<param name="scm">git</param>
</service>
<service name="set_version" mode="buildtime"/>
</services>
The spec file needs some hints to build inside the extracted sources directly. The macro can be used to switch to build tar balls or not to keep it working for stable releases where you want to provide a complete source RPM.
...
%define build_tar_ball 0
...
%if %{build_tar_ball}
Source0: %{name}-%version.tar.xz
%else
Source0: _service
%endif
...
%prep
%if %{build_tar_ball}
%setup -q
%else
%setup -q -n %_sourcedir/%name-%version -T -D
%endif