chiark / gitweb /
adt-run: actually make new auxverbscript and pbuilder-based dependency installation...
[autopkgtest.git] / runner / adt-run
index c14e9265821e3aef19f0a41f5703df0a0b9d8b30..9f1f76381bad531730acd289f0791c53a3790b6c 100755 (executable)
@@ -735,6 +735,8 @@ class Testbed:
                stdin=p, stdout=p, stderr=tb._errplumb.stream)
        tb.expect('ok')
        tb.caps = tb.commandr('capabilities')
+       if not 'print-execute-command' in tb.caps:
+               tb.bomb('testbed does not support print-execute-command')
  def stop(tb):
        tb._debug('stop')
        tb.close()
@@ -754,6 +756,37 @@ class Testbed:
        pl = tb.commandr('open')
        tb.scratch = InputDir('tb-scratch', pl[0], True)
        tb.deps_processed = []
+       tb._auxverbscript_make()
+
+ def _auxverbscript_make(tb):
+       pec = tb.commandr('print-execute-command')
+       if len(pec) < 2: tb.bomb('too few results from print-execute-command')
+       tb.ec_cmdl = map(urllib.unquote, pec[0].split(','))
+       tb.ec_mode = urllib.unquote(pec[1])
+       tb.ec_infos = map(urllib.unquote,pec[2:])
+
+       shellquote_re = regexp.compile(r'([\\"$`])')
+       def shellquote_arg(s): return '"' + shellquote_re.sub(r'\\\1', s) + '"'
+       def shellquote_cmdl(l): return ' '.join(map(shellquote_arg,l))
+
+       tb._debug('tb.ec_cmdl = %s' % (`tb.ec_cmdl`))
+
+       tb.ec_auxverbscript = TemporaryFile('satdep-auxverb')
+       print >>open(tb.ec_auxverbscript.write(),'w'), (
+'''#!/bin/sh
+set -ex
+echo >&2 ": $*"
+if [ $# = 2 ] && [ "x$1" = xdpkg-architecture ] && [ "x$2" = x-qDEB_HOST_ARCH ]; then
+       set -- dpkg --print-architecture
+fi
+if [ "x$1" = xsh ] && [ "x$2" = x-c ]; then
+       shift; shift
+       # what a horrible hack!
+fi
+exec '''+shellquote_cmdl(tb.ec_cmdl)+' "$*"'+"\n"
+               )
+       os.chmod(tb.ec_auxverbscript.write(), 0755)
+
  def mungeing_apt(tb):
        if not 'revert' in tb.caps:
                tb._need_reset_apt = True
@@ -782,6 +815,7 @@ class Testbed:
                tb.command('revert')
                tb.blamed = []
                for af in tb._ephemeral: af.invalidate(True)
+               tb._auxverbscript_make()
        tb.modified = False
  def prepare2(tb, deps_new):
        tb._debug('prepare2, deps_new=%s' % deps_new, 1)
@@ -796,18 +830,7 @@ class Testbed:
        tb._debug(' installing dependencies '+`deps_new`, 1)
        tb.deps_processed = deps_new
        if not deps_new: return
-       dstr = ', '.join(deps_new)
-       script = binaries.apt_pkg_gdebi_script(
-               dstr, [[
-               'from GDebi.DebPackage import DebPackage',
-               'd = DebPackage(cache)',
-               'res = d.satisfyDependsStr(arg)',
-               ]])
-       cmdl = ['python','-c',script]
-       what = 'install-deps'
-       rc = testbed.execute(what+'-debinstall', cmdl, script=script,
-                               kind='install')
-       if rc: badpkg('dependency install failed, exit code %d' % rc)
+       tb.satisfy_dependencies_string(', '.join(deps_new), 'install-deps')
  def needs_reset(tb):
        tb._debug('needs_reset, previously=%s' % tb.modified, 1)
        tb.modified = True
@@ -856,7 +879,7 @@ class Testbed:
                        " expected %d result parameters" %
                        (string, l, len(ll), nresults))
        return ll
- def commandr(tb, cmd, args=(), nresults=None):
+ def commandr(tb, cmd, args=(), nresults=None, unquote=True):
        # pass args=[None,...] or =(None,...) to avoid more url quoting
        if type(cmd) is str: cmd = [cmd]
        if len(args) and args[0] is None: args = args[1:]
@@ -864,8 +887,8 @@ class Testbed:
        al = cmd + args
        tb.send(string.join(al))
        ll = tb.expect('ok', nresults)
-       rl = map(urllib.unquote, ll)
-       return rl
+       if unquote: ll = map(urllib.unquote, ll)
+       return ll
  def command(tb, cmd, args=()):
        tb.commandr(cmd, args, 0)
  def commandr1(tb, cmd, args=()):
@@ -925,6 +948,26 @@ class Testbed:
 
        return rc
 
+ def satisfy_dependencies_string(tb, deps, what):
+       # Must have called Binaries.configure_apt
+       debug('dependencies: %s: satisfying %s' % (what,deps))
+       dsc = TemporaryFile('deps.dsc')
+       print >>open(dsc.write(),'w'), 'Build-Depends: ', deps, '\n\n'
+       # pbuilder-satisfydepends has a bug where it ignores the
+       #  Build-Depends if it's the last line in the dsc
+       tb.satisfy_dependencies_dsc(dsc, what)
+
+ def satisfy_dependencies_dsc(tb, dsc, what):
+       # Must have called Binaries.configure_apt
+       cmdl = [ '/usr/lib/pbuilder/pbuilder-satisfydepends-classic',
+               '--binary-all', # --check-key
+               '--internal-chrootexec',tb.ec_auxverbscript.read(),
+               '-c',dsc.read()
+       ]
+       debug('dependencies: %s: running %s' % (what,`cmdl`))
+       rc = subprocess.call(cmdl, stdout=None, stderr=None)
+       if rc: badpkg('dependency install failed, exit code %d' % rc)
+
 #---------- representation of test control files: Field*, Test, etc.
 
 class FieldBase:
