0

The aim is to have skeleton spec fun.spec.skel file which contains placeholders for Version, Release and that kind of things.

For the sake of simplicity I try to make a build target which updates those variables such that I transform the fun.spec.skel to fun.spec which I can then commit in my github repo. This is done such that rpmbuild -ta fun.tar does work nicely and no manual modifications of fun.spec.skel are required (people tend to forget to bump the version in the spec file, but not in the buildsystem).

drahnr
  • 6,782
  • 5
  • 48
  • 75

3 Answers3

1

Assuming the implied question is "How would I do this?", the common answer is to put placeholders in the file like @@VERSION@@ and then sed the file, or get more complicated and have autotools do it.

Aaron D. Marasco
  • 6,506
  • 3
  • 26
  • 39
1

We place a version.mk file in our project directories which define environment variables. Sample content includes:

RELPKG=foopackage
RELFULLVERS=1.0.0

As part of a script which builds the RPM, we can source this file:

#!/bin/bash
. $(pwd)/Version.mk
export RELPKG RELFULLVERS

if [ -z "${RELPKG}" ]; then exit 1; fi
if [ -z "${RELFULLVERS}" ]; then exit 1; fi

This leaves us a couple of options to access the values which were set:

  • We can define macros on the rpmbuild command line:

    % rpmbuild -ba --define "relpkg ${RELPKG}" --define "relfullvers ${RELFULLVERS}" foopackage.spec

  • We can access the environment variables using %{getenv:...} in the spec file itself (though this can be harder to deal with errors...):

    %define relpkg %{getenv:RELPKG} %define relfullvers %{getenv:RELFULLVERS}

From here, you simply use the macros in your spec file:

Name:  %{relpkg}
Version: %{relfullvers}

We have similar values (provided by environment variables enabled through Jenkins) which provide the build number which plugs into the "Release" tag.

Jeff W
  • 414
  • 5
  • 16
  • The aim was to get a spec file that is not dependent upon any scripts, such that I could copy it into `~/rpmbuild/SPECS` and building the rpmspec without any further considerations. Thanks for your insights though – drahnr Mar 07 '15 at 14:17
0

I found two ways:

a) use something like

Version: %(./waf version)

where version is a custom waf target

def version_fun(ctx):
    print(VERSION)


class version(Context):
    """Printout the version and only the version"""
    cmd = 'version'
    fun = 'version_fun'

this checks the version at rpm build time


b) create a target that modifies the specfile itself

from waflib.Context import Context
import re
def bumprpmver_fun(ctx):

    spec = ctx.path.find_node('oregano.spec')
    data = None
    with open(spec.abspath()) as f:
        data = f.read()

    if data:
        data = (re.sub(r'^(\s*Version\s*:\s*)[\w.]+\s*', r'\1 {0}\n'.format(VERSION), data, flags=re.MULTILINE))

        with open(spec.abspath(),'w') as f:
            f.write(data)
    else:
        logs.warn("Didn't find that spec file: '{0}'".format(spec.abspath()))


class bumprpmver(Context):
    """Bump version"""
    cmd = 'bumprpmver'
    fun = 'bumprpmver_fun'

The latter is used in my pet project oregano @ github

drahnr
  • 6,782
  • 5
  • 48
  • 75