#368 New option --buildrootdir
Merged 5 years ago by cqi. Opened 5 years ago by cqi.

file modified
+41 -6
@@ -2303,13 +2303,23 @@ 

          # This should have a try and catch koji errors

          self.kojisession.uploadWrapper(file, path, callback=callback)

  

-     def install(self, arch=None, short=False, builddir=None, nocheck=False):

-         """Run rpm -bi

+     def install(self, arch=None, short=False, builddir=None, nocheck=False,

+                 buildrootdir=None):

+         """Run ``rpmbuild -bi``

  

          optionally for a specific arch, short-circuit it, or

          define an alternative builddir

  

          Logs the output and returns nothing

+ 

+         :param str arch: specify a specific arch.

+         :param bool short: short-circuit it.

+         :param str builddir: alternate builddir.

+         :param bool nocheck: do not check.

+         :param str buildrootdir: alternate buildrootdir.

+ 

+         .. versionadded: 1.56

+            Parameter buildrootdir.

          """

  

          # setup the rpm command
@@ -2326,6 +2336,9 @@ 

              cmd.append('--nocheck')

          if self.quiet:

              cmd.append('--quiet')

+         if buildrootdir:

+             cmd.append("--define '_buildrootdir {0}'".format(

+                 os.path.abspath(buildrootdir)))

          cmd.extend(['-bi', os.path.join(self.path, self.spec)])

          # Run the command

          self._run_command(cmd, shell=True)
@@ -2374,7 +2387,8 @@ 

          # Run the command

          self._run_command(cmd, shell=True)

  

-     def local(self, localargs, arch=None, hashtype=None, builddir=None):

+     def local(self, localargs, arch=None, hashtype=None, builddir=None,

+               buildrootdir=None):

          """rpmbuild locally for given arch.

  

          Takes localargs (passed to rpmbuild), arch to build for, and hashtype
@@ -2388,7 +2402,11 @@ 

          :param str hashtype: an alternative algorithm used for payload file

              digests.

          :param str builddir: an alternative builddir.

+         :param str buildrootdir: an alternative buildrootdir.

          :raises rpkgError: if underlying `rpmbuild` fails.

+ 

+         .. versionadded: 1.56

+            Parameter buildrootdir.

          """

  

          # This could really use a list of arches to build for and loop over
@@ -2413,6 +2431,9 @@ 

              cmd.extend(['--target', arch])

          if self.quiet:

              cmd.append('--quiet')

+         if buildrootdir:

+             cmd.append("--define '_buildrootdir {0}'".format(

+                 os.path.abspath(buildrootdir)))

          cmd.extend(['-ba', os.path.join(self.path, self.spec)])

          logfile = '.build-%s-%s.log' % (self.ver, self.rel)

  
@@ -2654,12 +2675,16 @@ 

  

          self.repo.index.add(['sources', '.gitignore'])

  

-     def prep(self, arch=None, builddir=None):

-         """Run `rpmbuild -bp`

+     def prep(self, arch=None, builddir=None, buildrootdir=None):

+         """Run ``rpmbuild -bp``

  

          :param str arch: optional to run prep section for a specific arch. By

              default, local system arch will be used.

          :param str builddir: an alternative builddir.

+         :param str buildrootdir: an alternative buildrootdir.

+ 

+         .. versionadded: 1.56

+            Parameter buildrootdir.

          """

  

          # setup the rpm command
@@ -2672,6 +2697,9 @@ 

              cmd.extend(['--target', arch])

          if self.quiet:

              cmd.append('--quiet')

+         if buildrootdir:

+             cmd.append("--define '_buildrootdir {0}'".format(

+                 os.path.abspath(buildrootdir)))

          cmd.extend(['--nodeps', '-bp', os.path.join(self.path, self.spec)])

          # Run the command

          self._run_command(cmd, shell=True)
@@ -2767,10 +2795,14 @@ 

                  line_num += 1

          return [line_num, offset - offset_inc + 1]

  

-     def verify_files(self, builddir=None):

+     def verify_files(self, builddir=None, buildrootdir=None):

          """Run `rpmbuild -bl` to verify the `%files` section

  

          :param str builddir: optionally define an alternate builddir.

+         :param str buildrootdir: optionally define an alternate buildrootdir.

+ 

+         .. versionadded:: 1.56

+            Parameter buildrootdir.

          """

  

          # setup the rpm command
@@ -2779,6 +2811,9 @@ 

          if builddir:

              # Tack on a new builddir to the end of the defines

              cmd.append("--define '_builddir %s'" % os.path.abspath(builddir))

+         if buildrootdir:

