Building an RPM from a local tarball

I’m trying to build a RPM package from a tarball I have created with git archive. The purpose is testing a patch before submitting upstream and it seems I need an RPM installation for this kind of test.

I thought that copying the archive file in the current directory and changing the Version and Source0 lines in the spec file was enough, but fedpkg keeps downloading the old tarball.

Here’s what I’ve done.
Download the original repository and switch to the f30 branch:

git clone https://src.fedoraproject.org/rpms/frescobaldi.git
git checkout f30

Copy the archive file of my local sources with git archive --format=tar.gz HEAD.

Change the spec file:

$ git diff
diff --git a/frescobaldi.spec b/frescobaldi.spec
index 429de4e..3dbf32c 100644
--- a/frescobaldi.spec
+++ b/frescobaldi.spec
@@ -1,13 +1,13 @@
 Name:           frescobaldi
-Version:        3.0.0
-Release:        9%{?dist}
+Version:        3.1.0
+Release:        1%{?dist}
 Summary:        Edit LilyPond sheet music with ease!
 
 # hyphenator.py is LGPLv2+
 # The rest, including the core of the program, is GPLv2+
 License:        GPLv2+ and LGPLv2+
 URL:            http://www.frescobaldi.org/
-Source0:        https://github.com/wbsoft/%{name}/releases/download/v%{version}/%{name}-%{version}.tar.gz
+Source0:        frescobaldi-3.1.0.tar.gz
 Patch0:         frescobaldi-2.18-setup.patch
 BuildArch:      noarch

Run fedpkg:

$ fedpkg --release f30 local

Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.iO4dbi
+ umask 022
+ cd /home/fede/src/fedoraproject.org/rpms/frescobaldi
+ cd /home/fede/src/fedoraproject.org/rpms/frescobaldi
+ rm -rf frescobaldi-3.1.0
+ /usr/bin/gzip -dc /home/fede/src/fedoraproject.org/rpms/frescobaldi/frescobaldi-3.1.0.tar.gz
+ /usr/bin/tar -xof -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd frescobaldi-3.1.0
/var/tmp/rpm-tmp.iO4dbi: line 37: cd: frescobaldi-3.1.0: No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.iO4dbi (%prep)
    Bad exit status from /var/tmp/rpm-tmp.iO4dbi (%prep)


RPM build errors:
Could not execute local: rpmbuild --define '_sourcedir /home/fede/src/fedoraproject.org/rpms/frescobaldi' --define '_specdir /home/fede/src/fedoraproject.org/rpms/frescobaldi' --define '_builddir /home/fede/src/fedoraproject.org/rpms/frescobaldi' --define '_srcrpmdir /home/fede/src/fedoraproject.org/rpms/frescobaldi' --define '_rpmdir /home/fede/src/fedoraproject.org/rpms/frescobaldi' --define 'dist %{?distprefix}.fc30' --define 'fedora 30' --eval '%undefine rhel' --define 'fc30 1' -ba /home/fede/src/fedoraproject.org/rpms/frescobaldi/frescobaldi.spec | tee .build-3.1.0-1.fc30.log

When GitHub creates an archive, it passes --prefix=$name-$tag/, so you need to do the same.

1 Like

Thank you! This helped a lot.

I have a weird error though. It doesn’t happen when I build the original spec file so it must be something I’ve introduced either in the spec or in the application source file.

The error is strange because the file not found is actually there in the build dir:

Processing files: frescobaldi-3.1.0-1.fc30.noarch
error: File not found: /home/fede/rpmbuild/BUILDROOT/frescobaldi-3.1.0-1.fc30.x86_64/usr/lib/python3.7/site-packages/frescobaldi-3.1.0-py3.7.egg-info
Executing(%doc): /bin/sh -e /var/tmp/rpm-tmp.QAWxah
+ umask 022
+ cd /home/fede/src/fedoraproject.org/rpms/frescobaldi
+ cd frescobaldi-3.1.0
+ DOCDIR=/home/fede/rpmbuild/BUILDROOT/frescobaldi-3.1.0-1.fc30.x86_64/usr/share/doc/frescobaldi
+ export LC_ALL=C
+ LC_ALL=C
+ export DOCDIR
+ /usr/bin/mkdir -p /home/fede/rpmbuild/BUILDROOT/frescobaldi-3.1.0-1.fc30.x86_64/usr/share/doc/frescobaldi
+ cp -pr ChangeLog /home/fede/rpmbuild/BUILDROOT/frescobaldi-3.1.0-1.fc30.x86_64/usr/share/doc/frescobaldi
+ cp -pr COPYING /home/fede/rpmbuild/BUILDROOT/frescobaldi-3.1.0-1.fc30.x86_64/usr/share/doc/frescobaldi
+ cp -pr README-development README-translations README.md /home/fede/rpmbuild/BUILDROOT/frescobaldi-3.1.0-1.fc30.x86_64/usr/share/doc/frescobaldi
+ cp -pr THANKS /home/fede/rpmbuild/BUILDROOT/frescobaldi-3.1.0-1.fc30.x86_64/usr/share/doc/frescobaldi
+ cp -pr TODO /home/fede/rpmbuild/BUILDROOT/frescobaldi-3.1.0-1.fc30.x86_64/usr/share/doc/frescobaldi
+ exit 0
    File not found: /home/fede/rpmbuild/BUILDROOT/frescobaldi-3.1.0-1.fc30.x86_64/usr/lib/python3.7/site-packages/frescobaldi-3.1.0-py3.7.egg-info

