Why is topdir set to its default value when rpmbuild called from tcl?
Asked Answered
S

5

30

I have a tcl script which 'exec' rpmbuild. When doing so, the 'topdir' used by rpmbuild is wrong. I have a .rpmmacros file in my home directory and if I call manually rpmbuild, it works fine, ie. the 'topdir' is not the default one.

I added a [exec rpmbuild "--showrc" ] in the tcl script to check the value of topdir and it says '-14: _topdir %{_usrsrc}/redhat' which is the default value.

Can someone explain me why is that situation and how to solve it ?

I would prefer not to have to specify it with --define because it is actually done in a makefile and I don't want to touch it (if no other choice, I will do it).

Spire answered 6/1, 2009 at 15:35 Comment(0)
E
100

There's two ways to change the default rpmbuild topdir:

  1. Per-User: By configuring the RPM topdir in $HOME/.rpmmacros

    %_topdir    %{getenv:HOME}/rpmbuild
    
  2. Per-Project: By configuring the RPM topdir in the Makefile or on the command line

    rpmbuild --define '_topdir build' -ba package.spec
    

Note: in both cases, you will need to make sure your topdir directory has the appropriate directories (BUILD, SRPM, RPM, SPECS and SOURCES)

Enthusiasm answered 21/6, 2010 at 0:34 Comment(6)
awesome. "--define '_topdir xxxxx'" is the most underdocumented piece of rpm lore. I've been searching for this for ages.Transfusion
Mad kudos for dredging this up. Exactly what I needed. Thank you.Episternum
Just placing $HOME doesn't work - you should use %{getenv:HOME}Atrip
I had issues using a relative path; I think it's best to always have this be an abs directory (eg: topdir=pwd/../foo)Accolade
how about define a macro in the SPEC file? like: %define _topdir path/of/new/topdirBloch
This inspired me to try a per-source-package _topdir: %_topdir %{getenv:HOME}/rpmbuild/%{name}/ - and it works! the mixing of files bothered me all the time when working on more than one package, now i have them separate.Hugibert
F
10

In RHEL6 do:

  rpm --showrc|grep topdir
  rpm --showrc|grep srcrpmdir

To see what are the paths being used !

Make this change (my topdir was NOT set to /usr/src/):

vi  /usr/lib/rpm/macros
#       Path to top of build area.
#%_topdir               %{getenv:HOME}/rpmbuild
%_topdir                %{_usrsrc}/redhat

rpm --showrc|grep topdir    now shows   /usr/src/redhat/ as its BUILD dir
Furring answered 29/12, 2011 at 17:0 Comment(0)
A
1

TCL will exec in the current directory by default. You can change the current directory by using the TCL command http://www.tcl.tk/man/tcl8.4/TclCmd/cd.htm cd, for example:

cd ~username

If topdir is an environment variable, you might be able to set it http://www.tcl.tk/man/tcl8.4/TclCmd/tclvars.htm#M4 like this:

set env(topdir) whatever/you/want
Adsorb answered 6/1, 2009 at 18:9 Comment(0)
A
1

My first check would be to make sure you execute the same thing. Do these two on the command line to make sure aliases or paths do not disturb anything.

which rpmbuild

echo 'puts [auto_execok rpmbuild]' | tclsh
Athanasia answered 21/1, 2009 at 7:36 Comment(0)
E
0

In my case, this is due to the variable $HOME which is not set when rpmbuild is called.
The variable is used to search the '/rpmmacros' file. I suggest to use the command 'printenv' to verify.

Egestion answered 12/4, 2017 at 21:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.