aboutsummaryrefslogtreecommitdiff
path: root/scripts/initialize.py
blob: 191d8d1f8be56ae36497c94a5573d8184d273e7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import sys
import subprocess
import shutil

import utils
from conf import conf
from exceptions import MissingFile

def parse_kconfig():
	"Execute parse_kconfig in linux_sources directory and parsed output is placed to build_folder."
	env = dict(os.environ)
	env['SRCARCH'] = conf.SRCARCH
	env['ARCH'] = conf.ARCH
	env['KERNELVERSION'] = 'KERNELVERSION' # hides error
	wd = os.getcwd()
	os.chdir(conf.linux_sources)
	if conf.parse_kconfig_output:
		subprocess.call([conf.parse_kconfig, conf.linux_kconfig_head, conf.build_folder, "-v", "-v"], env=env)
	else:
		subprocess.call([conf.parse_kconfig, conf.linux_kconfig_head, conf.build_folder], env=env)

	os.chdir(wd)

def gen_requred():
	"Generates required depenpency from required file."

	if not os.path.isfile(conf.linux_sources + '/.config'):
		raise MissingFile(conf.linux_sources + '/.config',
				'Generate initial configuration. Execute make defconfig in linux folder. Or use make menuconfig and change configuration.')

	utils.build_symbol_map() # Ensure smap existence
	srmap = {value:key for key, value in utils.smap.items()}

	try:
		os.remove(conf.required_file)
		os.remove(conf.dot_config_file)
	except OSError:
		pass

	shutil.copy(conf.linux_sources + '/.config', conf.dot_config_back_file)

	with open(conf.linux_sources + '/.config', 'r') as f:
		with open(conf.required_file, 'w') as freq:
			with open(conf.dot_config_fragment_file, 'w') as fconf:
				for line in f:
					if (line[0] == '#') or (not '=' in line):
						continue
					indx = line.index('=')
					if (line[indx + 1] == 'y' or line[indx + 1] == 'm'):
						freq.write(srmap[line[7:indx]] + "\n")
					elif (line[indx + 1] == 'n'):
						freq.write("-" + srmap[line[7:indx]] + "\n")
					else:
						fconf.write(line);