+             cmd.append("--define '_buildrootdir {0}'".format(

+                 os.path.abspath(buildrootdir)))

          if self.quiet:

              cmd.append('--quiet')

          cmd.extend(['-bl', os.path.join(self.path, self.spec)])

file modified
+15 -5
@@ -513,6 +513,9 @@ 

          self.rpm_parser_common.add_argument(

              '--builddir', default=None, help='Define an alternate builddir')

          self.rpm_parser_common.add_argument(

+             '--buildrootdir', default=None,

+             help='Define an alternate buildrootdir')

+         self.rpm_parser_common.add_argument(

              '--arch', help='Prep for a specific arch')

  

      def register_build(self):
@@ -1849,7 +1852,8 @@ 

          self.cmd.install(arch=self.args.arch,

                           short=self.args.short_circuit,

                           builddir=self.args.builddir,

-                          nocheck=self.args.nocheck)

+                          nocheck=self.args.nocheck,

+                          buildrootdir=self.args.buildrootdir)

  

      def lint(self):

          self.cmd.lint(self.args.info, self.args.rpmlintconf)
@@ -1867,8 +1871,11 @@ 

              for arg in self.args.bcond_without:

                  localargs.extend(['--without', arg])

  

-         self.cmd.local(localargs, arch=self.args.arch, hashtype=self.args.hash,

-                        builddir=self.args.builddir)

+         self.cmd.local(localargs,

+                        arch=self.args.arch,

+                        hashtype=self.args.hash,

+                        builddir=self.args.builddir,

+                        buildrootdir=self.args.buildrootdir)

  

      def mockbuild(self):

          try:
@@ -2150,7 +2157,9 @@ 

  

      def prep(self):

          self.sources()

-         self.cmd.prep(arch=self.args.arch, builddir=self.args.builddir)

