]> rtime.felk.cvut.cz Git - linux-conf-perf.git/blobdiff - scripts/initialize.py
Rewrite configuration script
[linux-conf-perf.git] / scripts / initialize.py
old mode 100644 (file)
new mode 100755 (executable)
index 951834a..f48156d
@@ -1,50 +1,96 @@
+#!/usr/bin/env python3
 import os
 import sys
 import subprocess
 import shutil
 
 import utils
+import database
 from conf import conf
-from exceptions import MissingFile
+from conf import sf
+import exceptions
+import loop
 
-def kconfig_parser():
-       "Execute kconfig_parser 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.kconfig_parser_output:
-               subprocess.call([conf.kconfig_parser, conf.linux_kconfig_head, conf.build_folder, "-v", "-v"], env=env)
+def all():
+       base()
+       parse_kconfig()
+       gen_requred()
+       # check if database is initialized
+       database.database()
+
+def base():
+       print('Initialize base...')
+       try:
+               os.mkdir(sf(conf.build_folder))
+       except FileExistsError:
+               pass
+       try:
+               os.mkdir(sf(conf.configurations_folder))
+       except FileExistsError:
+               pass
+       try:
+               os.mkdir(sf(conf.log_folder))
+       except FileExistsError:
+               pass
+
+       if os.path.isfile(sf(conf.phase_file)):
+               print("Warning: file " + conf.phase_file + " already exists. Not overwritten.")
+       else:
+               loop.phase_set(1)
+
+       if os.path.isfile(sf(conf.iteration_file)):
+               print("Warning: file " + conf.iteration_file + " already exists. Not overwritten.")
        else:
-               subprocess.call([conf.kconfig_parser, conf.linux_kconfig_head, conf.build_folder], env=env)
+               loop.iteration_reset()
 
+
+def parse_kconfig():
+       "Execute parse_kconfig in linux_sources directory."
+       if os.path.isfile(sf(conf.symbol_map_file)) and \
+                       os.path.isfile(sf(conf.rules_file)) and \
+                       os.path.isfile(sf(conf.variable_count_file)):
+               print('Warning: parse_kconfig not executed. Files already exists.')
+               return
+       print('Executing parse_kconfig...')
+       env = dict(os.environ)
+       wd = os.getcwd()
+       os.chdir(sf(conf.linux_sources))
+       parse_kconfig_cmd = [sf(conf.parse_kconfig)]
+       parse_kconfig_cmd += [sf(conf.linux_kconfig_head), sf(conf.build_folder)]
+       parse_kconfig_cmd += ['-v', '-v']
+       utils.callsubprocess("parse_kconfig", parse_kconfig_cmd,
+                       conf.parse_kconfig_output, env=utils.get_kernel_env())
        os.chdir(wd)
 
+
 def gen_requred():
-       "Generates required depenpency from required file."
-       utils.build_symbol_map()
-       srmap = {value:key for key, value in utils.smap.items()}
+       "Generates required depenpency from dot_config file."
+       print('Generating required configuration...')
 
-       try:
-               os.remove(conf.required_file)
-               os.remove(conf.dot_config_file)
-       except OSError:
-               pass
+       if not os.path.isfile(sf(conf.dot_config)):
+               raise exceptions.MissingFile(sf(conf.dot_config),
+                               'Generate fixed configuration. Use make dot_config.')
+
+       utils.build_symbol_map() # Ensure smap existence
+       srmap = {value:key for key, value in utils.smap.items()} # swap dictionary
+
+       shutil.copy(sf(conf.dot_config), sf(conf.dot_config_back_file))
+
+       with open(sf(conf.dot_config), 'r') as f:
+               with open(sf(conf.required_file), 'w') as freq:
+                       for line in f:
+                               if (line[0] == '#') or (not '=' in line):
+                                       continue
+                               indx = line.index('=')
+                               if (line[indx + 1] == 'y'):
+                                       if line[7:indx] == "MODULES": # exception if modules set
+                                               raise exceptions.ConfigurationError("Fixed kernel configuration must have MODULES disabled.")
+                                       freq.write(str(srmap[line[7:indx]]) + "\n")
+                               elif (line[indx + 1] == 'n' or line[indx + 1] == 'm'):
+                                       freq.write("-" + str(srmap[line[7:indx]]) + "\n")
+
+
+#################################################################################
 
-       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);
+if __name__ == '__main__':
+       all()