Source code for libka.acctest_noinline

#!/usr/bin/python3
# -*- coding: utf-8 -*-
# kate: space-indent on; indent-width 4; replace-tabs on; indent-mode python; remove-trailing-space modified;
# vim: expandtab ts=4

############################################################################
#   Copyright © 2017 José Manuel Santamaría Lema <panfaust@gmail.com>      #
#                                                                          #
#   This program is free software; you can redistribute it and/or modify   #
#   it under the terms of the GNU General Public License as published by   #
#   the Free Software Foundation; either version 2 of the License, or      #
#   (at your option) any later version.                                    #
############################################################################

#Handle Crtl+C
import signal
from libka.ka_print import *
[docs] def signal_handler(signal, frame): ka_print_plain('Aborted by user request') sys.exit(130) #http://www.tldp.org/LDP/abs/html/exitcodes.html
signal.signal(signal.SIGINT, signal_handler) import xml.etree.ElementTree import glob #Return values: # 0 - sucess # 1 - already found -fno-keep-inline-functions # 2 - error
[docs] def acc_test_add_no_keep_inline(): acc_test_files = glob.glob("debian/*.acc.in") if len(acc_test_files) == 0: ka_print_info("No *.acc.in files found, skipping package.") return 2 no_keep_inline_found = 0 for file_name in acc_test_files: try: et = xml.etree.ElementTree.parse(file_name) except Exception as e: ka_print_error("Error parsing the acc test xml file: " + str(e)) return 2 root = et.getroot() must_write = False gcc_options_found = False for el in root: if el.tag == 'gcc_options': gcc_options_found = True gcc_options = el.text.split() if '-fno-keep-inline-functions' in gcc_options: no_keep_inline_found += 1 else: gcc_options += ["-fno-keep-inline-functions"] el.text = "\n" for gcc_option in gcc_options: el.text += " " + gcc_option + "\n" must_write = True break if not gcc_options_found: el = xml.etree.ElementTree.SubElement(root,'gcc_options') el.text = "\n -fno-keep-inline-functions\n" must_write = True if must_write: et.write(file_name,xml_declaration=True,encoding='utf-8') if len(acc_test_files) == no_keep_inline_found: return 1 else: return 0
if __name__ == "__main__": import argparse import sys import subprocess from git import Repo from libka.ka_print import * parser = argparse.ArgumentParser(description="This program changes the packaging in your CWD " "making sure '-fno-keep-inline-functions' is passed to GCC when running the acc autopkgtest") parser.add_argument("-c","--commit", action="store_true", help="Commit the changes to git if any.") args = parser.parse_args() ret_val = acc_test_add_no_keep_inline() if ret_val == 1: ka_print_warning("This package already has '-fno-keep-inline-functions' in its acc test.") sys.exit(0) elif ret_val != 0: sys.exit(0) subprocess.check_call(['dch',"Pass '-fno-keep-inline-functions' to gcc in the acc test " "in order to avoid possible spurious test failures."]) if args.commit and (ret_val == 0): try: repo = Repo(".") except: ka_print_error("Couldn't open git repository") sys.exit(1) repo_diff = repo.index.diff(None) if len(repo_diff) > 0: repo.index.add([diff.a_blob.path for diff in repo_diff]) repo.index.commit("NOCI\nPass '-fno-keep-inline-functions' to gcc in the acc test") ka_print_good_stuff("Package updated to pass '-fno-keep-inline-functions' to gcc in the acc test")