├── .cm
├── alias-a-module
└── alias-u-e9a4bb5e10b91e40
├── module
├── .cm
│ ├── alias-a-code
│ ├── alias-a-package
│ ├── alias-u-0247b19de472d7d0
│ ├── alias-u-688dee2e7014f1fb
│ ├── alias-a-code.source
│ └── alias-u-45741e3fbcf4024b
├── code.source
│ ├── .cm
│ │ ├── meta.json
│ │ └── info.json
│ └── module.py
├── package
│ ├── .cm
│ │ ├── info.json
│ │ └── meta.json
│ └── module.py
└── code
│ ├── .cm
│ ├── info.json
│ └── meta.json
│ └── module.py
├── README.md
└── .ckr.json
/.cm/alias-a-module:
--------------------------------------------------------------------------------
1 | e9a4bb5e10b91e40
2 |
--------------------------------------------------------------------------------
/.cm/alias-u-e9a4bb5e10b91e40:
--------------------------------------------------------------------------------
1 | module
2 |
--------------------------------------------------------------------------------
/module/.cm/alias-a-code:
--------------------------------------------------------------------------------
1 | 688dee2e7014f1fb
2 |
--------------------------------------------------------------------------------
/module/.cm/alias-a-package:
--------------------------------------------------------------------------------
1 | 0247b19de472d7d0
2 |
--------------------------------------------------------------------------------
/module/.cm/alias-u-0247b19de472d7d0:
--------------------------------------------------------------------------------
1 | package
2 |
--------------------------------------------------------------------------------
/module/.cm/alias-u-688dee2e7014f1fb:
--------------------------------------------------------------------------------
1 | code
2 |
--------------------------------------------------------------------------------
/module/.cm/alias-a-code.source:
--------------------------------------------------------------------------------
1 | 45741e3fbcf4024b
2 |
--------------------------------------------------------------------------------
/module/.cm/alias-u-45741e3fbcf4024b:
--------------------------------------------------------------------------------
1 | code.source
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ctuning-modules
2 | ===============
3 |
4 | cTuning modules
5 |
--------------------------------------------------------------------------------
/.ckr.json:
--------------------------------------------------------------------------------
1 | {
2 | "data_uid": "51d5e6084333ae86",
3 | "data_name": "cTuning modules",
4 | "dict": {},
5 | "data_alias": "ctuning-modules",
6 | "data_uoa": "ctuning-modules"
7 | }
--------------------------------------------------------------------------------
/module/code.source/.cm/meta.json:
--------------------------------------------------------------------------------
1 | {
2 | "license": "See CK LICENSE.txt for licensing details",
3 | "developer": "Grigori Fursin",
4 | "copyright": "See CK Copyright.txt for copyright details",
5 | "actions": {},
6 | "desc": "cTuning benchmark"
7 | }
--------------------------------------------------------------------------------
/module/code.source/.cm/info.json:
--------------------------------------------------------------------------------
1 | {
2 | "control": {
3 | "engine": "CK",
4 | "version": [
5 | "0",
6 | "1",
7 | "140810",
8 | "beta"
9 | ],
10 | "iso_datetime": "2014-11-17T15:59:48.532000"
11 | },
12 | "backup_module_uoa": "module",
13 | "data_name": "code.source",
14 | "backup_module_uid": "e9a4bb5e10b91e40"
15 | }
--------------------------------------------------------------------------------
/module/code.source/module.py:
--------------------------------------------------------------------------------
1 | #
2 | # Collective Knowledge (cTuning benchmark)
3 | #
4 | # See CK LICENSE.txt for licensing details
5 | # See CK Copyright.txt for copyright details
6 | #
7 | # Developer: Grigori Fursin
8 | #
9 |
10 | cfg={} # Will be updated by CK (meta description of this module)
11 | work={} # Will be updated by CK (temporal data)
12 | ck=None # Will be updated by CK (initialized CK kernel)
13 |
14 | # Local settings
15 |
16 | ##############################################################################
17 | # Initialize module
18 |
19 | def init(i):
20 | """
21 |
22 | Input: {}
23 |
24 | Output: {
25 | return - return code = 0, if successful
26 | > 0, if error
27 | (error) - error text if return > 0
28 | }
29 |
30 | """
31 | return {'return':0}
32 |
--------------------------------------------------------------------------------
/module/package/.cm/info.json:
--------------------------------------------------------------------------------
1 | {
2 | "control": {
3 | "engine": "CM",
4 | "copyright": "See CK Copyright.txt for copyright details",
5 | "license": "See CK LICENSE.txt for licensing details",
6 | "author": "Grigori Fursin",
7 | "author_email": "Grigori.Fursin@cTuning.org",
8 | "author_uoa": "0728a400aa1c86fe",
9 | "version": [],
10 | "author_webpage": "http://cTuning.org/lab/people/gfursin",
11 | "iso_datetime": "2012-04-13T17:11:05.931000"
12 | },
13 | "description": "cM packages",
14 | "backup_module_uid": "e9a4bb5e10b91e40",
15 | "cm_outdated": {
16 | "cm_access_control": {
17 | "read_groups": "all",
18 | "comments_groups": "admin",
19 | "write_groups": "admin"
20 | },
21 | "powered_by": {
22 | "version": "1.0.1977.beta",
23 | "name": "Collective Mind Engine"
24 | }
25 | },
26 | "data_name": "package",
27 | "backup_module_uoa": "module"
28 | }
--------------------------------------------------------------------------------
/module/code/.cm/info.json:
--------------------------------------------------------------------------------
1 | {
2 | "control": {
3 | "engine": "CM",
4 | "copyright": "See CK Copyright.txt for copyright details",
5 | "license": "See CK LICENSE.txt for licensing details",
6 | "author": "Grigori Fursin",
7 | "author_email": "Grigori.Fursin@cTuning.org",
8 | "author_uoa": "0728a400aa1c86fe",
9 | "version": [],
10 | "author_webpage": "http://cTuning.org/lab/people/gfursin",
11 | "iso_datetime": "2012-04-06T21:42:01.204000"
12 | },
13 | "description": "any binary code or scripts",
14 | "backup_module_uid": "e9a4bb5e10b91e40",
15 | "cm_outdated": {
16 | "powered_by": {
17 | "version": "1.0.1977.beta",
18 | "name": "Collective Mind Engine"
19 | },
20 | "cm_access_control": {
21 | "read_groups": "registered",
22 | "comments_groups": "admin",
23 | "write_groups": "admin"
24 | }
25 | },
26 | "data_name": "code",
27 | "backup_module_uoa": "module"
28 | }
--------------------------------------------------------------------------------
/module/code/.cm/meta.json:
--------------------------------------------------------------------------------
1 | {
2 | "cm_actions": [
3 | {
4 | "params_default": "",
5 | "params": "",
6 | "cm_index": "change_work_dir",
7 | "func": "change_work_dir",
8 | "desc": "changing working directory to a given code entry"
9 | },
10 | {
11 | "params": "",
12 | "cm_index": "get_env",
13 | "func": "get_env",
14 | "desc": "return environment script for code"
15 | },
16 | {
17 | "params": "",
18 | "cm_index": "install",
19 | "func": "install",
20 | "desc": "install code and prepare environment file"
21 | },
22 | {
23 | "params": "",
24 | "cm_index": "run",
25 | "func": "run",
26 | "desc": "run code (binary)"
27 | },
28 | {
29 | "params": "",
30 | "cm_index": "get_validated_dataset",
31 | "func": "get_validated_datatset",
32 | "desc": "get validated dataset"
33 | },
34 | {
35 | "params": "",
36 | "cm_index": "prepare_env_for_all_codes",
37 | "func": "prepare_env_for_all_codes",
38 | "desc": "prepare environment for all codes"
39 | },
40 | {
41 | "params_default": "",
42 | "params": "",
43 | "cm_index": "prepare_env_vars",
44 | "func": "prepare_env_vars",
45 | "desc": "changing environment variables"
46 | },
47 | {
48 | "params_default": "",
49 | "params": "",
50 | "cm_index": "set_env",
51 | "func": "set_env",
52 | "desc": "setting environment in a pipeline"
53 | },
54 | {
55 | "params": "",
56 | "cm_index": "prepare_cmd",
57 | "func": "prepare_cmd",
58 | "desc": "prepare cmd for the program"
59 | },
60 | {
61 | "params": "",
62 | "cm_index": "native_run",
63 | "func": "native_run",
64 | "desc": "native run with timing"
65 | }
66 | ],
67 | "license": "cM 1.x license",
68 | "calming_delay": "1",
69 | "cm_module_py_dir": "",
70 | "cm_modules": {
71 | "os.script": "d91afa2830ddcbac",
72 | "class": "58014c9c91d6d101",
73 | "dataset": "8a7141c59cd335f5",
74 | "os": "b9735a270ba455c3",
75 | "processor": "41a0bd4f09be3d16",
76 | "cm-core": "9ac54cef3d7caa8a"
77 | },
78 | "cm_env_prefix": "cm_code_env_",
79 | "cm_data_description": {},
80 | "cm_batch_script_ext": "tmp-cm-run-",
81 | "authors": [
82 | "0728a400aa1c86fe"
83 | ],
84 | "url_module": "",
85 | "cm_module_py_ext": "module",
86 | "cm_common_actions": []
87 | }
--------------------------------------------------------------------------------
/module/package/.cm/meta.json:
--------------------------------------------------------------------------------
1 | {
2 | "install_script_py_prefix": "python",
3 | "obj_dir": "obj",
4 | "install_dir": "install",
5 | "install_script": "install",
6 | "minimal_setup_for_download": "yes",
7 | "cm_common_actions": [],
8 | "license": "cM 1.x license",
9 | "cm_module_py_dir": "",
10 | "cm_modules": {
11 | "ctuning.setup": "b8a7418f9c701002",
12 | "code": "688dee2e7014f1fb",
13 | "ctuning.scenario": "aaa8e4766b0351e8",
14 | "system": "c0977f94653a6a1c",
15 | "code.source": "45741e3fbcf4024b",
16 | "cm-core": "9ac54cef3d7caa8a",
17 | "cm-web": "f0d8604c7abf6aee",
18 | "os": "b9735a270ba455c3",
19 | "class": "58014c9c91d6d101",
20 | "processor": "41a0bd4f09be3d16"
21 | },
22 | "dependencies_file": "cm_code_dependencies.txt",
23 | "cm_classes": {
24 | "compiler": "72f81bd39f84ed89"
25 | },
26 | "cm_actions": [
27 | {
28 | "params_default": {},
29 | "params": "",
30 | "cm_index": "install",
31 | "func": "install",
32 | "desc": "install cM package"
33 | },
34 | {
35 | "params_default": {},
36 | "params": "",
37 | "cm_index": "installed",
38 | "func": "installed",
39 | "desc": "view installed packages"
40 | },
41 | {
42 | "params_default": {},
43 | "cm_index": "web_install",
44 | "params": "",
45 | "func": "web_install",
46 | "params_desc": {
47 | "##compilation_type": {
48 | "default_value": "static",
49 | "skip_form_refresh": "yes",
50 | "sort_index": "52",
51 | "desc_text": "Compilation type",
52 | "has_choice": "yes",
53 | "choice": [
54 | "static",
55 | "dynamic"
56 | ],
57 | "type": "text"
58 | },
59 | "##compiler_code_uoa": {
60 | "title_before": "Additional build parameters",
61 | "cm_classes_uoa": [
62 | "72f81bd39f84ed89"
63 | ],
64 | "start_new_column": "yes",
65 | "force_select_first": "yes",
66 | "sort_index": "40",
67 | "desc_text": "Compiler",
68 | "cm_class_dependencies_from_data": {
69 | "##run_target_processor_uoa": {
70 | "cm_module_uoa": "41a0bd4f09be3d16",
71 | "cm_key": "target_processor"
72 | },
73 | "##run_host_os_uoa": {
74 | "cm_module_uoa": "b9735a270ba455c3",
75 | "cm_key": "host_os"
76 | },
77 | "##build_target_os_uoa": {
78 | "cm_module_uoa": "b9735a270ba455c3",
79 | "cm_key": "target_os"
80 | }
81 | },
82 | "cm_module_uoa": "688dee2e7014f1fb",
83 | "type": "uoa"
84 | },
85 | "##number_of_parallel_jobs_for_build": {
86 | "default_value": "1",
87 | "sort_index": "80",
88 | "desc_text": "Number of parallel jobs for build (if supported)",
89 | "has_choice": "yes",
90 | "choice": [
91 | "1",
92 | "2",
93 | "3",
94 | "4",
95 | "5",
96 | "6",
97 | "7",
98 | "8"
99 | ],
100 | "type": "integer"
101 | },
102 | "##keep_all_files": {
103 | "default_value": "no",
104 | "sort_index": "83",
105 | "desc_text": "Keep all produced files",
106 | "has_choice": "yes",
107 | "choice": [
108 | "yes",
109 | "no"
110 | ],
111 | "type": "text"
112 | },
113 | "##package_host_os_uoa": {
114 | "data_from_other_data": {
115 | "cm_sub_key": "##cm_choices#cm_host_os_uoa",
116 | "cm_module_uoa": "b8a7418f9c701002",
117 | "cm_key": "##ctuning_setup_uoa"
118 | },
119 | "force_select_first": "yes",
120 | "sort_index": "5",
121 | "desc_text": "Host OS",
122 | "cm_module_uoa": "b9735a270ba455c3",
123 | "type": "uoa"
124 | },
125 | "##run_target_processor_uoa": {
126 | "data_from_other_data": {
127 | "cm_sub_key": "##cm_choices#run_target_processor_uoa",
128 | "cm_module_uoa": "b8a7418f9c701002",
129 | "cm_key": "##ctuning_setup_uoa"
130 | },
131 | "force_select_first": "yes",
132 | "sort_index": "15",
133 | "desc_text": "Target processor",
134 | "cm_module_uoa": "41a0bd4f09be3d16",
135 | "type": "uoa"
136 | },
137 | "##build_target_os_uoa": {
138 | "data_from_other_data": {
139 | "cm_sub_key": "##cm_choices#cm_target_os_uoa",
140 | "cm_module_uoa": "b8a7418f9c701002",
141 | "cm_key": "##ctuning_setup_uoa"
142 | },
143 | "force_select_first": "yes",
144 | "sort_index": "10",
145 | "desc_text": "Target OS",
146 | "cm_module_uoa": "b9735a270ba455c3",
147 | "type": "uoa"
148 | },
149 | "##ctuning_setup_uoa": {
150 | "title_before": "Customize",
151 | "cm_module_uoa": "b8a7418f9c701002",
152 | "type": "uoa",
153 | "desc_text": "collective tuning setup",
154 | "sort_index": "1"
155 | },
156 | "##skip_extract_and_build": {
157 | "default_value": "no",
158 | "title_before": "Misc package parameters",
159 | "sort_index": "70",
160 | "desc_text": "Skip extract and build (refresh mode)",
161 | "has_choice": "yes",
162 | "choice": [
163 | "no",
164 | "yes"
165 | ],
166 | "type": "text"
167 | },
168 | "##package_repo_uoa": {
169 | "default_value": "ctuning-setup",
170 | "cm_module_uoa": "b59ada2b6842a6c8",
171 | "type": "uoa",
172 | "desc_text": "Install repository",
173 | "sort_index": "20"
174 | }
175 | },
176 | "desc": "install/monitor cM packages through web"
177 | }
178 | ],
179 | "cm_class_compiler": "72f81bd39f84ed89",
180 | "install_script_py_ext": ".py",
181 | "cm_data_description": {
182 | "##add_to_code_source": {
183 | "desc_text": "add following parameters to the installation code entry",
184 | "type": "dict",
185 | "dict_type": "free"
186 | },
187 | "##authors": {
188 | "type_next": "values",
189 | "desc_text": "authors",
190 | "sort_index": "5",
191 | "type": "list",
192 | "skip_next_desc": "yes"
193 | },
194 | "##title": {
195 | "desc_text": "package title",
196 | "type": "text",
197 | "sort_index": "1"
198 | },
199 | "##date_released": {
200 | "desc_text": "Date when released (ISO)",
201 | "type": "iso_datetime",
202 | "sort_index": "14"
203 | },
204 | "##url": {
205 | "desc_text": "package URL",
206 | "type": "url",
207 | "sort_index": "10"
208 | },
209 | "##license": {
210 | "default_value": "cM 1.x license",
211 | "desc_text": "package license",
212 | "type": "textarea",
213 | "sort_index": "15"
214 | },
215 | "##date_development_started": {
216 | "desc_text": "Date when development started (ISO)",
217 | "type": "iso_datetime",
218 | "sort_index": "12"
219 | },
220 | "##build": {
221 | "default_value": "no",
222 | "sort_index": "20",
223 | "desc_text": "build package?",
224 | "has_choice": "yes",
225 | "choice": [
226 | "no",
227 | "yes"
228 | ],
229 | "type": "text"
230 | },
231 | "##date_development_finished": {
232 | "desc_text": "Date when development finished (ISO)",
233 | "type": "iso_datetime",
234 | "sort_index": "13"
235 | },
236 | "##install_script": {
237 | "desc_text": "filename of install script (without extension); leave empty if no script",
238 | "type": "text",
239 | "sort_index": "25"
240 | },
241 | "##authors@$": {
242 | "cm_module_uoa": "b0743a4044480ead",
243 | "type": "uoa"
244 | }
245 | },
246 | "authors": [
247 | "0728a400aa1c86fe"
248 | ],
249 | "url_module": "",
250 | "cm_module_py_ext": "module",
251 | "source_classes_to_install": [
252 | "914178a17c102fb5",
253 | "7834e958464669af"
254 | ]
255 | }
--------------------------------------------------------------------------------
/module/code/module.py:
--------------------------------------------------------------------------------
1 | #
2 | # Collective Mind
3 | #
4 | # See cM LICENSE.txt for licensing details.
5 | # See cM Copyright.txt for copyright details.
6 | #
7 | # Developer(s): (C) Grigori Fursin, started on 2011.09
8 | #
9 |
10 | # Should always be here
11 | ini={}
12 | cm_kernel=None
13 |
14 | # Local settings
15 | import os
16 | import sys
17 | import time
18 | import json
19 | import copy
20 |
21 | # ============================================================================
22 | def init(i):
23 | return {'cm_return':0}
24 |
25 | # ============================================================================
26 | def change_work_dir(i):
27 |
28 | """
29 | Chaning working directory
30 |
31 | Input: {
32 | (work_dir) - change to this working directory before running code
33 | or
34 | (work_dir_repo_uoa) - change to the working directory in the repository (repo UOA)
35 | (work_dir_module_uoa) - change to the working directory in the repository (module UOA)
36 | (work_dir_data_uoa) - change to the working directory in the repository (data UOA)
37 | }
38 |
39 | Output: {
40 | cm_return - if =0, success
41 | work_dir - selected working directory
42 | }
43 | """
44 |
45 | # Changing to working directory
46 | sys.stdout.flush()
47 | work_dir=''
48 | if 'work_dir' in i: work_dir=i['work_dir']
49 | elif ('work_dir_module_uoa' in i and 'work_dir_data_uoa' in i):
50 | # Change path to another directory
51 | ii={'cm_run_module_uoa':i['work_dir_module_uoa'],
52 | 'cm_action':'load',
53 | 'cm_data_uoa':i['work_dir_data_uoa']}
54 | if 'work_dir_repo_uoa' in i: ii['cm_repo_uoa']=i['work_dir_repo_uoa']
55 | r=cm_kernel.access(ii)
56 | if r['cm_return']>0: return r
57 | work_dir=r['cm_path']
58 |
59 | if work_dir!='':
60 | cm_kernel.print_for_con('')
61 | cm_kernel.print_for_con('Changing path to '+work_dir+' ...')
62 | os.chdir(work_dir)
63 |
64 | return {'cm_return':0, 'work_dir':work_dir}
65 |
66 | # ============================================================================
67 | def get_env(i):
68 |
69 | """
70 | cM web index
71 |
72 | Input: {
73 | cm_data_uoa - code UOA to prepare environment script name
74 | os_uoa - OS configuration to prepare extension
75 | }
76 |
77 | Output: {
78 | cm_return - return code >0 if error
79 | }
80 | """
81 |
82 | if 'os_uoa' not in i or i['os_uoa']=='':
83 | return {'cm_return':1, 'cm_error': '"os_uoa" is not defined for "get_env" in "code" module'}
84 |
85 | # Load OS
86 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['os'],
87 | 'cm_action':'load',
88 | 'cm_data_uoa':i['os_uoa']}
89 | r=cm_kernel.access(ii)
90 | if r['cm_return']>0: return r
91 |
92 | os_cfg=r['cm_data_obj']['cfg']
93 |
94 | # Prepare script
95 | s=ini['cfg']['cm_env_prefix']+i['cm_data_uoa']+os_cfg['script_ext']
96 |
97 | return {'cm_return':0, 'cm_string':s}
98 |
99 | # ============================================================================
100 | def run(i):
101 |
102 | """
103 | Run code (binary or script)
104 |
105 | Input: {
106 | (run_host_os_uoa) - host OS UOA (if not set, use default OS from kernel)
107 | (run_target_os_uoa) - target OS UOA (if not set, use run_host_uoa_os)
108 |
109 | (run_target_processor_uoa) - target processor UOA (not strictly needed - can add some helper parameters before executing code)
110 |
111 | --------------------------------------------------------------------------------------------
112 | run_cmd_key - if !='', set all further run parameters (including target name)
113 | from the work_dir_data_uoa (must be set)
114 | (dataset_uoa) - use dataset to update cmd params from above
115 | or
116 | run_cmd - command line to run
117 | or
118 | run_script - use the following script (add extension from run_target_os)
119 | run_script_uoa - take script from this entry in os.script (add extension from run_target_os)
120 | or
121 | (run_cmd1) - following format: run_cmd1 run_cmd_name|binary_name run_cmd2 run_cmd_main run_cmd3 > run_cmd_out1 2> run_cmd_out2
122 | (run_cmd_name)
123 | (run_cmd2)
124 | (run_cmd_main) or (binary_name)
125 | (run_cmd3)
126 | (run_cmd_out1)
127 | (run_cmd_out2)
128 | --------------------------------------------------------------------------------------------
129 |
130 | (work_dir) - change to this working directory before running code
131 | or
132 | (work_dir_repo_uoa) - change to the working directory in the repository (repo UOA)
133 | (work_dir_module_uoa) - change to the working directory in the repository (module UOA)
134 | (work_dir_data_uoa) - change to the working directory in the repository (data UOA)
135 |
136 | (run_input_files) - list of files needed to run code (can be copied to the remote host system)
137 | (run_output_files) - list of files that will be created (for validation, etc)
138 |
139 | (code_deps) - list with code UOA for dependencies [{"index":"uoa"} ...]
140 | (skip_code_deps) - if 'yes', skip code deps
141 |
142 | (run_set_env1) - array with environment variables to be set before code deps
143 | (run_set_env2) - array with environment variables to be set before executable
144 |
145 | (run_commands_before) - run commands before executable
146 | (run_commands_after) - run commands after executable
147 |
148 | (cm_dependencies) - dependencies that set all other dependencies (code/include/lib).
149 | Format [{"class UOA":"code UOA"},{},...]
150 |
151 | (run_timeout) - time out for run (overheads may occur)
152 |
153 | (keep_all_files) - if 'yes', do not remove tmp files and do not clean up remote device
154 | (cm_verbose) - if 'yes', print all info
155 | }
156 |
157 | Output: {
158 | cm_return - return code = 0, if successful
159 |
160 | timed_out - 'yes' if timed out
161 | failed_run - 'yes' if return code !=0 or timed out or binary doesn't exist
162 | run_time_by_module - run time measured by module
163 | exit_code - exit code of the system call
164 | run_cmd - final run cmd
165 | work_dir - work directory
166 | run_output_files - final output files
167 | }
168 | """
169 |
170 | # Check verbose - yes, by default
171 | vrb=i.get('cm_verbose','yes')
172 |
173 | if vrb=='yes':
174 | # cm_kernel.print_for_con('***********************************************')
175 | cm_kernel.print_for_con('Running code ...')
176 |
177 | # Load OS configuration
178 | host_os_uoa=''
179 | if 'run_host_os_uoa' in i and i['run_host_os_uoa']!='': host_os_uoa=i['run_host_os_uoa']
180 | elif 'cm_default_os_uoa' in cm_kernel.ini['dcfg'] and cm_kernel.ini['dcfg']['cm_default_os_uoa']!='':
181 | host_os_uoa=cm_kernel.ini['dcfg']['cm_default_os_uoa']
182 |
183 | if host_os_uoa=='':
184 | return {'cm_return':1, 'cm_error':'"host_os_uoa" is not set and not in kernel'}
185 |
186 | target_os_uoa=''
187 | if 'run_target_os_uoa' in i and i['run_target_os_uoa']!='': target_os_uoa=i['run_target_os_uoa']
188 | elif host_os_uoa!='': target_os_uoa=host_os_uoa
189 |
190 | if vrb=='yes':
191 | sys.stdout.flush()
192 | cm_kernel.print_for_con('')
193 | cm_kernel.print_for_con('Loading host os '+host_os_uoa+' ...')
194 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['os'],
195 | 'cm_action':'load',
196 | 'cm_data_uoa':host_os_uoa}
197 | r=cm_kernel.access(ii)
198 | if r['cm_return']>0: return r
199 |
200 | host_os_cfg=r['cm_data_obj']['cfg']
201 | host_os_path=r['cm_path']
202 | host_os_uid=r['cm_uid']
203 | host_os_alias=r['cm_alias']
204 |
205 | if vrb=='yes':
206 | cm_kernel.print_for_con('')
207 | cm_kernel.print_for_con('Loading target os '+target_os_uoa+' ...')
208 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['os'],
209 | 'cm_action':'load',
210 | 'cm_data_uoa':target_os_uoa}
211 | r=cm_kernel.access(ii)
212 | if r['cm_return']>0: return r
213 |
214 | target_os_cfg=r['cm_data_obj']['cfg']
215 | target_os_path=r['cm_path']
216 | target_os_uid=r['cm_uid']
217 | target_os_alias=r['cm_alias']
218 |
219 | # Dependencies
220 | code_deps=i.get('code_deps',[])
221 |
222 | # Check if code_deps set additional parameters
223 | qq=i.get('cm_dependencies',{})
224 | if len(qq)>0:
225 | if vrb=='yes':
226 | cm_kernel.print_for_con('')
227 | cm_kernel.print_for_con('Updating code dependencies from cm_dependencies ...')
228 |
229 | code_deps1=[]
230 |
231 | for q in i.get('cm_dependencies',{}):
232 | yy=q.keys()[0]
233 | x=q[yy]
234 |
235 | jj={'cm_run_module_uoa':ini['cfg']['cm_modules']['class'],
236 | 'cm_data_uoa':yy,
237 | 'cm_action':'load'}
238 | rj=cm_kernel.access(jj)
239 | if rj['cm_return']>0: return rj
240 |
241 | drj=rj['cm_data_obj']['cfg']
242 |
243 | vcd=drj.get('build_code_deps_var','')
244 | if vcd!='': code_deps1.append({vcd:x})
245 |
246 | for q in code_deps: code_deps1.append(q)
247 |
248 | code_deps=code_deps1
249 |
250 | i['code_deps']=code_deps
251 |
252 | processor_params={}
253 | if 'run_target_processor_uoa' in i and i['run_target_processor_uoa']!='':
254 | if vrb=='yes':
255 | cm_kernel.print_for_con('')
256 | cm_kernel.print_for_con('Loading target processor '+i['run_target_processor_uoa']+' ...')
257 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['processor'],
258 | 'cm_action':'load',
259 | 'cm_data_uoa':i['run_target_processor_uoa']}
260 | r=cm_kernel.access(ii)
261 | if r['cm_return']>0: return r
262 |
263 | target_processor_cfg=r['cm_data_obj']['cfg']
264 | target_processor_path=r['cm_path']
265 | target_processor_uid=r['cm_uid']
266 | target_processor_alias=r['cm_alias']
267 |
268 | if 'family' in target_processor_cfg:
269 | processor_params['CM_PROCESSOR_FAMILY']=target_processor_cfg['family']
270 | if 'architecture' in target_processor_cfg:
271 | processor_params['CM_PROCESSOR_ARCH']=target_processor_cfg['architecture']
272 | if 'bits' in target_processor_cfg:
273 | processor_params['CM_PROCESSOR_BITS']=target_processor_cfg['bits']
274 |
275 | # Changing to working directory
276 | sys.stdout.flush()
277 | work_dir=''
278 | if 'work_dir' in i: work_dir=i['work_dir']
279 | elif ('work_dir_module_uoa' in i and 'work_dir_data_uoa' in i):
280 | # Change path to another directory
281 | ii={'cm_run_module_uoa':i['work_dir_module_uoa'],
282 | 'cm_action':'load',
283 | 'cm_data_uoa':i['work_dir_data_uoa']}
284 | if 'work_dir_repo_uoa' in i: ii['cm_repo_uoa']=i['work_dir_repo_uoa']
285 | r=cm_kernel.access(ii)
286 | if r['cm_return']>0: return r
287 | work_dir=r['cm_path']
288 |
289 | if work_dir!='':
290 | if vrb=='yes':
291 | cm_kernel.print_for_con('')
292 | cm_kernel.print_for_con('Changing path to '+work_dir+' ...')
293 | os.chdir(work_dir)
294 |
295 | e1a={}
296 |
297 | # Check if remote
298 | remote=False
299 | if target_os_cfg.get('remote','')=='yes':
300 | remote=True
301 | files=[]
302 |
303 | # Check vars
304 | run_input_files=i.get('run_input_files',[])
305 |
306 | run_name=''
307 | run_cmd=''
308 |
309 | if i.get('run_script','')!='':
310 | if vrb=='yes':
311 | cm_kernel.print_for_con('')
312 | cm_kernel.print_for_con('Using script '+i['run_script'])
313 |
314 | r=prepare_sub_script({'run_script':i['run_script'],
315 | 'run_script_uoa':i.get('run_script_uoa',''),
316 | 'target_os_cfg':target_os_cfg,
317 | 'run_cmd':i.get('run_cmd',''),
318 | 'run_cmd_out1':i.get('run_cmd_out1',''),
319 | 'run_cmd_out2':i.get('run_cmd_out2','')})
320 | if r['cm_return']>0: return r
321 | run_cmd=r['run_cmd']
322 | elif i.get('run_cmd','')!='':
323 | run_cmd=i['run_cmd']
324 |
325 | if i.get('run_cmd_out1','')!='': run_cmd+=' 1>'+i['run_cmd_out1']
326 | if i.get('run_cmd_out2','')!='': run_cmd+=' 2>'+i['run_cmd_out2']
327 | elif i.get('binary_name','')!='' or i.get('run_cmd_name','')!='' or i.get('run_cmd_key','')!='':
328 | run_time={}
329 |
330 | rcmd=''
331 | if i.get('run_cmd_key','')!='':
332 | r=prepare_cmd({'code_module_uoa':i.get('work_dir_module_uoa',''),
333 | 'code_data_uoa':i.get('work_dir_data_uoa',''),
334 | 'run_cmd_key':i.get('run_cmd_key',''),
335 | 'dataset_uoa':i.get('dataset_uoa',''),
336 | 'os_uoa':target_os_uoa})
337 | if r['cm_return']>0: return r
338 | run_time=r['run_time']
339 | for j in run_time.get('run_input_files',[]):
340 | if j not in run_input_files: run_input_files.append(j)
341 |
342 | run_set_env2=i.get('run_set_env2',{})
343 | if len(run_time.get('run_set_env2',{}))>0: run_set_env2.update(run_time['run_set_env2'])
344 | i['run_set_env2']=run_set_env2
345 |
346 | if run_time.get('run_script','')!='':
347 | if vrb=='yes':
348 | cm_kernel.print_for_con('')
349 | cm_kernel.print_for_con('Using script '+run_time['run_script'])
350 |
351 | ii={'run_script':run_time['run_script'],
352 | 'run_script_uoa':run_time.get('run_script_uoa',''),
353 | 'target_os_cfg':target_os_cfg,
354 | 'run_cmd':i.get('run_cmd',''),
355 | 'run_cmd_out1':i.get('run_cmd_out1',''),
356 | 'run_cmd_out2':i.get('run_cmd_out2','')}
357 | if ii['run_cmd_out1']=='': ii['run_cmd_out1']=run_time.get('run_cmd_out1','')
358 | if ii['run_cmd_out2']=='': ii['run_cmd_out2']=run_time.get('run_cmd_out2','')
359 | r=prepare_sub_script(ii)
360 | if r['cm_return']>0: return r
361 | rcmd=r['run_cmd']
362 |
363 | if i.get('run_cmd1','')!='': run_time['run_cmd1']=i['run_cmd1']
364 | if i.get('binary_name','')!='': run_time['binary_name']=i['binary_name']
365 | elif i.get('run_cmd_name','')!='': run_time['run_cmd_name']=i['run_cmd_name']
366 | if i.get('run_cmd2','')!='': run_time['run_cmd2']=i['run_cmd2']
367 | if i.get('run_cmd_main','')!='': run_time['run_cmd_main']=i['run_cmd_main']
368 | if i.get('run_cmd_out1','')!='': run_time['run_cmd_out1']=i['run_cmd_out1']
369 | if i.get('run_cmd_out2','')!='': run_time['run_cmd_out2']=i['run_cmd_out2']
370 |
371 | if len(run_time.get('run_output_files',[]))>0 and ('run_output_files' not in i or len(i['run_output_files'])==0):
372 | i['run_output_files']=run_time['run_output_files']
373 |
374 | run_cmd=''
375 | run_name=''
376 | if 'run_cmd1' in run_time: run_cmd+=' '+run_time['run_cmd1']
377 | if 'binary_name' in run_time: run_cmd+=' '+run_time['binary_name']; run_name=run_time['binary_name']
378 | elif 'run_cmd_name' in run_time: run_cmd+=' '+run_time['run_cmd_name']; run_name=run_time['run_cmd_name']
379 | if 'run_cmd2' in run_time: run_cmd+=' '+run_time['run_cmd2']
380 | if 'run_cmd_main' in run_time: run_cmd+=' '+run_time['run_cmd_main']
381 | if 'run_cmd_out1' in run_time: run_cmd+=' 1>'+run_time['run_cmd_out1']; i['run_cmd_out1']=run_time['run_cmd_out1']
382 | if 'run_cmd_out2' in run_time: run_cmd+=' 2>'+run_time['run_cmd_out2']; i['run_cmd_out2']=run_time['run_cmd_out2']
383 |
384 | if rcmd!='':
385 | e1a['CM_RUN_CMD1']=run_time.get('run_cmd1','')
386 | e1a['CM_RUN_CMD2']=run_time.get('run_cmd2','')
387 | e1a['CM_RUN_NAME']=run_name
388 | e1a['CM_RUN_CMD_MAIN']=run_time.get('run_cmd_main','')
389 | run_cmd=rcmd
390 |
391 | else:
392 | return {'cm_return':1, 'cm_error':'not enough parameters to run code in "code run"'}
393 |
394 | if vrb=='yes':
395 | cm_kernel.print_for_con('')
396 | cm_kernel.print_for_con('Prepared command line:')
397 | cm_kernel.print_for_con(' '+run_cmd)
398 |
399 | # Check commands after
400 | run_commands_after=[]
401 | if 'run_commands_after' in i: run_commands_after=i['run_commands_after']
402 |
403 | # Check that executable exists
404 | if run_name!='' and not os.path.isfile(run_name):
405 | if vrb=='yes':
406 | cm_kernel.print_for_con('Can\'t find executable '+run_name)
407 | return {'cm_return':0, 'failed_run':'yes'}
408 |
409 | # Prepare environment before code deps
410 | # First, set fixed ones
411 | if 'family' in target_os_cfg: e1a['CM_OS_FAMILY']=target_os_cfg['family']
412 | if 'bits' in target_os_cfg: e1a['CM_OS_BITS']=target_os_cfg['bits']
413 | if 'version' in target_os_cfg: e1a['CM_OS_VERSION']=target_os_cfg['version']
414 | if 'lib_dir' in target_os_cfg: e1a['CM_OS_LIB_DIR']=target_os_cfg['lib_dir']
415 |
416 | if 'run_set_env1' in i: e1a.update(i['run_set_env1'])
417 | e1a.update(processor_params)
418 |
419 | # Prepare script name
420 | script=''
421 | if 'exec_prefix' in target_os_cfg and target_os_cfg['exec_prefix']!='': script+=target_os_cfg['exec_prefix']
422 | script+=ini['cfg']['cm_batch_script_ext']
423 |
424 | r=cm_kernel.gen_uid({})
425 | if r['cm_return']>0: return r
426 | script+=r['cm_uid']
427 |
428 | # Create script *****************************************************************************************
429 | ii={'script_name':script,
430 | 'target_os_uoa':target_os_uoa,
431 | 'set_env1':e1a}
432 | if 'code_deps' in i and i.get('skip_code_deps','')!='yes':
433 | ii['code_deps']=i['code_deps']
434 | if 'run_set_env2' in i and i['run_set_env2']!='': ii['set_env2']=i['run_set_env2']
435 | if 'run_commands_before' in i: ii['run_commands_before']=i['run_commands_before']
436 | if run_cmd!='': ii['run_cmd']=run_cmd
437 | if len(run_commands_after)>0: ii['run_commands_after']=run_commands_after
438 | r=prepare_script(ii)
439 | if r['cm_return']>0: return r
440 | script=r['cm_path']
441 |
442 | # Check if remote
443 | if remote:
444 | fail=False
445 |
446 | if remote and 'remote_init' in target_os_cfg:
447 | sys.stdout.flush()
448 | if vrb=='yes':
449 | cm_kernel.print_for_con('')
450 | cm_kernel.print_for_con('Initializing remote device ...')
451 | p=target_os_cfg['remote_init']; cm_kernel.print_for_con(p); x=os.system(p)
452 | if x!=0: fail=True
453 |
454 | if not fail:
455 | if vrb=='yes':
456 | cm_kernel.print_for_con('')
457 | cm_kernel.print_for_con('Copying files to device ...')
458 | if target_os_cfg.get('no_script_execution','')!='yes': files.append(script)
459 | if run_name!='': files.append(run_name)
460 | if len(run_input_files)>0:
461 | for x in run_input_files:
462 | if x not in files: files.append(x)
463 |
464 | for z in files:
465 | filename=os.path.basename(z)
466 | p=target_os_cfg['remote_push']+' '+host_os_cfg['env_quotes']+z+host_os_cfg['env_quotes']+\
467 | ' '+target_os_cfg['remote_dir']+target_os_cfg['dir_sep']+filename
468 | if vrb=='yes':
469 | cm_kernel.print_for_con(' '+p)
470 | x=os.system(p)
471 | if x!=0:
472 | fail=True
473 | if vrb=='yes':
474 | cm_kernel.print_for_con('')
475 | cm_kernel.print_for_con('Error: Couldn\'t copy all necessary files for a run!')
476 |
477 | if not fail and run_name!='' and 'set_executable' in target_os_cfg:
478 | if vrb=='yes':
479 | cm_kernel.print_for_con('')
480 | cm_kernel.print_for_con('Setting permissions for binary ...')
481 |
482 | filename=run_name
483 | if remote: filename=os.path.basename(run_name)
484 |
485 | p=target_os_cfg['remote_shell']+' '+target_os_cfg['set_executable']+' '+target_os_cfg['remote_dir']+\
486 | target_os_cfg['dir_sep']+filename
487 | if vrb=='yes':
488 | cm_kernel.print_for_con(' '+p)
489 | x=os.system(p)
490 | if x!=0: fail=True
491 |
492 | if target_os_cfg.get('no_script_execution', '')!='yes':
493 | p=target_os_cfg['remote_shell']+' '+target_os_cfg['set_executable']+' '+target_os_cfg['remote_dir']+\
494 | target_os_cfg['dir_sep']+script
495 | if vrb=='yes':
496 | cm_kernel.print_for_con(' '+p)
497 | x=os.system(p)
498 | if x!=0: fail=True
499 |
500 | # Clean output files
501 | if remote:
502 | # if remote and run_cmd_out1/run_cmd_out2 !='', add to run_output_files
503 | # to get them from remote device
504 | if i.get('run_cmd_out1','')!='' or i.get('run_cmd_out2','')!='':
505 | if len(i.get('run_output_files',[]))==0: i['run_output_files']=[]
506 | if i.get('run_cmd_out1','')!='' and i['run_cmd_out1'] not in i['run_output_files']: i['run_output_files'].append(i['run_cmd_out1'])
507 | if i.get('run_cmd_out2','')!='' and i['run_cmd_out2'] not in i['run_output_files']: i['run_output_files'].append(i['run_cmd_out2'])
508 | else:
509 | if i.get('run_cmd_out1','')!='':
510 | try:
511 | os.remove(i['run_cmd_out1'])
512 | except:
513 | pass
514 | if i.get('run_cmd_out2','')!='':
515 | try:
516 | os.remove(i['run_cmd_out2'])
517 | except:
518 | pass
519 |
520 | if 'run_output_files' in i and len(i['run_output_files'])>0:
521 | if vrb=='yes':
522 | sys.stdout.flush()
523 | cm_kernel.print_for_con('')
524 | cm_kernel.print_for_con('Deleting output files ...')
525 | for z in i['run_output_files']:
526 | if vrb=='yes':
527 | cm_kernel.print_for_con(' '+z)
528 |
529 | if remote:
530 | p=target_os_cfg['remote_shell']+' '+target_os_cfg['delete_file']+' '+host_os_cfg['env_quotes']+target_os_cfg['remote_dir']+\
531 | target_os_cfg['dir_sep']+z+host_os_cfg['env_quotes']
532 | if vrb=='yes':
533 | cm_kernel.print_for_con(' '+p)
534 | x=os.system(p)
535 | # Ignore errors
536 | # if x!=0: fail=True
537 |
538 | else:
539 | try:
540 | os.remove(z)
541 | except:
542 | pass
543 |
544 | # Run cmd
545 | cmd=''
546 | if target_os_cfg.get('no_script_execution','')=='yes':
547 | r=cm_kernel.load_array_from_file({'cm_filename':script})
548 | if r['cm_return']>0: return r
549 | a=r['cm_array']
550 | for x in a:
551 | xx=x.strip()
552 | if xx!='' and not xx.startswith(target_os_cfg['rem']):
553 | if cmd!='': cmd+=target_os_cfg['env_separator']+' '
554 | cmd+=xx
555 | else:
556 | # FGG: this was originally, (we used . ./script) but Abdul reported many problems
557 | # on UBUNTU and Debian when running scripts with variable substitution (MILEPOST GCC, for example)
558 | # cmd=target_os_cfg['env_call']+' '+script
559 | if target_os_cfg.get('set_executable','')!='':
560 | cmd=target_os_cfg['set_executable']+' '+script+' '+target_os_cfg['env_separator']+' '+script
561 | else:
562 | # for Windows like
563 | cmd=target_os_cfg['env_call']+' '+script
564 |
565 | if remote:
566 | cmd=target_os_cfg['change_dir']+' '+target_os_cfg['remote_dir']+\
567 | target_os_cfg['env_separator']+' '+cmd
568 | if host_os_cfg.get('env_quotes_if_remote','')!='':
569 | cmdx1=cmd.replace(host_os_cfg['env_quotes_if_remote'], '\\'+host_os_cfg['env_quotes_if_remote'])
570 | cmdx=host_os_cfg['env_quotes_if_remote']+cmdx1+host_os_cfg['env_quotes_if_remote']
571 | else:
572 | cmdx=cmd
573 |
574 | if host_os_cfg.get('env_dollar_if_remote','')=='yes':
575 | cmdx=cmdx.replace('$','\\$')
576 |
577 | cmd=target_os_cfg['remote_shell']+' '+cmdx
578 |
579 | ii={'cmd':cmd}
580 | if 'run_timeout' in i and i['run_timeout']!='': ii['timeout']=i['run_timeout']
581 | r=-1
582 | fail=False
583 |
584 | sys.stdout.flush()
585 | if 'calming_delay' in i:
586 | calming_delay=i['calming_delay']
587 | else:
588 | calming_delay=ini['cfg'].get('calming_delay','')
589 |
590 | if calming_delay!='' and float(calming_delay)!=0:
591 | if vrb=='yes':
592 | cm_kernel.print_for_con('')
593 | cm_kernel.print_for_con('Calming delay: '+calming_delay+' second(s) ...')
594 | time.sleep(float(calming_delay))
595 |
596 | if vrb=='yes':
597 | cm_kernel.print_for_con('')
598 | cm_kernel.print_for_con('Executing script:')
599 | cm_kernel.print_for_con(' '+cmd)
600 |
601 | start_time=time.time()
602 | rx=cm_kernel.system(ii)
603 | t=time.time()-start_time
604 |
605 | sys.stdout.flush()
606 |
607 | ii={'cm_return':0}
608 |
609 | if rx['cm_return']==1: # timeout
610 | ii.update({'timed_out':'yes', 'failed_run':'yes'})
611 | elif rx['cm_return']>0: return rx # Module error
612 | else:
613 | ts="%.3f" % t
614 | rc=rx['cm_return_code']
615 | ii.update({'run_time_by_module':ts, 'exit_code':rc})
616 | if rc!=0: ii.update({'failed_run':'yes'})
617 |
618 | ii['run_cmd']=run_cmd
619 |
620 | # Moving back output files if needed
621 | if remote and 'run_output_files' in i and len(i['run_output_files'])>0:
622 | if vrb=='yes':
623 | sys.stdout.flush()
624 | cm_kernel.print_for_con('')
625 | cm_kernel.print_for_con('Copying output files from remote device ...')
626 | for z in i['run_output_files']:
627 | if vrb=='yes':
628 | cm_kernel.print_for_con(' '+z)
629 |
630 | filename=os.path.basename(z)
631 | p=target_os_cfg['remote_pull']+' '+target_os_cfg['remote_dir']+target_os_cfg['dir_sep']+filename+\
632 | ' '+host_os_cfg['env_quotes']+z+host_os_cfg['env_quotes']
633 | if vrb=='yes':
634 | cm_kernel.print_for_con(' '+p)
635 | x=os.system(p)
636 | if x!=0: fail=True
637 |
638 | # Cleaning up tmp and other files
639 | if i.get('keep_all_files','')!='yes':
640 | if vrb=='yes':
641 | cm_kernel.print_for_con('')
642 | cm_kernel.print_for_con('Cleaning up local files ...')
643 | # clean up script if not from cM
644 |
645 | try:
646 | os.remove(script)
647 | except:
648 | pass
649 |
650 | if remote:
651 | if vrb=='yes':
652 | cm_kernel.print_for_con('')
653 | cm_kernel.print_for_con('Cleaning up files on remote device ...')
654 | # files already exist - add output files if needed
655 | if 'run_output_files' in i and len(i['run_output_files'])>0:
656 | for x in i['run_output_files']:
657 | if x not in files: files.append(x)
658 |
659 | for z in files:
660 | filename=os.path.basename(z)
661 | p=target_os_cfg['remote_shell']+' '+target_os_cfg['delete_file']+' '+host_os_cfg['env_quotes']+target_os_cfg['remote_dir']+\
662 | target_os_cfg['dir_sep']+filename+host_os_cfg['env_quotes']
663 | if vrb=='yes':
664 | cm_kernel.print_for_con(' '+p); x=os.system(p)
665 |
666 | if vrb=='yes':
667 | cm_kernel.print_for_con('')
668 | cm_kernel.print_for_con('Run time (by module): '+ts)
669 |
670 | ii['work_dir']=work_dir
671 | ii['run_output_files']=i.get('run_output_files',[])
672 |
673 | if vrb=='yes':
674 | cm_kernel.print_for_con('')
675 | cm_kernel.print_for_con('Execution finished!')
676 |
677 | return ii
678 |
679 | # ============================================================================
680 | def prepare_env_for_all_codes(i):
681 |
682 | """
683 | Prepare environment for all codes
684 |
685 | Input: {
686 | code_deps - list with code UOA for dependencies [{"index":"uoa"} ...]
687 | os_uoa - OS UOA
688 | no_strict_check - if 'yes', do not check if code dependency was installed properly
689 | }
690 |
691 | Output: {
692 | cm_return - return code = 0, if successful
693 | cm_string - environment string
694 | cm_array - array with environment setting (for scripts)
695 | include_paths1 - list with paths with include directories
696 | lib_paths - list with libraries
697 | env_separator - environment separator (just in case to avoid double loading of OS)
698 | }
699 | """
700 |
701 | # Check vars
702 | if 'code_deps' not in i: return {'cm_return':1, 'cm_error':'"code_deps" is not defined in "code prepare_env_for_all_codes"'}
703 |
704 | include_paths=[]
705 | lib_paths=[]
706 |
707 | # Load OS
708 | os_uoa=''
709 | if 'os_uoa' in i and i['os_uoa']!='': os_uoa=i['os_uoa']
710 | elif 'cm_default_os_uoa' in cm_kernel.ini['dcfg'] and cm_kernel.ini['dcfg']['cm_default_os_uoa']!='':
711 | os_uoa=cm_kernel.ini['dcfg']['cm_default_os_uoa']
712 |
713 | if os_uoa=='' not in i:
714 | return {'cm_return':1, 'cm_error':'"os_uoa" is not defined and not in kernel'}
715 |
716 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['os'],
717 | 'cm_action':'load',
718 | 'cm_data_uoa':os_uoa}
719 | r=cm_kernel.access(ii)
720 | if r['cm_return']>0: return r
721 |
722 | os_cfg=r['cm_data_obj']['cfg']
723 | os_path=r['cm_path']
724 | os_uid=r['cm_uid']
725 | os_alias=r['cm_alias']
726 |
727 | s_code_deps=''
728 | a_code_deps=[]
729 | if 'code_deps' in i:
730 | for xx in i['code_deps']:
731 | yy=xx.keys()[0]
732 | x=xx[yy]
733 |
734 | if x=='':
735 | return {'cm_return':1, 'cm_error':'dependency "'+yy+'" is empty, please check your input'}
736 |
737 | # Check if code was installed
738 | if i.get('no_strict_check','')!='yes':
739 | ii={'cm_run_module_uoa':ini['cm_module_uid'],
740 | 'cm_action':'load',
741 | 'cm_data_uoa':x}
742 | r=cm_kernel.access(ii)
743 | if r['cm_return']==16:
744 | return {'cm_return':1, 'cm_error':'dependency is not resolved - code '+x+' ('+yy+') is not installed'}
745 | elif r['cm_return']>0: return r
746 | code_cfg=r['cm_data_obj']['cfg']
747 | if code_cfg.get('build_finished_successfully','')!='yes':
748 | return {'cm_return':1, 'cm_error':'dependency is not resolved - code '+x+' ('+yy+') is not installed'}
749 |
750 | code_path=r['cm_path']
751 | include_paths.append(os.path.join(code_path, 'include'))
752 |
753 | if 'state_input' in code_cfg and \
754 | 'run_set_env2' in code_cfg['state_input'] and \
755 | 'CM_TARGET_FILE' in code_cfg['state_input']['run_set_env2']:
756 | lib_paths.append(os.path.join(code_path, os_cfg['lib_dir'],
757 | code_cfg['state_input']['run_set_env2']['CM_TARGET_FILE']))
758 |
759 | # Environment script
760 | r=get_env({'cm_data_uoa':x, 'os_uoa':os_uoa})
761 | if r['cm_return']>0: return r
762 |
763 | # z=os_cfg['env_call']+' '+os.path.join(cm_kernel.ini[cm_kernel.env_cm_bin],r['cm_string'])
764 | z1=os_cfg['env_set']+' '+yy+'='+os_cfg['env_quotes']+x+os_cfg['env_quotes']
765 | z=os_cfg['env_call']+' '+r['cm_string']
766 |
767 | if s_code_deps!='': s_code_deps+=' '+os_cfg['env_separator']+' '
768 | s_code_deps+=z1
769 | if s_code_deps!='': s_code_deps+=' '+os_cfg['env_separator']+' '
770 | s_code_deps+=z
771 | # FGG added again setting environment variable since calling other scripts can change it
772 | # for example, we set CM_CODE_DEP_COMPILER and then call GMP that was compiled with another
773 | # compiler, then it will change this variable to a wrong value and further tools will
774 | # not be working correctly ...
775 | if s_code_deps!='': s_code_deps+=' '+os_cfg['env_separator']+' '
776 | s_code_deps+=z1
777 |
778 | a_code_deps.append(z1)
779 | a_code_deps.append(z)
780 | a_code_deps.append(z1)
781 |
782 | return {'cm_return':0, 'cm_string':s_code_deps, 'cm_array':a_code_deps, 'env_separator': os_cfg['env_separator'],
783 | 'include_paths':include_paths, 'lib_paths':lib_paths}
784 |
785 | # ============================================================================
786 | def prepare_env_vars(i):
787 | """
788 | Prepare environment variables
789 |
790 | Input: {
791 | array - array of environment variables to set
792 | prefix - add prefix to set environment variable
793 | separator - add separator for the command line
794 | (quotes) - use quotes?
795 | }
796 |
797 | Output: {
798 | cm_return - if =0, success
799 | cm_string - cmd with prepared environment (export A=B; export C=D; ...)
800 | cm_string1 - simplified string (CM_ALL_ENV="A=B C=D E=F")
801 | cm_array - array with environment setting (for scripts)
802 | }
803 | """
804 |
805 | # Check vars
806 | if 'array' not in i: return {'cm_return':1, 'cm_error': '"array" is not set in "os prepare_env_vars"'}
807 | if 'prefix' not in i: return {'cm_return':1, 'cm_error': '"prefix" is not set in "os prepare_env_vars"'}
808 | if 'separator' not in i: return {'cm_return':1, 'cm_error': '"separator" is not set in "os prepare_env_vars"'}
809 |
810 | q=''
811 | if 'quotes' in i: q=i['quotes']
812 |
813 | a=[]
814 | s=''
815 | s1=i['prefix']+' CM_ALL_ENV='+q
816 |
817 | for k,v in i['array'].iteritems():
818 | if s!='':
819 | s+=' '+i['separator']+' '
820 | s1+=' '
821 |
822 | z=i['prefix']+' '+k+'='
823 |
824 | # Check quotes (a bit tricky depending on the OS)
825 | x=''
826 | if q!='':
827 | # likely Linux/Android
828 | x=q+v.replace('"', '\"')+q
829 | else:
830 | # likely Windows
831 | x=v
832 |
833 | s+=z+x
834 | a.append(z+x)
835 |
836 | s1+=k+'='+q+v+q
837 | s1+=q
838 |
839 | return {'cm_return':0, 'cm_string':s, 'cm_string1':s1, 'cm_array':a}
840 |
841 | # ============================================================================
842 | def set_env(i):
843 |
844 | """
845 | Set environment for a given code
846 |
847 | Input: {
848 | input_key - key with code_uoa
849 | }
850 |
851 | Output: {
852 | cm_return - return code = 0, if successful
853 | os_env - OS environment from the code
854 | }
855 | """
856 |
857 | # Check vars
858 | if 'input_key' not in i: return {'cm_return':1, 'cm_error':'"input_key" is not defined in "code set_env"'}
859 | if i['input_key'] not in i: return {'cm_return':1, 'cm_error':'i["input_key"] is not defined in "code set_env"'}
860 |
861 | code_uoa=i[i['input_key']]
862 |
863 | # Load code
864 | ii={'cm_run_module_uoa':ini['cm_module_uid'],
865 | 'cm_action':'load',
866 | 'cm_data_uoa':code_uoa}
867 | r=cm_kernel.access(ii)
868 | if r['cm_return']>0: return r
869 | code_cfg=r['cm_data_obj']['cfg']
870 |
871 | r={'cm_return':0}
872 |
873 | if 'os_env' in code_cfg: r.update({'os_env':code_cfg['os_env']})
874 |
875 | return r
876 |
877 | # ============================================================================
878 | def install(i):
879 |
880 | """
881 | Install code and set environment
882 |
883 | Input: {
884 | (install_data_uid) - create an entry with this UID
885 | (install_data_alias) - create an entry with this alias
886 | (install_data_display_as_alias) - use this display as alias for a generated entry
887 | (install_module_uoa) - use this module to create an entry (if not set, use 'code')
888 | (install_repo_uoa) - use this repo to create an entry
889 | (cm_array) - add this data to the new entry
890 | target_os_uoa - target os to install script
891 | (add_rem_to_script) - add rem to install script
892 | }
893 |
894 | Output: {
895 | cm_return - return code = 0, if successful
896 |
897 | Parameters from entry creation
898 |
899 | script_filename - script filename
900 | script_name - full script name
901 | }
902 | """
903 |
904 | cm_kernel.print_for_con('***********************************************')
905 | cm_kernel.print_for_con('Installing code ...')
906 |
907 | # Check vars
908 | if 'target_os_uoa' not in i: return {'cm_return':1, 'cm_error':'"target_os_uoa" is not defined in "code install"'}
909 |
910 | # Create entry
911 | ii={'cm_run_module_uoa':ini['cm_module_uid'],
912 | 'cm_action':'update'}
913 | if 'install_data_uid' in i and i['install_data_uid']!='':
914 | ii['cm_data_uid']=i['install_data_uid']
915 | if 'install_data_alias' in i and i['install_data_alias']!='':
916 | ii['cm_data_uoa']=i['install_data_alias']
917 | if 'install_data_display_as_alias' in i:
918 | ii['cm_display_as_alias']=i['install_data_display_as_alias']
919 | if 'install_module_uoa' in i and i['install_module_uoa']!='':
920 | ii['cm_run_module_uoa']=i['install_module_uoa']
921 | if 'cm_array' in i and len(i['cm_array'])>0: ii['cm_array']=i['cm_array']
922 | if 'install_repo_uoa' in i and i['install_repo_uoa']!='':
923 | ii['cm_repo_uoa']=i['install_repo_uoa']
924 | r=cm_kernel.access(ii)
925 | if r['cm_return']>0: return r
926 |
927 | target_path=r['cm_path']
928 | target_uid=r['cm_uid']
929 | target_alias=r['cm_alias']
930 |
931 | # Prepare script
932 | rx=get_env({'cm_data_uoa':target_uid,
933 | 'os_uoa':i['target_os_uoa']})
934 | if rx['cm_return']>0: return rx
935 |
936 | script=rx['cm_string']
937 |
938 | ii={'script_name':script,
939 | 'skip_extension':'yes',
940 | 'target_os_uoa':i['target_os_uoa'],
941 | 'cm_path':target_path}
942 | if 'code_deps' in i and i.get('skip_code_deps','')!='yes':
943 | ii['code_deps']=i['code_deps']
944 |
945 | # Add remark about how code was built
946 | if 'add_rem_to_script' in i:
947 | run_commands_before=[]
948 | run_commands_before.append('')
949 | for x in i['add_rem_to_script']:
950 | run_commands_before.append(x)
951 | ii['run_commands_before']=run_commands_before
952 |
953 | rx=prepare_script(ii)
954 | if rx['cm_return']>0: return rx
955 |
956 | r['script_name']=rx['cm_path']
957 | r['script_filename']=script
958 |
959 | return r
960 |
961 | # ============================================================================
962 | def prepare_script(i):
963 |
964 | """
965 | Prepare script with code deps
966 |
967 | Input: {
968 | script_name - script name (usually without extensions)
969 | target_os_uoa - target os to get script extension and other parameters
970 | (skip_extension) - if 'yes', script already has extension
971 | (cm_path) - path to create script
972 | (set_env1) - add environment vars (1) to script
973 | (code_deps) - add code deps to script
974 | (set_env2) - add environment vars (2) to script
975 | (run_commands_before) - add some commands before main command
976 | (run_cmd) - add main command
977 | (run_commands_after) - add some commands after main command
978 | }
979 |
980 | Output: {
981 | cm_return - return code = 0, if successful
982 | cm_path - full name of the created script with path
983 | }
984 | """
985 |
986 | # Check vars
987 | if 'script_name' not in i: return {'cm_return':1, 'cm_error':'"script_name" is not defined in "code prepare_script"'}
988 | if 'target_os_uoa' not in i: return {'cm_return':1, 'cm_error':'"target_os_uoa" is not defined in "code prepare_script"'}
989 |
990 | # Prepare path
991 | p=''
992 | if 'cm_path' in i and i['cm_path']!='':
993 | p=os.path.join(i['cm_path'], i['script_name'])
994 | else:
995 | p=i['script_name']
996 |
997 | # Load OS
998 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['os'],
999 | 'cm_action':'load',
1000 | 'cm_data_uoa':i['target_os_uoa']}
1001 | r=cm_kernel.access(ii)
1002 | if r['cm_return']>0: return r
1003 |
1004 | target_os_cfg=r['cm_data_obj']['cfg']
1005 | target_os_path=r['cm_path']
1006 | target_os_uid=r['cm_uid']
1007 | target_os_alias=r['cm_alias']
1008 |
1009 | if i.get('skip_extension','')!='yes':
1010 | p+=target_os_cfg['script_ext']
1011 |
1012 | try:
1013 | f=open(p, 'w')
1014 | if 'batch_prefix' in target_os_cfg and target_os_cfg['batch_prefix']!='': f.write(target_os_cfg['batch_prefix'])
1015 |
1016 | if 'rem' in target_os_cfg: f.write('\n'+target_os_cfg['rem']+' target_os_uoa: '+i['target_os_uoa']+'\n')
1017 |
1018 | if 'set_env1' in i and len(i['set_env1'])>0:
1019 | f.write('\n')
1020 | if 'rem' in target_os_cfg: f.write(target_os_cfg['rem']+' Set global parameters\n')
1021 | r=prepare_env_vars({'array':i['set_env1'],
1022 | 'prefix':target_os_cfg['env_set'],
1023 | 'separator':target_os_cfg['env_separator'],
1024 | 'quotes':target_os_cfg['env_quotes']})
1025 | if r['cm_return']>0: return r
1026 | for x in r['cm_array']: f.write(x+'\n')
1027 |
1028 | if 'code_deps' in i and len(i['code_deps'])>0:
1029 | r=prepare_env_for_all_codes({'code_deps':i['code_deps'],
1030 | 'os_uoa':i['target_os_uoa']})
1031 | if r['cm_return']>0: return r
1032 | f.write('\n')
1033 | if 'rem' in target_os_cfg: f.write(target_os_cfg['rem']+' Prepare code dependencies\n')
1034 | for x in r['cm_array']: f.write(x+'\n')
1035 |
1036 | if 'set_env2' in i and len(i['set_env2'])>0:
1037 | f.write('\n')
1038 | if 'rem' in target_os_cfg: f.write(target_os_cfg['rem']+' Set execution parameters\n')
1039 | r=prepare_env_vars({'array':i['set_env2'],
1040 | 'prefix':target_os_cfg['env_set'],
1041 | 'separator':target_os_cfg['env_separator'],
1042 | 'quotes':target_os_cfg['env_quotes']})
1043 | if r['cm_return']>0: return r
1044 | for x in r['cm_array']: f.write(x+'\n')
1045 |
1046 | if 'run_commands_before' in i:
1047 | for x in i['run_commands_before']: f.write(x+'\n')
1048 |
1049 | if 'run_cmd' in i:
1050 | f.write('\n')
1051 | if 'rem' in target_os_cfg: f.write(target_os_cfg['rem']+' Executable\n')
1052 | f.write(i['run_cmd'].strip()+'\n')
1053 |
1054 | if 'run_commands_after' in i:
1055 | for x in i['run_commands_after']: f.write(x+'\n')
1056 |
1057 | f.close()
1058 | except Exception as e:
1059 | return {'cm_return':1, 'cm_error':'error while preparing script in "code prepare_script" ('+format(e)+')'}
1060 |
1061 | return {'cm_return':0, 'cm_path':p}
1062 |
1063 | # ============================================================================
1064 | def prepare_sub_script(i):
1065 |
1066 | """
1067 | Prepare sub_script with extension
1068 |
1069 | Input: {
1070 | run_script - script name (usually without extensions)
1071 | (run_script_uoa) - script UOA if any
1072 | target_os_cfg - target os cfg to get script extension and other parameters
1073 |
1074 | }
1075 |
1076 | Output: {
1077 | cm_return - return code = 0, if successful
1078 | cm_path - full name of the created script with path
1079 | }
1080 | """
1081 |
1082 | run_cmd=''
1083 |
1084 | target_os_cfg=i['target_os_cfg']
1085 |
1086 | remote=False
1087 | if target_os_cfg.get('remote','')=='yes':
1088 | remote=True
1089 |
1090 | script_name=i['run_script']
1091 |
1092 | script_path=''
1093 | if 'run_script_uoa' in i and i['run_script_uoa']!='':
1094 | # cm_kernel.print_for_con('')
1095 | # cm_kernel.print_for_con('Preparing path for OS script '+i['run_script_uoa']+' ...')
1096 |
1097 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['os.script'],
1098 | 'cm_action':'load',
1099 | 'cm_data_uoa':i['run_script_uoa']}
1100 | r=cm_kernel.access(ii)
1101 | if r['cm_return']>0: return r
1102 |
1103 | script_cfg=r['cm_data_obj']['cfg']
1104 | script_path=r['cm_path']
1105 |
1106 | if 'scripts' not in script_cfg or i['run_script'] not in script_cfg['scripts']:
1107 | return {'cm_return':1, 'cm_error':'can\'t find script in os.script configuration'}
1108 |
1109 | script_name=script_cfg['scripts'][script_name]
1110 |
1111 | script_name+=target_os_cfg['script_ext']
1112 |
1113 | run_name=script_name
1114 | if script_path!='':
1115 | run_name=os.path.join(script_path, run_name)
1116 | elif 'exec_prefix' in target_os_cfg and target_os_cfg['exec_prefix']!='':
1117 | run_name=target_os_cfg['exec_prefix']+run_name
1118 |
1119 | if target_os_cfg.get('set_executable','')!='':
1120 | p=target_os_cfg['set_executable']+' '+run_name
1121 | x=os.system(p)
1122 |
1123 | run_cmd=''
1124 | if remote and target_os_cfg.get('no_script_execution','')=='yes':
1125 | r=cm_kernel.load_array_from_file({'cm_filename':run_name})
1126 | if r['cm_return']>0: return r
1127 | a=r['cm_array']
1128 | for x in a:
1129 | xx=x.strip()
1130 | if xx!='' and not xx.startswith(target_os_cfg['rem']):
1131 | if run_cmd!='': run_cmd+=target_os_cfg['env_separator']+' '
1132 | run_cmd+=xx
1133 | run_name=''
1134 | else:
1135 | run_cmd=run_name
1136 |
1137 | if i.get('run_cmd','')!='': run_cmd+=' '+i['run_cmd']
1138 |
1139 | if i.get('run_cmd_out1','')!='': run_cmd+=' 1>'+i['run_cmd_out1']
1140 | if i.get('run_cmd_out2','')!='': run_cmd+=' 2>'+i['run_cmd_out2']
1141 |
1142 |
1143 | return {'cm_return':0, 'run_cmd':run_cmd}
1144 |
1145 | # ============================================================================
1146 | def prepare_cmd(i):
1147 | """
1148 | Prepare command line for the code
1149 |
1150 | Input: {
1151 | (code_module_uoa) - module of the working data
1152 | (code_data_uoa) - working data uoa
1153 | (run_cmd_key) - name if multiple CMDs available for this program
1154 | (dataset_uoa) - UOA of dataset used to prepare this cmd
1155 | (os_uoa) - OS UOA
1156 | (compilation_type) - static or dynamic
1157 | }
1158 |
1159 | Output: {
1160 | cm_return - if =0, success
1161 | (cm_error) - if cm_return>0, error text
1162 |
1163 | run_time={
1164 | run_env - set environment before command line
1165 | - the following params will be aggregated to 1 line
1166 | run_cmd1
1167 | run_cmd_binary_name
1168 | run_cmd2
1169 | run_cmd_main
1170 | run_cmd3
1171 | run_cmd_out1
1172 | run_cmd_out2
1173 | run_output_files
1174 | run_input_files
1175 | dataset_files
1176 | }
1177 |
1178 | build_compiler_vars - possible compiler variables (often set hardwired dataset)
1179 | }
1180 | """
1181 |
1182 | # Prepare environment
1183 | rr={'cm_return':0}
1184 |
1185 | # Load OS configuration
1186 | os_uoa=''
1187 | if 'os_uoa' in i and i['os_uoa']!='': os_uoa=i['os_uoa']
1188 | elif 'cm_default_os_uoa' in cm_kernel.ini['dcfg'] and cm_kernel.ini['dcfg']['cm_default_os_uoa']!='':
1189 | os_uoa=cm_kernel.ini['dcfg']['cm_default_os_uoa']
1190 |
1191 | if os_uoa=='' not in i:
1192 | return {'cm_return':1, 'cm_error':'"os_uoa" is not defined and not in kernel'}
1193 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['os'],
1194 | 'cm_action':'load',
1195 | 'cm_data_uoa':os_uoa}
1196 | r=cm_kernel.access(ii)
1197 | if r['cm_return']>0: return r
1198 |
1199 | os_cfg=r['cm_data_obj']['cfg']
1200 | os_path=r['cm_path']
1201 | os_uid=r['cm_uid']
1202 | os_alias=r['cm_alias']
1203 |
1204 | run_time={}
1205 | run_input_files=[]
1206 | target_file=''
1207 |
1208 | # Check vars
1209 | if 'code_data_uoa' in i and 'run_cmd_key' in i:
1210 | # Load source code
1211 | m=ini['cm_module_uid']
1212 | if 'code_module_uoa' in i and i['code_module_uoa']!='': m=i['code_module_uoa']
1213 | ii={'cm_run_module_uoa':m,
1214 | 'cm_action':'load',
1215 | 'cm_data_uoa':i['code_data_uoa']}
1216 | r=cm_kernel.access(ii)
1217 | if r['cm_return']>0: return r
1218 |
1219 | sc_cfg=r['cm_data_obj']['cfg']
1220 | sc_path=r['cm_path']
1221 | sc_uid=r['cm_uid']
1222 | sc_alias=r['cm_alias']
1223 |
1224 | # Prepare binary file
1225 | target_file=''
1226 | if 'target_file' in sc_cfg: target_file=os_cfg.get('exec_prefix','')+sc_cfg['target_file']
1227 |
1228 | add_target_extension1=sc_cfg.get('add_target_extension',{})
1229 | ct=i.get('compilation_type','')
1230 | if ct=='': ct='static'
1231 | if ct in add_target_extension1: add_target_extension=add_target_extension1.get(ct)
1232 |
1233 | if add_target_extension!='':
1234 | if 'file_extensions' in os_cfg and add_target_extension in os_cfg['file_extensions']:
1235 | target_ext=os_cfg['file_extensions'][add_target_extension]
1236 | target_file+=target_ext
1237 |
1238 | cm_kernel.print_for_con('Prepared target binary name: '+target_file)
1239 |
1240 | # Set vars
1241 | if 'run_cmds' in sc_cfg and i['run_cmd_key'] in sc_cfg['run_cmds']:
1242 | rc=sc_cfg['run_cmds'][i['run_cmd_key']]
1243 |
1244 | run_time=copy.deepcopy(rc.get('run_time',{})) # otherwise change somewhere
1245 | # and it mixes up caching
1246 |
1247 | # Put original input files (useful for mobiles not to mix with dataset files)
1248 | orif=[]
1249 | for q in run_time.get('run_input_files',[]):
1250 | orif.append(q)
1251 |
1252 | # Load dataset
1253 | if i.get('dataset_uoa','')!='':
1254 | cm_kernel.print_for_con('')
1255 | cm_kernel.print_for_con('Loading dataset ...')
1256 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['dataset'],
1257 | 'cm_action':'load',
1258 | 'cm_data_uoa':i['dataset_uoa']}
1259 | r=cm_kernel.access(ii)
1260 | if r['cm_return']>0: return r
1261 |
1262 | ds_cfg=r['cm_data_obj']['cfg']
1263 | ds_path=r['cm_path']
1264 | ds_uid=r['cm_uid']
1265 | ds_alias=r['cm_alias']
1266 |
1267 | if 'build_compiler_vars' in ds_cfg:
1268 | rr['build_compiler_vars']=ds_cfg['build_compiler_vars']
1269 |
1270 | if 'run_cmd_main' in run_time:
1271 | ds_path1=ds_path
1272 | os_sep=os_cfg.get('dir_sep','')
1273 | if os_cfg.get('remote','')=='yes':
1274 | ds_path1=''
1275 | os_sep=''
1276 | run_time['run_cmd_main']=run_time['run_cmd_main'].replace(cm_kernel.convert_str_to_special('dataset_path'), ds_path1)
1277 | run_time['run_cmd_main']=run_time['run_cmd_main'].replace(cm_kernel.convert_str_to_special('os_dir_separator'), os_sep)
1278 |
1279 | # Check which path to use for data set
1280 | if 'dataset_files' in ds_cfg and len(ds_cfg['dataset_files'])>0:
1281 | run_time['dataset_files']=ds_cfg['dataset_files']
1282 | xx=0
1283 | for x in ds_cfg['dataset_files']:
1284 | y='dataset_filename'
1285 | if xx!=0: y+='_'+str(xx)
1286 | run_time['run_cmd_main']=run_time['run_cmd_main'].replace(cm_kernel.convert_str_to_special(y), x)
1287 | xx+=1
1288 |
1289 | # Prepare input files (for remote)
1290 | if 'dataset_files' in ds_cfg and len(ds_cfg['dataset_files'])>0:
1291 | x1=ds_path
1292 | for x2 in ds_cfg['dataset_files']:
1293 | x3=os.path.join(x1,x2)
1294 | if x3 not in run_input_files: run_input_files.append(x3)
1295 |
1296 | # Check cm_properties
1297 | rcm=ds_cfg.get('cm_properties',{}).get('run_time',{}).get('run_cmd_main',{})
1298 | for x in rcm:
1299 | run_time['run_cmd_main']=run_time['run_cmd_main'].replace(cm_kernel.convert_str_to_special(x), rcm[x])
1300 |
1301 | run_time['binary_name']=target_file
1302 | rr['run_time']=run_time
1303 | rr['run_time']['original_run_input_files']=orif
1304 | if 'run_input_files' not in rr['run_time']: rr['run_time']['run_input_files']=[]
1305 | for q in run_input_files:
1306 | if q not in rr['run_time']['run_input_files']: rr['run_time']['run_input_files'].append(q)
1307 |
1308 | return rr
1309 |
1310 | # ============================================================================
1311 | def native_run(i):
1312 | """
1313 | Native run with timing
1314 |
1315 | Input: {
1316 | cm_unparsed - run
1317 | skip_output - if 'yes', do not print 'Execution time ...'
1318 | }
1319 |
1320 | Output: {
1321 | cm_return - return of the system
1322 | execution_time - execution time of a command
1323 | }
1324 | """
1325 |
1326 | ucmd=i['cm_unparsed']
1327 |
1328 | cmd=''
1329 | for q in ucmd:
1330 | cmd+=' '+q
1331 | cmd=cmd.strip()
1332 |
1333 | tstart=time.time()
1334 |
1335 | rc=os.system(cmd)
1336 |
1337 | t=time.time()-tstart
1338 |
1339 | if i.get('skip_output','')!='yes':
1340 | cm_kernel.print_for_con('Execution time: '+"%.3f" % t+' seconds')
1341 |
1342 | return {'cm_return':0, 'execution_time':str(t)}
1343 |
--------------------------------------------------------------------------------
/module/package/module.py:
--------------------------------------------------------------------------------
1 | #
2 | # Collective Mind
3 | #
4 | # See cM LICENSE.txt for licensing details.
5 | # See cM Copyright.txt for copyright details.
6 | #
7 | # Developer(s): (C) Grigori Fursin, started on 2011.09
8 | #
9 |
10 | # Should always be here
11 | ini={}
12 | cm_kernel=None
13 |
14 | # Local settings
15 | import shutil
16 | import os
17 | import json
18 | import re
19 |
20 | # ============================================================================
21 | def init(i):
22 | return {'cm_return':0}
23 |
24 | # ============================================================================
25 | def install(i):
26 |
27 | """
28 | Install cM package
29 |
30 | Input: {
31 | package_data_uoa - UOA of package to install
32 | (package_repo_uoa) - repo of the package
33 | package_host_os_uoa - UOA of host OS (to set up script execution)
34 |
35 | (install_data_uid) - UID of the code where package will be installed
36 | if install_data_uid=='' it will be randomly generated
37 | (install_data_alias) - use this alias for a generated entry
38 | (install_data_display_as_alias) - use this display as alias for a generated entry
39 |
40 | If package should be built:
41 | build_target_os_uoa - target OS uoa for building
42 | (code_deps) - list with code UOA for dependencies [{"index":"uoa"} ...]
43 | (run_target_processor_uoa) - target processor UOA (not strictly needed - can add some helper parameters before executing code)
44 | (run_set_env2) - array with environment variables to be set before executable
45 | (add_rem_to_script) - add rem to install script
46 | (add_to_code_entry) - add array to code entry
47 | (skip_extract_and_build) - if 'yes', skip copy, extract and build (by setting CM_SKIP_BUILD=yes)
48 | }
49 |
50 | Output: {
51 | cm_return - return code = 0, if successful
52 |
53 | Output from 'code install'
54 | }
55 | """
56 |
57 | cm_kernel.print_for_con('***********************************************')
58 | cm_kernel.print_for_con('Installing package ...')
59 |
60 | # Check package UOA
61 | if 'package_data_uoa' not in i:
62 | return {'cm_return':1, 'cm_error':'"package_data_uoa" is not defined'}
63 | package=i['package_data_uoa']
64 |
65 | # Load package configuration
66 | cm_kernel.print_for_con('')
67 | cm_kernel.print_for_con('Loading info about package '+package+' ...')
68 |
69 | ii={'cm_run_module_uoa':ini['cm_module_uid'],
70 | 'cm_action':'load',
71 | 'cm_data_uoa':package}
72 | if 'package_repo_uoa' in i: ii.update({'cm_repo_uoa':i['package_repo_uoa']})
73 | r=cm_kernel.access(ii)
74 | if r['cm_return']>0: return r
75 |
76 | package_cfg=r['cm_data_obj']['cfg']
77 | package_path=r['cm_path']
78 | package_uid=r['cm_uid']
79 | package_alias=r['cm_alias']
80 |
81 | # Set run_set_env2
82 | run_set_env2=package_cfg.get('run_set_env2',{})
83 | if 'run_set_env2' in i and len(i['run_set_env2'])>0: run_set_env2.update(i['run_set_env2'])
84 |
85 | cm_kernel.print_for_con('')
86 | cm_kernel.print_for_con('Package path: '+package_path)
87 | cm_kernel.print_for_con('Package Alias: '+package_alias)
88 | cm_kernel.print_for_con('Package UID: '+package_uid)
89 |
90 | # Check if need to add something to the code entry
91 | add_to_code_entry=i.get('add_to_code_entry',{})
92 | if 'add_to_code_entry' in package_cfg:
93 | cm_kernel.merge_arrays({'cm_array':add_to_code_entry, 'cm_array1': package_cfg['add_to_code_entry']})
94 |
95 | # Load OS configuration
96 | package_host_os_uoa=''
97 | if 'package_host_os_uoa' in i and i['package_host_os_uoa']!='': package_host_os_uoa=i['package_host_os_uoa']
98 | elif 'cm_default_os_uoa' in cm_kernel.ini['dcfg'] and cm_kernel.ini['dcfg']['cm_default_os_uoa']!='':
99 | package_host_os_uoa=cm_kernel.ini['dcfg']['cm_default_os_uoa']
100 |
101 | if package_host_os_uoa=='' not in i:
102 | return {'cm_return':1, 'cm_error':'"package_host_os_uoa" is not defined and not in kernel'}
103 | cm_kernel.print_for_con('')
104 | cm_kernel.print_for_con('Loading os '+package_host_os_uoa+' ...')
105 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['os'],
106 | 'cm_action':'load',
107 | 'cm_data_uoa':package_host_os_uoa}
108 | r=cm_kernel.access(ii)
109 | if r['cm_return']>0: return r
110 |
111 | target_os_cfg=r['cm_data_obj']['cfg']
112 | target_os_path=r['cm_path']
113 | target_os_uid=r['cm_uid']
114 | target_os_alias=r['cm_alias']
115 |
116 | # Check if need to build
117 | build=False
118 | if package_cfg.get('build','')=='yes': build=True
119 |
120 | # Check where to copy files before installing: to "code" or to "code.source"
121 | if build:
122 | # Create code source entry
123 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['code.source'],
124 | 'cm_action':'update'}
125 | if 'install_data_uid' in i:
126 | ii['cm_data_uoa']=i['install_data_uid']
127 | else:
128 | ii['cm_data_uoa']=package_uid
129 | if 'add_to_code_source' in package_cfg:
130 | ii['cm_array']=package_cfg['add_to_code_source']
131 | if 'install_repo_uoa' in i: ii['cm_repo_uoa']=i['install_repo_uoa']
132 | r=cm_kernel.access(ii)
133 | if r['cm_return']>0: return r
134 | target_path=r['cm_path']
135 | target_uoa=r['cm_uid']
136 | else:
137 | # Create code entry
138 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['code'],
139 | 'cm_action':'update'}
140 | if 'install_data_uid' in i: ii.update({'cm_data_uid':i['install_data_uid']})
141 | if 'install_data_alias' in i: ii.update({'cm_data_uoa':i['install_data_alias']})
142 | if 'install_data_display_as_alias' in i: ii.update({'cm_display_as_alias':i['install_data_display_as_alias']})
143 | if 'install_repo_uoa' in i: ii['cm_repo_uoa']=i['install_repo_uoa']
144 | if 'local_src_dir' in package_cfg:
145 | ii['cm_array']={}
146 | ii['cm_array']['local_src_dir']=package_cfg['local_src_dir']
147 | r=cm_kernel.access(ii)
148 | if r['cm_return']>0: return r
149 | target_path=r['cm_path']
150 | target_uoa=r['cm_uid']
151 |
152 | # Install script
153 | install_script_without_ext=''
154 | install_script=''
155 | if 'install_script' in package_cfg:
156 | install_script_without_ext=package_cfg['install_script']
157 | install_script=install_script_without_ext+target_os_cfg['script_ext']
158 |
159 | # Copy files
160 | files=[]
161 | if 'cm_files' in package_cfg: files=package_cfg['cm_files']
162 | if install_script!='': files.append(install_script)
163 |
164 | if len(files)>0:
165 | cm_kernel.print_for_con('')
166 | cm_kernel.print_for_con('Copying files ...')
167 | for f in files:
168 | cm_kernel.print_for_con(' '+f)
169 | f1=os.path.join(package_path, f)
170 | f2=os.path.join(target_path, f)
171 | try:
172 | shutil.copyfile(str(f1),str(f2))
173 | except IOError as e:
174 | return {'cm_return':1, 'cm_error':'can\'t copy file '+f+' ('+format(e)+')'}
175 |
176 | if i.get('skip_extract_and_build','')!='yes':
177 |
178 | # Extracting
179 | if len(files)>0:
180 | cm_kernel.print_for_con('')
181 | cm_kernel.print_for_con('Check if need to extract files ...')
182 | for f in files:
183 | if f!=install_script:
184 | for ext in target_os_cfg['extract_package']:
185 | if f.endswith(ext):
186 | s=target_os_cfg['change_dir']+' '+target_path+' '+target_os_cfg['env_separator']+\
187 | target_os_cfg['extract_package'][ext]
188 | s1=s.replace(cm_kernel.convert_str_to_special('cm_file'), f)
189 | s2=s1.replace(cm_kernel.convert_str_to_special('cm_file_without_one_ext'), os.path.splitext(f)[0])
190 |
191 | cm_kernel.print_for_con('')
192 | cm_kernel.print_for_con(s2)
193 | cm_kernel.print_for_con('')
194 |
195 | r=os.system(str(s2))
196 | if r!=0: return {'cm_return':1, 'cm_error':'problem while extracting '+f}
197 |
198 | # Set executable
199 | if install_script!='' and 'set_executable' in target_os_cfg:
200 | cm_kernel.print_for_con('')
201 | cm_kernel.print_for_con('Setting permissions for executable ...')
202 |
203 | p1=os.path.join(target_path, install_script)
204 | r=os.system(target_os_cfg['set_executable']+' '+p1)
205 |
206 | # Build
207 | if build:
208 | cm_kernel.print_for_con('')
209 | cm_kernel.print_for_con('Building ...')
210 | else:
211 | cm_kernel.print_for_con('')
212 | cm_kernel.print_for_con('Installing ...')
213 |
214 | if install_script=='':
215 | return {'cm_return':1, 'cm_error':'install script is not defined'}
216 |
217 | # Checking some vars
218 | if 'build_target_os_uoa' not in i:
219 | return {'cm_return':1, 'cm_error':'"build_target_os_uoa" is not defined'}
220 |
221 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['code.source'],
222 | 'package_data_uoa':i['package_data_uoa'],
223 | 'cm_action':'build',
224 | 'work_dir_data_uoa':target_uoa,
225 | 'run_script':install_script_without_ext,
226 | 'install':'yes',
227 | 'run_host_os_uoa':i['package_host_os_uoa'],
228 | 'build_target_os_uoa':i['build_target_os_uoa'],
229 | 'run_set_env2':{}}
230 | if build:
231 | ii['work_dir_module_uoa']=ini['cfg']['cm_modules']['code.source']
232 | else:
233 | ii['work_dir_module_uoa']=ini['cfg']['cm_modules']['code']
234 |
235 | if 'install_repo_uoa' in i:
236 | ii['work_dir_repo_uoa']=i['install_repo_uoa']
237 | ii['install_repo_uoa']=i['install_repo_uoa']
238 | if 'install_data_uid' in i:
239 | ii['install_data_uid']=i['install_data_uid']
240 | else: ii['install_data_uid']=target_uoa #FGG: need to check that it's correct, i.e. if we install
241 | # something like GCC, that we correctly reuse code & code.source
242 | if 'install_data_alias' in i: ii['install_data_uoa']=i['install_data_alias']
243 | if 'install_data_display_as_alias' in i: ii['install_data_display_as_alias']=i['install_data_display_as_alias']
244 | if 'code_deps' in i: ii['code_deps']=i['code_deps']
245 | if len(run_set_env2)>0: ii['run_set_env2']=run_set_env2
246 | if i.get('skip_extract_and_build','')=='yes': ii['run_set_env2']['CM_SKIP_BUILD']='yes'
247 | if 'run_target_processor_uoa' in i: ii['run_target_processor_uoa']=i['run_target_processor_uoa']
248 | if 'add_rem_to_script' in i: ii['add_rem_to_script']=i['add_rem_to_script']
249 | if len(add_to_code_entry)>0: ii['add_to_code_entry']=add_to_code_entry
250 |
251 | rr=cm_kernel.access(ii)
252 |
253 | return rr
254 |
255 | # ============================================================================
256 | def web_install(i):
257 |
258 | """
259 | Install cM package/library
260 |
261 | When searching for already installed code, dependencies are checked
262 | * using classes for packages (to allow reuse of packages)
263 | * by exact code_uoa for code.source (to have exact build setup)
264 |
265 | FGG: the checks are a bit ugly and were done in a rush.
266 | Should be simplified, cleaned up and unified one day.
267 |
268 | Input: {
269 | package_data_uoa - UOA of package to install
270 | (package_repo_uoa) - repo of the package
271 | package_host_os_uoa - UOA of host OS (to set up script execution)
272 |
273 | (install_data_uid) - UID of the code where package will be installed
274 | if install_data_uid=='' it will be randomly generated
275 | (install_data_alias) - use this alias for a generated entry
276 |
277 | If package should be built:
278 | build_target_os_uoa - target OS uoa for building
279 | (code_deps) - list with code UOA for dependencies [{"index":"uoa"} ...]
280 | (run_target_processor_uoa) - target processor UOA (not strictly needed - can add some helper parameters before executing code)
281 | (run_set_env2) - array with environment variables to be set before executable
282 | (add_rem_to_script) - add rem to install script
283 | (skip_extract_and_build) - if 'yes', skip copy, extract and build (by setting CM_SKIP_BUILD=yes)
284 | }
285 |
286 | Output: {
287 | cm_return - return code = 0, if successful
288 |
289 | Output from 'code install'
290 | }
291 | """
292 |
293 | # Get web style
294 | if 'cfg' in cm_kernel.ini['web_style']: web=cm_kernel.ini['web_style']['cfg']
295 | else:
296 | return {'cm_return':1, 'cm_error':'web style is not defined'}
297 |
298 | cm_kernel.print_for_con('Install / monitor packages
')
299 |
300 | # Detecting/restoring data from forms
301 | a1={}
302 |
303 | r=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['cm-web'],
304 | 'cm_action':'detect_form_params',
305 | 'cm_array':i,
306 | 'cm_prefix':'#form1'})
307 | if r['cm_return']>0: return r
308 | cm_form_array1=r['cm_array']
309 | cm_form_commands1=r['cm_commands']
310 |
311 | # Get data description for this action
312 | r=cm_kernel.get_data_description({'cm_module_uoa':ini['cm_module_uoa'],
313 | 'cm_which_action':i['cm_action']})
314 | if r['cm_return']>0: return r
315 | cm_data_desc1=r['cm_data_desc']
316 | cm_params_default1=r['cm_params_default']
317 |
318 | # Check default
319 | if len(cm_form_array1)==0:
320 | a1=cm_params_default1
321 | else:
322 | r=cm_kernel.restore_flattened_array({'cm_array':cm_form_array1,
323 | 'cm_replace_in_keys':{'^35^':'#', '^64^':'@'}})
324 | if r['cm_return']>0: return r
325 | a1=r['cm_array']
326 |
327 | # If there is data in form, means that refresh
328 | forms_exists='yes'
329 | if len(cm_form_array1)==0: forms_exists='no'
330 |
331 | if 'skip_extract_and_build' in i: a1['skip_extract_and_build']=i['skip_extract_and_build']
332 |
333 | # Check if setup is selected and prune choices *********************************************************************
334 | cm_scen_c=''
335 | cm_scen_p=''
336 |
337 | cm_setup_uoa=a1.get('ctuning_setup_uoa','')
338 | if cm_setup_uoa!='':
339 | # Load setup
340 | ii={}
341 | ii['cm_run_module_uoa']=ini['cfg']['cm_modules']['ctuning.setup']
342 | ii['cm_action']='load'
343 | ii['cm_data_uoa']=cm_setup_uoa
344 | r=cm_kernel.access(ii)
345 | if r['cm_return']>0: return r
346 |
347 | ds=r['cm_data_obj']['cfg']
348 |
349 | # Check class
350 | ctuning_scenario_uoa=ds.get('ctuning_scenario_uoa','')
351 | if ctuning_scenario_uoa!='':
352 | ii={}
353 | ii['cm_run_module_uoa']=ini['cfg']['cm_modules']['ctuning.scenario']
354 | ii['cm_action']='load'
355 | ii['cm_data_uoa']=ctuning_scenario_uoa
356 | r=cm_kernel.access(ii)
357 | if r['cm_return']>0: return r
358 | ds1=r['cm_data_obj']['cfg']
359 |
360 | cm_scen_c=ds1.get('cm_classes_uoa',[])
361 | cm_scen_p=ds1.get('cm_properties',{})
362 |
363 | cm_kernel.print_for_web('