Learn and Discover Open Source with Daily Genuine Experience. From Coding, Design, Package Management Tweak to Desktop Customization.
 
   

Table of Content

This is a four-parts article. There are few sections here.

Part One
  • Preface: Test Bed
  • Getting Started With Docker
  • Package Management: RPM Frontend, Get Help, DNF Shell
  • Updating System: OS Release, Repository List, System Upgrade, Extra Commands
  • Package IRSIF: Install, Removal, Query Search, Show Info, Install Feature, List File
  • What's Next
Part Two
  • Dependency: Help, Dependency, Reverse Dependency, Test, Tree
  • Group: Group List, Group Info, Group Install, Beyond Group
  • Repositories: repolist, repoinfo, repo-pkgs, --enablerepo, Mirror
  • What's Next
Part Three
  • Plugin: List, Install, Help, Config Manager Example
  • History: The Log File, DNF History
  • Hold Package: Example, Add Lock, Remove Lock
  • Clean Up
  • Build from Source
  • Miscellanous: Downgrade, dist-sync
  • What's Next
Part Four
  • Build from Source: Requirement, Example, Extract, Dependencies, Build, Install
  • Inspect Package: rpmlint, rpm -Qpl, rpmls, rpm2cpio
  • Conclusion

Build from Source

DNF has the capability to download the source code. Then we can utilize other tool to build from source.

Consider choose herbstluftwm as our guinea pig example.

Thank You Community

I was wondering how DNF handle source code, and I finally figure out a generic steps, from the very nice fedora Community in Google Plus.

Let me quote form “Johan Heikkilä”:

Dnf has capability to install source packages, as long as they are available in the installed/enabled repositories. It is recommended to do the following steps as user and not as root.

In this example:

  • I actually alter the steps a bit for clarity.

  • And I still use root for simplicity. It is just docker experience anyway.

  • Using herbstluftwm as an example case

General Requirement

We require to install rpm-build

$ dnf install rpm-build
Last metadata expiration check: 0:25:14 ago on Sun Sep  3 02:01:23 2017.
Dependencies resolved.
====================================================================
 Package             Arch   Version                   Repository
                                                               Size
====================================================================
Installing:
 rpm-build           x86_64 4.13.90-0.git14002.7.fc28 rawhide 158 k
Upgrading:
 python3-rpm         x86_64 4.13.90-0.git14002.7.fc28 rawhide 115 k
 rpm                 x86_64 4.13.90-0.git14002.7.fc28 rawhide 528 k
...
 xz                  x86_64 5.2.3-4.fc27              rawhide 150 k
 zip                 x86_64 3.0-20.fc27               rawhide 270 k

Transaction Summary
====================================================================
Install  35 Packages
Upgrade   6 Packages

Total download size: 17 M
Is this ok [y/N]:
Downloading Packages:
(1/41): bzip2-1.0.6-24.fc27.x86_64.rpm        44 kB/s |  58 kB     00:01
...
-----------------------------------------------------------------------------
Total                                        565 kB/s |  17 MB     00:30   
...
Running transaction
  Preparing        :                                                     1/1 
  Upgrading        : rpm-plugin-selinux-4.13.90-0.git14002.7.fc28.x8    1/47 
...
Installed:
  rpm-build.x86_64 4.13.90-0.git14002.7.fc28   
...  
Upgraded:
  python3-rpm.x86_64 4.13.90-0.git14002.7.fc28                               
  rpm.x86_64 4.13.90-0.git14002.7.fc28                                       
  rpm-build-libs.x86_64 4.13.90-0.git14002.7.fc28                            
...            

Complete!

Docker RPM: Build Source

And also these toolchain.

$ dnf install gcc make

Download

Now consider using home directory.

cd ~

Since we have already enable rawhide-source, we can directly download.

