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 print("Running: " + " ".join(process))
60 sprc = subprocess.Popen(process, stdout = subprocess.PIPE,
61 stderr = subprocess.STDOUT, stdin = subprocess.PIPE, env = env)
65 os.mkdir(os.path.join(sf(conf.log_folder), process_name))
71 sprc.stdin.write(bytes(ln + '\n', sys.getdefaultencoding()))
76 timerout = __subprocess_timer__(sprc, timeout)
77 with open(os.path.join(sf(conf.log_folder),
78 process_name, time.strftime("%y-%m-%d-%H-%M-%S") + ".log"),
80 f.write('::' + time.strftime("%y-%m-%d-%H-%M-%S-%f") + '::\n')
81 for linen in sprc.stdout:
84 line = linen.decode(sys.getdefaultencoding())
89 rtn.append(line.rstrip())
90 except UnicodeDecodeError:
92 rtn.append('DecodeError')
94 raise exceptions.ProcessTimeout(process_name, rtn)
96 if rtncode not in allowed_exit_codes and not allow_all_exit_codes:
97 raise exceptions.ProcessFailed(process, rtncode, rtn)
100 def get_kernel_env():
101 env = dict(os.environ)
102 env.update(conf.kernel_env)
105 def __dirty_repo__(path):
107 os.chdir(conf.absroot)
108 out = subprocess.check_output(conf.git_describe_cmd)
109 if re.search('dirty', out.decode(sys.getdefaultencoding())):
110 raise exceptions.DirtyRepository(path)
113 __dirty_repo__(conf.absroot)
114 __dirty_repo__(conf.linux_sources)