2

I have a Python-based SVN pre-commit script that generates an rpmbuild .spec file and runs rpmbuild -bb my.spec via subprocess. The current state is:

1) When doing an SVN commit (SVN over SSH) remotely the rpmbuild fails with...

error: failed to create directory %{_topdir}: /rpmbuild: Permission denied

2) When I rpmbuild -bb my.spec (local on the SVN server) it completes successfully

I have ~/.rpmmacros...

%_topdir /tmp/rpmbuild

When doing #2 (above) rpmbuild will create BUILD, BUILDROOT, RPMS, SOURCES, SPECS, and SRPMS under /tmp/rpmbuild and an RPM is created in RPMS.

From the command line, if I rpm --showrc the dirs are as I expect (and should be which is why the process completes successfully).

But I have different results from the process running via pre-commit...

Command line... -14: _topdir /tmp/rpmbuild

Pre-commit... -14: _topdir %{getenv:HOME}/rpmbuild

I suspect this is the problem and I do not know how to correct this. I also tried:

1) To set the path in my.spec... %define _topdir /tmp/rpmbuild which gave the same permission denied error.

2) To set the path in the rpmbuild command... rpmbuild --define='_topdir /tmp/rpmbuild' which resulted in error: Macro % has illegal name (%define).

Your expertise in resolving this appreciated; thanks very much!

user1801810
  • 614
  • 1
  • 11
  • 29
  • Is your pre-commit script trying to run `rpmbuild`? Or just use the `SPECS` directory to create the `.spec` file? – Etan Reisner Nov 14 '14 at 19:22
  • Pre-commit runs `rpmbuild -bb my.spec` via `subprocess`. – user1801810 Nov 14 '14 at 19:54
  • Why is your pre-commit hook trying to build an rpm? Is that some sort of build-validation process? Is that cheap enough to make sense there? – Etan Reisner Nov 14 '14 at 20:26
  • Yes, if rpmbuild fails the commit is blocked. Cheap enough? I don't understand. – user1801810 Nov 14 '14 at 20:33
  • I'm surprised that the time it takes to build the rpm is short enough that that is a reasonably pre-commit delay to be adding. That's all. – Etan Reisner Nov 14 '14 at 20:37
  • Oh I understand. Yes, it's pretty quick. Of the three packages (at this point) that it will handle the longest build takes about 10 seconds. Engineering dudes are now requiring all code be deployed via RPMs... replacing a shell script run via cron that grabs tarballs via HTTP and expands into particular dirs along with a tiny bit more magic. – user1801810 Nov 14 '14 at 21:14
  • Surely this problem has not stumped the community! Did I not give enough info, too much, poorly presented?? – user1801810 Nov 18 '14 at 16:50
  • I don't think you can set things like _topdir in a spec file. I think that's too late. When you tried `--define` did you have the `%define _topdir` line in the spec file still? Do you know what line of the spec file that error was coming from? Can you run `rpm --showrc` in the pre-commit hook and see what it spits out? Also `env` in the hook? – Etan Reisner Nov 18 '14 at 17:32

2 Answers2

0

That error means $HOME is unset when pre-commit runs (so your .rpmmacros file isn't being used and ${getenv:HOME} is evaluating to the empty string).

I don't know why that would be (perhaps an svn change) but that seems to be the issue.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
0

The missing piece is the file...

/etc/rpm/macros

I created /etc/rpm and the file macros populated with my needed %_topdir.... After doing so _topdir is available to rpmbuild and my process completes successfully. This was discovered by running rpmbuild through strace.

user1801810
  • 614
  • 1
  • 11
  • 29