$ dnf download --source herbstluftwm
Fedora - Rawhide - Developmental pa 840 kB/s |  66 MB     01:20    
Last metadata expiration check: 0:01:12 ago on Sun Sep  3 01:53:48 2017.
herbstluftwm-0.6.2-8.fc27.src.rpm    84 kB/s | 228 kB     00:02

or use --enablerepo and --source instead.

$ dnf --enablerepo rawhide download --source herbstluftwm

Docker DNF: Download Source

Extract

We need to extract the previously downloaded package to ~/rpmbuild directory. As you can see below, there are warnings for using root. For real system, please do not use root.

$ rpm -ivh herbstluftwm-0.6.2-8.fc27.src.rpm 
warning: herbstluftwm-0.6.2-8.fc27.src.rpm: Header V3 RSA/SHA256 Signature, key ID 9db62fb1: NOKEY
Updating / installing...
   1:herbstluftwm-0.6.2-8.fc27        
warning: user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root
warning: user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root
################################# [100%]

Docker RPM: Build Source

Now we have two directories inside.

$ ls rpmbuild/
SOURCES  SPECS

Docker RPM: Build Source

Dependencies

Since the case is Herbstluftwm, we also need require to install these packages to avoid missing dependencies.

$ dnf builddep ~/rpmbuild/SPECS/herbstluftwm.spec 
Last metadata expiration check: 2:39:31 ago on Wed Sep 20 14:19:59 2017.
Dependencies resolved.
====================================================================
 Package                Arch     Version            Repository
                                                               Size
====================================================================
Installing:
 glib2-devel            x86_64   2.54.0-1.fc28      rawhide   453 k
 libX11-devel           x86_64   1.6.5-4.fc27       rawhide   984 k
 libXinerama-devel      x86_64   1.1.3-9.fc27       rawhide    17 k
Installing dependencies:
 libX11-xcb             x86_64   1.6.5-4.fc27       rawhide    22 k
 libXau-devel           x86_64   1.0.8-9.fc27       rawhide    18 k
 libXext-devel          x86_64   1.3.3-7.fc27       rawhide    79 k
 libxcb-devel           x86_64   1.12-5.fc27        rawhide   1.0 M
 pcre-cpp               x86_64   8.41-1.fc27.2      rawhide    41 k
 pcre-devel             x86_64   8.41-1.fc27.2      rawhide   548 k
 pcre-utf16             x86_64   8.41-1.fc27.2      rawhide   190 k
 pcre-utf32             x86_64   8.41-1.fc27.2      rawhide   181 k
 xorg-x11-proto-devel   noarch   7.7-23.fc27        rawhide   287 k

Transaction Summary
====================================================================
Install  12 Packages

Total download size: 3.8 M
Installed size: 10 M
Is this ok [y/N]: 

Docker DNF: Build Dependency

Build

Consider get in to ~/rpmbuild/SPECS to build.

$ cd ./rpmbuild/SPECS
$ rpmbuild -ba herbstluftwm.spec
...
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.jys9eY
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd herbstluftwm-0.6.2
+ /usr/bin/rm -rf /root/rpmbuild/BUILDROOT/herbstluftwm-0.6.2-8.fc28.x86_64
+ exit 0

Docker RPM: Build Source

Consider going back to ~/rpmbuild directory. Now we can see additional directories inside as built result.

$ ls   
BUILD  BUILDROOT  RPMS  SOURCES  SPECS  SRPMS

And the build output result

$ ls ~/rpmbuild/RPMS/x86_64
herbstluftwm-0.6.2-8.fc28.x86_64.rpm
herbstluftwm-debuginfo-0.6.2-8.fc28.x86_64.rpm
herbstluftwm-debugsource-0.6.2-8.fc28.x86_64.rpm

Docker RPM: Build Source

Install

Now we can install the previously built rpm.

$ rpm -iv ~/rpmbuild/RPMS/x86_64/herbstluftwm-0.6.2-8.fc28.x86_64.rpm 
Preparing packages...
herbstluftwm-0.6.2-8.fc28.x86_64

Docker RPM: Build Source

Using Mock

