sclorg / rpm-list-builder

RPM List Builder helps you to build a list of defined RPM packages including Software Collection from the recipe file
GNU General Public License v2.0
4 stars 8 forks source link

platforms element in a recipe file #48

Closed junaruga closed 7 years ago

junaruga commented 7 years ago

This ticket is to manage implementing platforms element https://github.com/sclorg/rhscl-rebuild-recipes COLLECTION_ID/packages/PACKAGE/platforms

Format

The platforms file format is inspired from .travis.yml's branches element. https://docs.travis-ci.com/user/customizing-the-build/#Building-Specific-Branches

COLLECTION_ID/packages/PACKAGE is omitted in below examples.

# White list
platforms:
  only:
    - el7
    - el6
# Black list
platforms:
  except:
    - f

The platform string is such as fc23, fc24, fc\d+, el6, el7, el\d+. (=> How about CentOS?) White list can use regular expressions that is inspired from

https://docs.travis-ci.com/user/customizing-the-build/#Building-Specific-Branches you can safelist them all with regular expressions, for example /^v\d+.\d+(.\d+)?(-\S*)?$/.

Internal Logic

How to know current building platform that is used to build RPM package is Fedora, CentOS or RHEL from a RPM spec file's directory?

If it is in the RPM file, we can know using below macro. But this way is not fit this time.

On fedora rawhide mock environment

<mock-chroot> sh-4.4# rpm -E '%{?fedora}'
27   
<mock-chroot> sh-4.4# rpm -E '%{?rhel}'
<= empty
<mock-chroot> sh-4.4# rpm -E '%{?fc27}'
1
<mock-chroot> sh-4.4# rpm -E '%{?fc26}'
<= empty
<mock-chroot> sh-4.4# rpm -E '%{?el7}'
<= empty

On RHEL7 mock environment

<mock-chroot> sh-4.2# rpm -E '%{?rhel}'
7
<mock-chroot> sh-4.2# rpm -E '%{?fedora}'
<= empty
<mock-chroot> sh-4.2# rpm -E '%{?el7}'
1
<mock-chroot> sh-4.2# rpm -E '%{?el6}'
<= empty
<mock-chroot> sh-4.2# rpm -E '%{?fc25}'
<= empty
junaruga commented 7 years ago

Memo: After talking with @hhorak, I decided to add rpmlb --platform option.

junaruga commented 7 years ago

@hhorak one more question, do you know CentOS's macro name such as Fedora: %{?fc25}, RHEL: %{el7}?

junaruga commented 7 years ago

one more question, do you know CentOS's macro name such as Fedora: %{?fc25}, RHEL: %{el7}?

I could solve above thing.

CentOS 7

Download centos-release package from below site, and unpack the RPM file. https://centos-packages.com/7/package/centos-release/

Then

$ cat ./etc/rpm/macros.dist
# dist macros.

%centos_ver 7
%centos 7
%rhel 7
%dist .el7.centos
%el7 1

RHEL 7

<mock-chroot> sh-4.2# cat /etc/rpm/macros.dist
# dist macros.

%rhel 7
%dist .el7
%el7 1

Fedora 25

$ cat /usr/lib/rpm/macros.d/macros.dist
# dist macros.

%fedora                25
%dist                .fc25
%fc25                1
junaruga commented 7 years ago

I decided the specification for the platform element feature considering current situation.

Element

At first, I prefer to use rpmlb --dist string than rpmlb --platform string to specify platform. Because the name dist is used in above RPM macro and .travis.yml to describe platform.

dist as command option

Available dist option's value.

--dist el
--dist el7
--dist fc
--dist fc25
--dist centos
--dist centos7

dist in the recipe file

I show you examples in the recipe file.

Case 1

rubygem-rspec-mocks is built for all the el platforms.

    - rubygem-rspec-mocks:
        replaced_macros:
          need_bootstrap_set: 1
        dist: 'el'

Case 2

rubygem-rspec-mocks is built for only el6 and el7 platforms.

    - rubygem-rspec-mocks:
        replaced_macros:
          need_bootstrap_set: 1
        dist: 'el[67]'

Case 3

rubygem-flexmock's command line sed -i '/^BuildRequires.*rubygem(rspec)$/ s/^/#/' rubygem-flexmock.spec is run for only all the centos platforms.

    - rubygem-flexmock:
        macros:
          _with_bootstrap: 1
        cmd:
          # Hack around flexmock bootstrap
          - |
            if [[ "${DIST}" =~ centos ]]; then
                sed -i '/^BuildRequires.*rubygem(rspec)$/ s/^/#/' rubygem-flexmock.spec
            fi
          - sed -i '/^%check$/,/^popd$/ s/^/#/' rubygem-flexmock.spec
khardix commented 7 years ago

I think that this specification is a bit off from what we actually need. I do not thing that we would need platform specific packages, rather a platform specific features.

Example for what I would want from the feature:

- rubygem-flexmock:
    dist:
      el:
        macros:  # add macro only on el platform
          _with_bootstrap: 1
      fc25:
        cmd:  # execute only on fedora 25
          - sed -i 's/rh-ruby24/rh-ruby23/g' rubygem-flexmock.spec
    replaced_macros:  # top-level – default for all platforms
      need_bootstrap_set: 1

I realize this is much more complicated to implement, so if we need this feature fast, I would settle for if statements in cmds – and worked on expanding the possibilities afterwards.

junaruga commented 7 years ago

I do not thing that we would need platform specific packages, rather a platform specific features.

I think we sill need the platform specific packages. Because below is an actual case that we need platform specific packages. https://github.com/sclorg/rhscl-rebuild-recipes/blob/master/mysql-mariadb.yml#L27

Your below suggested idea (dist/fc25/cmd) may look good. But I prefer that is not for this PR. So, I wish someone will implement that kind of feature in the future. Because this PR's platform feature works for your requirement like this.

- rubygem-flexmock:
    cmd: |
      if [[ "${DIST}" =~ el ]]; then
          sed -i 'something' rubygem-flexmock.spec for "_with_bootstrap: 1"
      elif [[ "${DIST}" =~ fc25 ]]; then
          sed -i 's/rh-ruby24/rh-ruby23/g' rubygem-flexmock.spec
      if
    replaced_macros:  # top-level – default for all platforms
      need_bootstrap_set: 1
khardix commented 7 years ago

Because below is an actual case that we need platform specific packages.

Point taken, that I did not know 😊.

Your below suggested idea (dist/fc25/cmd) may look good. But I prefer that is not for this PR.

OK, lets keep it as it is then, and I will file a separate issue.

junaruga commented 7 years ago

Done. The document is later.