Belle II Software  release-05-01-25
manipulate_SConstruct.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 import sys
5 from basf2 import find_file
6 sconstruct_path = find_file('site_scons/SConstruct')
7 # sconstruct_path = '../site_scons/SConstruct'
8 
9 fobj = open(sconstruct_path, 'r')
10 
11 optionlist = [' global_env.Append(CCFLAGS = [\'-Wextra\'])\n',
12  ' global_env.Append(CCFLAGS = [\'-Wextra\',\'-O3\'])\n',
13  ' global_env.Append(CCFLAGS = [\'-Wextra\',\'-O3\', \'-native\'])\n'
14  ]
15 option = optionlist[int(sys.argv[1])]
16 a = False
17 output = []
18 input_data = []
19 for line in fobj:
20  input_data.append(line)
21 for i in range(0, len(input_data)):
22  if input_data[i].startswith('elif option == \'opt\':'):
23  a = True
24  print('line found')
25  if a:
26  if input_data[i].startswith(' global_env.Append(CCFLAGS'):
27  output.append(option)
28  a = False
29  print('option changed')
30  else:
31  output.append(input_data[i])
32  else:
33  output.append(input_data[i])
34 fobj.close()
35 fobj = open(sconstruct_path, 'w')
36 for i in output:
37  fobj.write(i)