Do you have an idea of what’s happening?

You can reproduce it this way:

git clone https://github.com/fedelibre/frescobaldi.git
git checkout 879/appdata
git archive --prefix=frescobaldi-3.1.0/ -o frescobaldi-3.1.0.tar.gz HEAD

Then download the spec repository:

git clone https://src.fedoraproject.org/rpms/frescobaldi.git
git checkout f30

and apply this diff:

diff --git a/frescobaldi.spec b/frescobaldi.spec
index 429de4e..c91bd07 100644
--- a/frescobaldi.spec
+++ b/frescobaldi.spec
@@ -1,14 +1,14 @@
 Name:           frescobaldi
-Version:        3.0.0
-Release:        9%{?dist}
+Version:        3.1.0
+Release:        1%{?dist}
 Summary:        Edit LilyPond sheet music with ease!
 
 # hyphenator.py is LGPLv2+
 # The rest, including the core of the program, is GPLv2+
 License:        GPLv2+ and LGPLv2+
 URL:            http://www.frescobaldi.org/
-Source0:        https://github.com/wbsoft/%{name}/releases/download/v%{version}/%{name}-%{version}.tar.gz
-Patch0:         frescobaldi-2.18-setup.patch
+Source0:        frescobaldi-3.1.0.tar.gz
+#Patch0:         frescobaldi-2.18-setup.patch
 BuildArch:      noarch
 
 BuildRequires:  desktop-file-utils
@@ -49,7 +49,7 @@ yet lightweight and easy to use. It features:
 %setup -q
 find -name "*.py"  -exec sed -i -e 's|#! python||' {} \;
 
-%patch0 -p0
+#%patch0 -p0
 
 %build
 python3 ./setup.py build
@@ -66,7 +66,10 @@ desktop-file-install                                         \
    --add-category=AudioVideo                                 \
    --add-category=X-Notation                                 \
    --delete-original                                         \
-   %{name}.desktop
+   data/%{name}.desktop
+
+# AppData file
+cp data/%{name}.metainfo.xml %{buildroot}%{_datadir}/metainfo/
 %files
 %doc ChangeLog COPYING README* THANKS TODO
@@ -75,6 +78,7 @@ desktop-file-install                                         \
 %{python3_sitelib}/%{name}-%{version}-py3.7.egg-info
 %{_datadir}/applications/%{name}.desktop
 %{_datadir}/icons/hicolor/scalable/apps/%{name}.svg
+%{_datadir}/metainfo/%{name}.metainfo.xml
 %{_mandir}/man1/*
 
 %changelog

Ok, I got it. The version in the setup.py is 3.0.1-git, different from the version I was using in the spec, so there’s a problem with the name of a directory listed in %files:

$ ls /home/fede/rpmbuild/BUILDROOT/frescobaldi-3.1.0-1.fc30.x86_64/usr/lib/python3.7/site-packages
frescobaldi-3.0.1_git-py3.7.egg-info  frescobaldi_app

So I changed the Version in the spec, as well as in the tarball filename and prefix. I’ve applied this diff and it works now:

$ git diff
diff --git a/frescobaldi.spec b/frescobaldi.spec
index c91bd07..d6fd6b5 100644
--- a/frescobaldi.spec
+++ b/frescobaldi.spec
@@ -1,5 +1,5 @@
 Name:           frescobaldi
-Version:        3.1.0
+Version:        3.0.1
 Release:        1%{?dist}
 Summary:        Edit LilyPond sheet music with ease!
 
@@ -7,7 +7,7 @@ Summary:        Edit LilyPond sheet music with ease!
 # The rest, including the core of the program, is GPLv2+
 License:        GPLv2+ and LGPLv2+
 URL:            http://www.frescobaldi.org/
-Source0:        frescobaldi-3.1.0.tar.gz
+Source0:        frescobaldi-%{version}.tar.gz
 #Patch0:         frescobaldi-2.18-setup.patch
 BuildArch:      noarch
 
@@ -75,7 +75,7 @@ cp data/%{name}.metainfo.xml %{buildroot}%{_datadir}/metainfo/
 %doc ChangeLog COPYING README* THANKS TODO
 %{_bindir}/%{name}
 %{python3_sitelib}/%{name}_app
-%{python3_sitelib}/%{name}-%{version}-py3.7.egg-info
+%{python3_sitelib}/%{name}-%{version}_git-py3.7.egg-info
 %{_datadir}/applications/%{name}.desktop
 %{_datadir}/icons/hicolor/scalable/apps/%{name}.svg
 %{_datadir}/metainfo/%{name}.metainfo.xml