@@ -1315,35 +1358,18 @@ END
  def apt_configs(b):
        return {
                "Dir::Etc::sourcelist": b.dir.read(True)+'sources.list',
+               "Debug::pkgProblemResolver": "true",
        }
 
- def apt_pkg_gdebi_script(b, arg, middle):
-       script = [
-               'import apt_pkg',
-               'import urllib',
-               'arg = urllib.unquote("%s")' % urllib.quote(arg),
-               ]
+ def _configure_apt(b, tb):
+       config = OutputFile('apt-config','/etc/apt/apt.conf.d/90autopkgtest',
+                       True)
+       f = open(config.write(),'w')
        for (k,v) in b.apt_configs().iteritems():
-               v = urllib.quote(v)
-               script.append('apt_pkg.Config.Set("%s",urllib.unquote("%s"))'
-                               % (k, v))
-       script += [
-               'from GDebi.Cache import Cache',
-               'cache = Cache()',
-               ]
-       for m in middle:
-               script += m + [
-               'print res',
-               'print d.missingDeps',
-               'print d.requiredChanges',
-               'if not res: raise "gdebi failed (%s, %s, %s): %s" % '+
-                       ' (`res`, `d.missingDeps`, `d.requiredChanges`, '+
-                         'd._failureString)',
-               'cache.commit()',
-               ''
-               ]
-       return '\n'.join(script)
- def apt_get(b):
+               print >>f, '%s { "%s"; };' % (k, v)
+       f.close()
+       
+ def _apt_get(b):
        ag = ['apt-get','-qy']
        for kv in b.apt_configs().iteritems():
                ag += ['-o', '%s=%s' % kv]
@@ -1386,6 +1412,8 @@ END
  def publish(b):
        b._debug('publish')
 
+       b._configure_apt(testbed)
+
        script = '''
   exec >&2
   cd "$1"
@@ -1412,7 +1440,7 @@ END
   if [ "x`ls /var/lib/dpkg/updates`" != x ]; then
     echo >&2 "/var/lib/dpkg/updates contains some files, aargh"; exit 1
   fi
-  '''+ b.apt_get() +''' update >&2
+  '''+ b._apt_get() +''' update >&2
   cat /var/lib/dpkg/status >&3
                '''
        testbed.mungeing_apt()
@@ -1437,7 +1465,7 @@ END
        if pkgs_reinstall:
                for pkg in pkgs_reinstall: testbed.blame(pkg)
                what = 'apt-get-reinstall'
-               cmdl = (b.apt_get() + ' --reinstall install '+
+               cmdl = (b._apt_get() + ' --reinstall install '+
                        ' '.join([pkg for pkg in pkgs_reinstall])+' >&2')
                cmdl = ['sh','-c',cmdl]
                rc = testbed.execute(what, cmdl, script=None, kind='install')
@@ -1448,7 +1476,7 @@ END
        for pkg in b.install:
                what = 'apt-get-install-%s' % pkg
                testbed.blame(pkg)
-               cmdl = b.apt_get() + ' install ' + pkg + ' >&2'
+               cmdl = b._apt_get() + ' install ' + pkg + ' >&2'
                cmdl = ['sh','-c',cmdl]
                rc = testbed.execute(what, cmdl, script=None, kind='install')
                if rc: badpkg("installation of %s failed, exit code %d"
@@ -1529,15 +1557,8 @@ def build_source(act, control_override):
 
        if act.kind == 'dsc':
                testbed.prepare2([])
-               script = binaries.apt_pkg_gdebi_script('', [[
-                               'from GDebi.DebPackage import DebPackage',
-                               'd = DebPackage(cache)',
-                               'res = d.satisfyDependsStr("dpkg-dev")',
-                       ]])
-               cmdl = ['python','-c',script]
-               whatp = what+'-dpkgsource'
-               rc = testbed.execute(what, cmdl, script=script, kind='install')
-               if rc: badpkg('dpkg-source install failed, exit code %d' % rc)
+               testbed.satisfy_dependencies_string('dpkg-dev',
+                                               'install dpkg-dev')
 
        work = TemporaryDir(what+'-build')
        act.work = work
@@ -1632,24 +1653,9 @@ def build_source(act, control_override):
                if act.kind != 'dsc':
                        testbed.prepare2([])
 
-               script = binaries.apt_pkg_gdebi_script(
-                       dsc.read(True), [[
-                       'from GDebi.DscSrcPackage import DscSrcPackage',
-                       'd = DscSrcPackage(cache, arg)',
-                       'res = d.checkDeb()',
-                        ],[
-                       'from GDebi.DebPackage import DebPackage',
-                       'd = DebPackage(cache)',
-                       'res = d.satisfyDependsStr("'+
-                                       ','.join(build_essential)+
-                               '")',
-                       ]])
-
-               cmdl = ['python','-c',script]
-               whatp = what+'-builddeps'
-               rc = testbed.execute(what, cmdl, script=script, kind='install')
-               if rc: badpkg('build-depends install failed,'
-                             ' exit code %d' % rc)
+               testbed.satisfy_dependencies_string('build-essential',
+                               'install build-essential')
+               testbed.satisfy_dependencies_dsc(dsc, 'build dependencies')
 
                script = tmpdir_script + [
                        'cd "$2"',