+ filter = act.ah['dsc_filter']
+
+ if control_test_rc == '1': act.missing_tests_control = True
+
+ # For optional builds:
+ #
+ # We might need to build the package because:
+ # - we want its binaries (filter isn't _ and at least one of the
+ # deb_... isn't ignore)
+ # - the test control file says so
+ # (assuming we have any tests)
+
+ class NeedBuildException: pass
+ def build_needed(m):
+ debug_b('build needed for %s' % m)
+ raise NeedBuildException()
+
+ try:
+ if filter != '_' and (act.ah['deb_forbuilds'] != 'ignore' or
+ act.ah['deb_fortests'] != 'ignore'):
+ build_needed('binaries')
+
+ result_pwd_af = InputDir(what+'-treeforcontrol',
+ result_pwd, True)
+ stanzas = read_control(act, result_pwd_af, control_override)
+ for stanza in stanzas:
+ for t in stanza[' tests']:
+ if 'no-build-needed' not in t.feature_names:
+ build_needed('test %s' % t.tname)
+ for d in t.depends:
+ if '@' in d:
+ build_needed('test %s '
+ 'dependency %s' % (t.tname,d))
+
+ debug_b('build not needed')
+ built = False
+
+ except NeedBuildException:
+
+ 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)
+
+ script = tmpdir_script + [
+ 'cd "$2"',
+ 'dpkg-checkbuilddeps',
+ opts.user_wrap('debian/rules build'),
+ ]
+ source_rules_command(act,script,what,'build',work,
+ cwd=initcwd, xargs=['x',tmpdir,result_pwd])
+
+ if os.path.dirname(result_pwd)+'/' != work.read(True):
+ badpkg("results dir `%s' is not in expected parent"
+ " dir `%s'" % (result_pwd, work.read(True)))
+
+ built = True