+         self.cmd.prep(arch=self.args.arch,

+                       builddir=self.args.builddir,

+                       buildrootdir=self.args.buildrootdir)

  

      def pull(self):

          self.cmd.pull(rebase=self.args.rebase,
@@ -2224,7 +2233,8 @@ 

          print('\n'.join(unused))

  

      def verify_files(self):

-         self.cmd.verify_files(builddir=self.args.builddir)

+         self.cmd.verify_files(builddir=self.args.builddir,

+                               buildrootdir=self.args.buildrootdir)

  

      def verrel(self):

          print('%s-%s-%s' % (self.cmd.repo_name, self.cmd.ver,

file modified
+46 -19
@@ -545,18 +545,24 @@ 

      @patch('pyrpkg.Commands._run_command')

      def test_prep_with_options(self, _run_command):

          builddir = os.path.join(self.cloned_repo_path, 'builddir')

+         buildrootdir = os.path.join(self.cloned_repo_path, 'buildrootdir')

  

-         cli_cmd = ['rpkg', '--path', self.cloned_repo_path, '--release', 'rhel-6', '-q',

-                    'compile', '--arch', 'i686', '--builddir', builddir]

+         cli_cmd = [

+             'rpkg', '--path', self.cloned_repo_path, '--release', 'rhel-6',

+             '-q', 'compile', '--arch', 'i686', '--builddir', builddir,

+             '--buildrootdir', buildrootdir

+         ]

  

          with patch('sys.argv', new=cli_cmd):

              cli = self.new_cli()

              cli.prep()

  

          spec = os.path.join(cli.cmd.path, cli.cmd.spec)

-         rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + \

-             ["--define '_builddir %s'" % builddir, '--target', 'i686', '--quiet', '--nodeps',

-              '-bp', spec]

+         rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + [

+             "--define '_builddir %s'" % builddir, '--target', 'i686',

+             '--quiet', "--define '_buildrootdir %s'" % buildrootdir,

+             '--nodeps', '-bp', spec

+         ]

          _run_command.assert_called_once_with(rpmbuild, shell=True)

  

  
@@ -580,18 +586,25 @@ 

      @patch('pyrpkg.Commands._run_command')

      def test_install_with_options(self, _run_command):

          builddir = os.path.join(self.cloned_repo_path, 'builddir')

+         buildrootdir = os.path.join(self.cloned_repo_path, 'buildrootdir')

  

-         cli_cmd = ['rpkg', '--path', self.cloned_repo_path, '--release', 'rhel-6', '-q',

-                    'install', '--nocheck', '--arch', 'i686', '--builddir', builddir]

+         cli_cmd = [

+             'rpkg', '--path', self.cloned_repo_path, '--release', 'rhel-6',

+             '-q', 'install', '--nocheck', '--arch', 'i686',

+             '--builddir', builddir, '--buildrootdir', buildrootdir

+         ]

  

          with patch('sys.argv', new=cli_cmd):

              cli = self.new_cli()

              cli.install()

  

          spec = os.path.join(cli.cmd.path, cli.cmd.spec)

-         rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + \

-             ["--define '_builddir %s'" % builddir, '--target', 'i686', '--nocheck', '--quiet',

-              '-bi', spec]

+         rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + [

+             "--define '_builddir %s'" % builddir, '--target', 'i686',

+             '--nocheck', '--quiet',

+             "--define '_buildrootdir %s'" % buildrootdir,

+             '-bi', spec

+         ]

  

          _run_command.assert_called_once_with(rpmbuild, shell=True)

  
@@ -619,18 +632,25 @@ 

      @patch('pyrpkg.subprocess.check_call')

      def test_local_with_options(self, check_call):

          builddir = os.path.join(self.cloned_repo_path, 'this-builddir')

+         buildrootdir = os.path.join(self.cloned_repo_path, 'this-buildrootdir')

  

-         cli_cmd = ['rpkg', '--path', self.cloned_repo_path, '--release', 'rhel-6', '-q', 'local',

-                    '--builddir', builddir, '--arch', 'i686', '--with', 'a', '--without', 'b']

+         cli_cmd = [

+             'rpkg', '--path', self.cloned_repo_path, '--release', 'rhel-6',

+             '-q', 'local', '--builddir', builddir, '--arch', 'i686',

+             '--with', 'a', '--without', 'b', '--buildrootdir', buildrootdir]

  

          with patch('sys.argv', new=cli_cmd):

              cli = self.new_cli()

              cli.local()

  

          spec = os.path.join(cli.cmd.path, cli.cmd.spec)

-         rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + \

-             ['--with', 'a', '--without', 'b', "--define '_builddir %s'" % builddir,

-              '--target', 'i686', '--quiet', '-ba', spec]

+         rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + [

+             '--with', 'a', '--without', 'b',

+             "--define '_builddir %s'" % builddir,

+             '--target', 'i686', '--quiet',

+             "--define '_buildrootdir %s'" % buildrootdir,

+             '-ba', spec

+         ]

          tee = ['tee', '.build-%s-%s.log' % (cli.cmd.ver, cli.cmd.rel)]

  

          cmd = '%s | %s; exit "${PIPESTATUS[0]} ${pipestatus[1]}"' % (
@@ -659,17 +679,24 @@ 

      @patch('pyrpkg.Commands._run_command')

      def test_verify_files_with_options(self, _run_command):

          builddir = os.path.join(self.cloned_repo_path, 'this-builddir')

+         buildrootdir = os.path.join(self.cloned_repo_path, 'this-buildrootdir')

  

-         cli_cmd = ['rpkg', '--path', self.cloned_repo_path, '--release', 'rhel-6', '-q',

-                    'verify-files', '--builddir', builddir]

+         cli_cmd = [

+             'rpkg', '--path', self.cloned_repo_path, '--release', 'rhel-6',

+             '-q', 'verify-files', '--builddir', builddir,

+             '--buildrootdir', buildrootdir

+         ]

  

          with patch('sys.argv', new=cli_cmd):

              cli = self.new_cli()

              cli.verify_files()

  

          spec = os.path.join(cli.cmd.path, cli.cmd.spec)

-         rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + \

-             ["--define '_builddir %s'" % builddir, '--quiet', '-bl', spec]

+         rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + [

+             "--define '_builddir %s'" % builddir,

+             "--define '_buildrootdir %s'" % buildrootdir,

+             '--quiet', '-bl', spec

+         ]

          _run_command.assert_called_once_with(rpmbuild, shell=True)

  

  

This new option is for command local, prep, install and verify-files to
allow not to assemble the rpm in ~/rpmbuild/BUILDROOT/.

Resolves: rhbz#1583822

Signed-off-by: Chenxiong Qi cqi@redhat.com

Fixes #324

rebased onto d8796e7d1d5cb3b27edb5d263fa8398f7314f809

5 years ago

Isn't is rpmbuild command instead of rpm? rpm installed in my system doesn't know -b parameter.

No other comments to be written here.

Good catch. It should be rpmbuild. Thanks.

rebased onto ab31fc4ff0941967e6158fa5983eb752a64ab013

5 years ago

rebased onto 68b8f1c22eea7ce51974f6e910fdb46e1b594ddd

5 years ago

The typo is fixed. Merging.

Pull-Request has been merged by cqi

5 years ago