Skip to content

Commit 8eaee3b

Browse files
Wei Liuacrnsi
authored andcommitted
acrn-config: add "enable_commit" parameter for config tool
Config tool will generate files for board/scenaro/launch, some files are part of souce code for specify board. Git add/commit these files should be one optional of user experience. Add "--enable_commit" parameter to enable git add/commit. usage: --enable_commit: flag of whether to do git commit the config file changes to current git branch. Do commit with this flag and not do without the flag. Tracked-On: #3834 Signed-off-by: Wei Liu <weix.w.liu@intel.com> Acked-by: Victor Sun <victor.sun@intel.com>
1 parent 780a53a commit 8eaee3b

File tree

5 files changed

+76
-35
lines changed

5 files changed

+76
-35
lines changed

misc/acrn-config/board_config/board_cfg_gen.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def main(args):
3131
config_srcs = []
3232
config_dirs = []
3333

34-
(err_dic, board_info_file, scenario_info_file) = board_cfg_lib.get_param(args)
34+
(err_dic, board_info_file, scenario_info_file, enable_commit) = board_cfg_lib.get_param(args)
3535
if err_dic:
3636
return err_dic
3737

@@ -104,22 +104,29 @@ def main(args):
104104
if err_dic:
105105
return err_dic
106106

107+
config_str = 'Config files'
108+
gen_str = 'generated'
107109
# move changes to patch, and apply to the source code
108-
err_dic = board_cfg_lib.gen_patch(config_srcs, board)
110+
if enable_commit:
111+
err_dic = board_cfg_lib.gen_patch(config_srcs, board)
112+
config_str = 'Config patch'
113+
gen_str = 'committed'
109114

110115
if board not in board_cfg_lib.BOARD_NAMES and not err_dic:
111-
print("Config patch for NEW board {} is committed successfully!".format(board))
116+
print("{} for NEW board {} is {} successfully!".format(config_str, board, gen_str))
112117
elif not err_dic:
113-
print("Config patch for {} is committed successfully!".format(board))
118+
print("{} for {} is {} successfully!".format(config_str, board, gen_str))
114119
else:
115-
print("Config patch for {} is failed".format(board))
120+
print("{} for {} is failed".format(config_str, board))
116121

117122
return err_dic
118123

119124

120-
def ui_entry_api(board_info,scenario_info):
125+
def ui_entry_api(board_info,scenario_info, enable_commit=False):
121126

122127
arg_list = ['board_cfg_gen.py', '--board', board_info, '--scenario', scenario_info]
128+
if enable_commit:
129+
arg_list.append('--enable_commit')
123130

124131
err_dic = board_cfg_lib.prepare()
125132
if err_dic:

misc/acrn-config/launch_config/launch_cfg_gen.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,15 @@ def validate_launch_setting(board_info, scenario_info, launch_info):
8181
return (launch_cfg_lib.ERR_LIST, pt_sel, dm)
8282

8383

84-
def ui_entry_api(board_info, scenario_info, launch_info):
84+
def ui_entry_api(board_info, scenario_info, launch_info, enable_commit=False):
8585

8686
err_dic = {}
87+
8788
arg_list = ['board_cfg_gen.py', '--board', board_info, '--scenario', scenario_info, '--launch', launch_info, '--uosid', '0']
8889

90+
if enable_commit:
91+
arg_list.append('--enable_commit')
92+
8993
err_dic = launch_cfg_lib.prepare()
9094
if err_dic:
9195
return err_dic
@@ -139,7 +143,7 @@ def main(args):
139143
config_srcs = []
140144

141145
# get parameters
142-
(err_dic, board_info_file, scenario_info_file, launch_info_file, vm_th) = launch_cfg_lib.get_param(args)
146+
(err_dic, board_info_file, scenario_info_file, launch_info_file, vm_th, enable_commit) = launch_cfg_lib.get_param(args)
143147
if err_dic:
144148
return err_dic
145149
# vm_th =[0..post_vm_max]
@@ -208,12 +212,18 @@ def main(args):
208212

209213
commit_msg = "launch_uos_id{}.sh".format(launch_vm_count)
210214

