8 from threading import Thread
13 def build_symbol_map():
14 """Generates global variable smap from symbol_map_file.
15 When file not exists, MissingFile exception is raised.
21 # Check if symbol_map_file exist
22 if not os.path.isfile(sf(conf.symbol_map_file)):
23 raise exceptions.MissingFile(sf(conf.symbol_map_file),
24 "Run parse_kconfig to generate it.")
27 with open(sf(conf.symbol_map_file)) as f:
29 w = lnn.rstrip().split(sep=':')
30 smap[int(w[0])] = w[1]
32 class __subprocess_timer__(Thread):
33 def __init__(self, sprc, timeout):
34 Thread.__init__(self, name='subprocess_timer')
36 self.last = time.time()
38 self.timeout = timeout
39 self.timeouted = False
43 self.last = time.time()
48 while not self.exitit:
50 if (now - self.last) >= self.timeout:
52 os.kill(self.sprc.pid, signal.SIGTERM)
56 def callsubprocess(process_name, process, show_output = True,
57 return_output = False, env=os.environ, allowed_exit_codes = [0],
58 allow_all_exit_codes = False, stdin = None, timeout = -1):
59 sprc = subprocess.Popen(process, stdout = subprocess.PIPE,
60 stderr = subprocess.STDOUT, stdin = subprocess.PIPE, env = env)
64 os.mkdir(os.path.join(sf(conf.log_folder), process_name))
70 sprc.stdin.write(bytes(ln + '\n', sys.getdefaultencoding()))
75 timerout = __subprocess_timer__(sprc, timeout)
76 with open(os.path.join(sf(conf.log_folder),
77 process_name, time.strftime("%y-%m-%d-%H-%M-%S") + ".log"),
79 f.write('::' + time.strftime("%y-%m-%d-%H-%M-%S-%f") + '::\n')
80 for linen in sprc.stdout:
82 line = linen.decode(sys.getdefaultencoding())
87 rtn.append(line.rstrip())
89 raise exceptions.ProcessTimeout(process_name, rtn)
91 if rtncode not in allowed_exit_codes and not allow_all_exit_codes:
92 raise exceptions.ProcessFailed(process, rtncode, rtn)
96 env = dict(os.environ)
97 env.update(conf.kernel_env)
100 def __dirty_repo__(path):
102 os.chdir(conf.absroot)
103 out = subprocess.check_output(conf.git_describe_cmd)
104 if re.search('dirty', out.decode(sys.getdefaultencoding())):
105 raise exceptions.DirtyRepository(path)
108 __dirty_repo__(conf.absroot)
109 __dirty_repo__(conf.linux_sources)