rpm-software-management / mock

Mock is a tool for a reproducible build of RPM packages.
GNU General Public License v2.0
381 stars 226 forks source link

Specifying `module_enable` config option via the command line errors #1206

Open yavor-atanasov opened 1 year ago

yavor-atanasov commented 1 year ago

Short description of the problem

Specifying module_enable config option via the command line seems to cause an error.

Output of rpm -q mock

mock-5.0-1.el8.noarch

Steps to reproduce issue

This is the command I'm running. The contents of the specfile and the sources is irrelevant, because mock fails when it tries to setup the build environment

/usr/bin/mock --isolation=simple --config-opts module_enable=nodejs:18 --root /etc/mock/rocky+epel-8-aarch64.cfg  --no-bootstrap-image --buildsrpm --spec SPECS/hello-rpm.spec --sources SOURCES --resultdir SRPMS

The error this produces is:

ERROR: Exception(SPECS/hello-rpm.spec) Config(rocky+epel-8-aarch64) 1 minutes 3 seconds
INFO: Results and/or logs in: SRPMS
INFO: Cleaning up build root ('cleanup_on_failure=True')
Start: clean chroot
Finish: clean chroot
ERROR: can only concatenate list (not "str") to list
Traceback (most recent call last):
  File "/usr/libexec/mock/mock", line 1087, in <module>
    exitStatus = main()
  File "/usr/lib/python3.6/site-packages/mockbuild/trace_decorator.py", line 93, in trace
    result = func(*args, **kw)
  File "/usr/libexec/mock/mock", line 847, in main
    result = run_command(options, args, config_opts, commands, buildroot, state)
  File "/usr/lib/python3.6/site-packages/mockbuild/trace_decorator.py", line 93, in trace
    result = func(*args, **kw)
  File "/usr/libexec/mock/mock", line 966, in run_command
    mockbuild.rebuild.do_buildsrpm(config_opts, commands, buildroot, options, args)
  File "/usr/lib/python3.6/site-packages/mockbuild/trace_decorator.py", line 93, in trace
    result = func(*args, **kw)
  File "/usr/lib/python3.6/site-packages/mockbuild/rebuild.py", line 105, in do_buildsrpm
    cmd=cmd, post=None, clean=clean)
  File "/usr/lib/python3.6/site-packages/mockbuild/trace_decorator.py", line 93, in trace
    result = func(*args, **kw)
  File "/usr/lib/python3.6/site-packages/mockbuild/rebuild.py", line 24, in rebuild_generic
    commands.init(prebuild=not config_opts.get('short_circuit'))
  File "/usr/lib/python3.6/site-packages/mockbuild/trace_decorator.py", line 93, in trace
    result = func(*args, **kw)
  File "/usr/lib/python3.6/site-packages/mockbuild/backend.py", line 167, in init
    self.buildroot.initialize(**kwargs)
  File "/usr/lib/python3.6/site-packages/mockbuild/trace_decorator.py", line 93, in trace
    result = func(*args, **kw)
  File "/usr/lib/python3.6/site-packages/mockbuild/buildroot.py", line 186, in initialize
    self._init(prebuild=prebuild)
  File "/usr/lib/python3.6/site-packages/mockbuild/trace_decorator.py", line 93, in trace
    result = func(*args, **kw)
  File "/usr/lib/python3.6/site-packages/mockbuild/buildroot.py", line 264, in _init
    self._init_pkg_management()
  File "/usr/lib/python3.6/site-packages/mockbuild/trace_decorator.py", line 93, in trace
    result = func(*args, **kw)
  File "/usr/lib/python3.6/site-packages/mockbuild/buildroot.py", line 448, in _init_pkg_management
    self._module_setup()
  File "/usr/lib/python3.6/site-packages/mockbuild/trace_decorator.py", line 93, in trace
    result = func(*args, **kw)
  File "/usr/lib/python3.6/site-packages/mockbuild/buildroot.py", line 419, in _module_setup
    cmd = ['module', 'enable'] + self.config['module_enable']
TypeError: can only concatenate list (not "str") to list

I can see why the error happens, but I can't work out how I'm supposed to specify this option via the command line. I can specify this option fine in a config file like this and it gets interpreted as python:

config_opts['module_enable'] = ['nodejs:18']

I can't see any examples of this in any docs. Any help is much appreciated

praiskup commented 1 year ago

The module_enable option doesn't make much sense on the command line. The options you pick at the "chroot initialization" phase are baked into the cache, any other subsequent use of these has no effect. The option is not documented, and is obsoleted by module_setup_commands (we should raise a proper warning).

Anyway, if you need to specify array on commandline, you have set the same value multiple times, and if you need array with a single item - just specify the first item as empty string, e.g. --config-opts module_enable= --config-opts module_enable=nodejs:18.

yavor-atanasov commented 1 year ago

The options you pick at the "chroot initialization" phase are baked into the cache, any other subsequent use of these has no effect

I realised this as I played around with it a bit more. It's a shame, I think being able to trigger different builds with the same root config but vary the enabled yum modules per build would be a great feature. Otherwise, like you say, there's no point in exposing those options on the command line. Also, I'm not sure how you even provide values to the module_setup_commands via the command line given it needs to translate to a list of tuples.

I guess our best bet is to just create separate configurations per build, which will result in multiple root caches (even though they will only differ on the set of enabled modules)

praiskup commented 1 year ago

Alternatively, we could implement a runtime knob for working with modules (so that modules are enabled/installed/... post-init time)? The popularity of modularity is decreasing though; Fedora demodularizes, not sure what's the future to invest too much into it. Would you mind submitting a patch?