There are also Mock solution. But it is beyond this scope.

Thank You

I respect the help from community. Again, thank you.


Inspect Package

Often we need to inspect .rpm package. No need any dnf command, as this more like an rpm issue.

$ dnf install rpmlint rpmdevtools 
...
Installing:
 rpmdevtools            noarch 8.10-3.fc27            rawhide 105 k
 rpmlint                noarch 1.10-3.fc28            rawhide 189 k
...

rpmlint

Check for possible issue, similar to lintian or namcap.

$ rpmlint ~/rpmbuild/RPMS/x86_64/herbstluftwm-0.6.2-8.fc28.x86_64.rpm 
herbstluftwm.x86_64: W: spelling-error %description -l en_US subframes -> sub frames, sub-frames, frames
herbstluftwm.x86_64: W: spelling-error %description -l en_US workspaces -> work spaces, work-spaces, works paces
herbstluftwm.x86_64: W: spelling-error %description -l en_US runtime -> run time, run-time, rudiment
herbstluftwm.x86_64: W: spelling-error %description -l en_US ipc -> pic, inc
herbstluftwm.x86_64: W: spelling-error %description -l en_US startup -> start up, start-up, upstart
herbstluftwm.x86_64: W: only-non-binary-in-usr-lib
1 packages and 0 specfiles checked; 0 errors, 6 warnings.

Docker Fedora: rpmlint

rpm -Qpl

You can also query file -Qpl directly to the .rpm package.

$ rpm -qpl ~/rpmbuild/RPMS/x86_64/herbstluftwm-0.6.2-8.fc28.x86_64.rpm
/etc/xdg/herbstluftwm
/etc/xdg/herbstluftwm/autostart
/etc/xdg/herbstluftwm/panel.sh
/etc/xdg/herbstluftwm/restartpanels.sh
/usr/bin/herbstclient
/usr/bin/herbstluftwm
/usr/lib/.build-id
/usr/lib/.build-id/3d
/usr/lib/.build-id/3d/0a8089936f6a6836c973eafe14d619b086c60a
/usr/lib/.build-id/da
...

Docker Fedora: rpm -qpl

rpmls

Or use the rpmls from the rpmdevtools package

$ rpmls ~/rpmbuild/RPMS/x86_64/herbstluftwm-0.6.2-8.fc28.x86_64.rpm
drwxr-xr-x  /etc/xdg/herbstluftwm
-rwxr-xr-x  /etc/xdg/herbstluftwm/autostart
-rwxr-xr-x  /etc/xdg/herbstluftwm/panel.sh
-rwxr-xr-x  /etc/xdg/herbstluftwm/restartpanels.sh
-rwxr-xr-x  /usr/bin/herbstclient
-rwxr-xr-x  /usr/bin/herbstluftwm
drwxr-xr-x  /usr/lib/.build-id
drwxr-xr-x  /usr/lib/.build-id/3d
lrwxrwxrwx  /usr/lib/.build-id/3d/0a8089936f6a6836c973eafe14d619b086c60a
...

Docker Fedora: rpmls

rpm2cpio

This one also extract.

$ rpm2cpio ~/rpmbuild/RPMS/x86_64/herbstluftwm-0.6.2-8.fc28.x86_64.rpm | cpio -vid
./etc/xdg/herbstluftwm
./etc/xdg/herbstluftwm/autostart
./etc/xdg/herbstluftwm/panel.sh
./etc/xdg/herbstluftwm/restartpanels.sh
./usr/bin/herbstclient
./usr/bin/herbstluftwm
./usr/lib/.build-id
./usr/lib/.build-id/3d
./usr/lib/.build-id/3d/0a8089936f6a6836c973eafe14d619b086c60a
./usr/lib/.build-id/da
...

Docker Fedora: rpm2cpio, cpio -vid


Conclusion

These are just preliminary knowledge about DNF.

Thank you for reading


Epsi Nurwijayadi bio photo
By Epsi Nurwijayadi