215+
config_str = 'Config files'
216+
gen_str = 'generated'
211217
# move changes to patch, and apply to the source code
212-
err_dic = launch_cfg_lib.gen_patch(config_srcs, commit_msg)
218+
if enable_commit:
219+
err_dic = launch_cfg_lib.gen_patch(config_srcs, commit_msg)
220+
config_str = 'Config patch'
221+
gen_str = 'committed'
222+
213223
if not err_dic:
214-
print("Config patch for {} is committed successfully!".format(commit_msg))
224+
print("{} for {} is {} successfully!".format(config_str, commit_msg, gen_str))
215225
else:
216-
print("Config patch for {} is failed".format(commit_msg))
226+
print("{} for {} is failed".format(config_str, commit_msg))
217227

218228
return err_dic
219229

misc/acrn-config/library/common.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ def print_if_red(msg, err=False):
5858
def usage(file_name):
5959
""" This is usage for how to use this tool """
6060
print("usage= {} [h] ".format(file_name), end="")
61-
print("--board <board_info_file> --scenario <scenario_info_file>")
61+
print("--board <board_info_file> --scenario <scenario_info_file> [--enable_commit]")
6262
print('board_info_file : file name of the board info')
6363
print('scenario_info_file : file name of the scenario info')
64+
print('enable_commit: enable the flag that git add/commit the generate files to the code base. without --enable_commit will not commit this source code')
6465

6566

6667
def get_param(args):
@@ -71,34 +72,37 @@ def get_param(args):
7172
err_dic = {}
7273
board_info_file = False
7374
scenario_info_file = False
75+
enable_commit = False
7476

7577
if '--board' not in args or '--scenario' not in args:
7678
usage(args[0])
7779
err_dic['common error: get wrong parameter'] = "wrong usage"
78-
return (err_dic, board_info_file, scenario_info_file)
80+
return (err_dic, board_info_file, scenario_info_file, enable_commit)
7981

8082
args_list = args[1:]
81-
(optlist, args_list) = getopt.getopt(args_list, '', ['board=', 'scenario='])
83+
(optlist, args_list) = getopt.getopt(args_list, '', ['board=', 'scenario=', 'enable_commit'])
8284
for arg_k, arg_v in optlist:
8385
if arg_k == '--board':
8486
board_info_file = arg_v
8587
if arg_k == '--scenario':
8688
scenario_info_file = arg_v
89+
if arg_k == '--enable_commit':
90+
enable_commit = True
8791

8892
if not board_info_file or not scenario_info_file:
8993
usage(args[0])
9094
err_dic['common error: get wrong parameter'] = "wrong usage"
91-
return (err_dic, board_info_file, scenario_info_file)
95+
return (err_dic, board_info_file, scenario_info_file, enable_commit)
9296

9397
if not os.path.exists(board_info_file):
9498
err_dic['common error: get wrong parameter'] = "{} is not exist!".format(board_info_file)
95-
return (err_dic, board_info_file, scenario_info_file)
99+
return (err_dic, board_info_file, scenario_info_file, enable_commit)
96100

97101
if not os.path.exists(scenario_info_file):
98102
err_dic['common error: get wrong parameter'] = "{} is not exist!".format(scenario_info_file)
99-
return (err_dic, board_info_file, scenario_info_file)
103+
return (err_dic, board_info_file, scenario_info_file, enable_commit)
100104

101-
return (err_dic, board_info_file, scenario_info_file)
105+
return (err_dic, board_info_file, scenario_info_file, enable_commit)
102106

103107

104108
def check_env():

misc/acrn-config/library/launch_cfg_lib.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@ def print_red(msg, err=False):
8080
def usage(file_name):
8181
""" This is usage for how to use this tool """
8282
print("usage= {} [h]".format(file_name), end="")
83-
print("--board <board_info_file> --scenario <scenario_info_file> --launch <launch_info_file> --uosid <uosid id>")
83+
print("--board <board_info_file> --scenario <scenario_info_file> --launch <launch_info_file> --uosid <uosid id> [--enable_commit]")
8484
print('board_info_file : file name of the board info')
8585
print('scenario_info_file : file name of the scenario info')
8686
print('launch_info_file : file name of the launch info')
8787
print('uosid : this is the relateive id for post launch vm in scenario info XML:[1..max post launch vm]')
88+
print('enable_commit: enable the flag that git add/commit the generate files to the code base. without --enable_commit will not commit this source code')
8889

8990

9091
def get_param(args):
@@ -97,15 +98,24 @@ def get_param(args):
9798
board_info_file = False
9899
scenario_info_file = False
99100
launch_info_file = False
101+
enable_commit = False
102+
param_list = ['--board', '--scenario', '--launch', '--uosid', '--enable_commit']
100103

101-
if '--board' not in args or '--scenario' not in args or '--launch' not in args or '--uosid' not in args:
102-
usage(args[0])
103-
err_dic['common error: get wrong parameter'] = "wrong usage"
104-
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th))
104+
for arg_str in param_list:
105+
106+
if arg_str == '--enable_commit':
107+
continue
108+
109+
if arg_str not in args:
110+
usage(args[0])
111+
err_dic['common error: get wrong parameter'] = "wrong usage"
112+
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), enable_commit)
105113

106114
args_list = args[1:]
107-
(optlist, args_list) = getopt.getopt(args_list, '', ['board=', 'scenario=', 'launch=', 'uosid='])
115+
(optlist, args_list) = getopt.getopt(args_list, '', ['board=', 'scenario=', 'launch=', 'uosid=', 'enable_commit'])
108116
for arg_k, arg_v in optlist:
117+
if arg_k == '--enable_commit':
118+
enable_commit = True
109119
if arg_k == '--board':
110120
board_info_file = arg_v
111121
if arg_k == '--scenario':
@@ -117,26 +127,26 @@ def get_param(args):
117127
vm_th = arg_v
118128
if not vm_th.isnumeric():
119129
err_dic['common error: get wrong parameter'] = "--uosid should be a number"
120-
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th))
130+
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), enable_commit)
121131

122132
if not board_info_file or not scenario_info_file or not launch_info_file:
123133
usage(args[0])
124134
err_dic['common error: get wrong parameter'] = "wrong usage"
125-
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th))
135+
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), enable_commit)
126136

127137
if not os.path.exists(board_info_file):
128138
err_dic['common error: get wrong parameter'] = "{} is not exist!".format(board_info_file)
129-
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th))
139+
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), enable_commit)
130140

131141
if not os.path.exists(scenario_info_file):
132142
err_dic['common error: get wrong parameter'] = "{} is not exist!".format(scenario_info_file)
133-
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th))
143+
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), enable_commit)
134144

135145
if not os.path.exists(launch_info_file):
136146
err_dic['common error: get wrong parameter'] = "{} is not exist!".format(launch_info_file)
137-
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th))
147+
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), enable_commit)
138148

139-
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th))
149+
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), enable_commit)
140150

141151

142152
def get_scenario_uuid():

misc/acrn-config/scenario_config/scenario_cfg_gen.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def main(args):
7878
err_dic = {}
7979
config_srcs = []
8080

81-
(err_dic, board_info_file, scenario_info_file) = scenario_cfg_lib.get_param(args)
81+
(err_dic, board_info_file, scenario_info_file, enable_commit) = scenario_cfg_lib.get_param(args)
8282
if err_dic:
8383
return err_dic
8484

@@ -127,18 +127,28 @@ def main(args):
127127
with open(pci_config_c, 'w') as config:
128128
pci_dev_c.generate_file(config)
129129

130+
config_str = 'Config files'
131+
gen_str = 'generated'
130132
# move changes to patch, and apply to the source code
131-
err_dic = scenario_cfg_lib.gen_patch(config_srcs, scenario)
133+
if enable_commit:
134+
err_dic = scenario_cfg_lib.gen_patch(config_srcs, scenario)
135+
config_str = 'Config patch'
136+
gen_str = 'committed'
137+
132138
if not err_dic:
133-
print("Config patch for {} is committed successfully!".format(scenario))
139+
print("{} for {} is {} successfully!".format(config_str, scenario, gen_str))
134140
else:
135-
print("Config patch for {} is failed".format(scenario))
141+
print("{} for {} is failed".format(config_str, scenario))
136142

137143
return err_dic
138144

139145

140-
def ui_entry_api(board_info, scenario_info):
146+
def ui_entry_api(board_info, scenario_info, enable_commit=False):
147+
141148
arg_list = ['board_cfg_gen.py', '--board', board_info, '--scenario', scenario_info]
149+
if enable_commit:
150+
arg_list.append('--enable_commit')
151+
142152
err_dic = scenario_cfg_lib.prepare()
143153
if err_dic:
144154
return err_dic

0 commit comments

Comments
 (0)