26
26
CONFIG_JSON = "config.json"
27
27
CONTRACTS_DIR = "contracts/"
28
28
TEMPLATE_DIR = ("TEMPLATE_DIR" , "templates/contracts" )
29
- EOSIO_CPP_DIR = "/usr/opt/eosio.cdt/0.0.0/"
30
29
31
30
eosfactory_data_ = ("EOSFACTORY_DATA_DIR" ,
32
31
[os .path .expandvars ("${HOME}/.local/" + EOSFACTORY_DIR ),\
58
57
["nodeos" ,"/usr/bin/nodeos" , "/usr/local/bin/nodeos" ])
59
58
eosio_cpp_ = ("EOSIO_CPP" ,
60
59
["eosio-cpp" , "/usr/bin/eosio-cpp" , "/usr/local/bin/eosio-cpp" ])
61
- eosio_cpp_dir_ = ("EOSIO_CPP_DIR" , [EOSIO_CPP_DIR ])
60
+ eosio_cdt_root_ = ("EOSIO_CDT_ROOT" ,
61
+ ["/usr/opt/eosio.cdt/0.0.0/" , "/usr/local/Cellar/eosio.cdt/0.0.0" ])
62
62
eosio_cpp_includes_ = (
63
63
"EOSIO_CPP_INCLUDES" ,
64
64
[["include" , "include/libcxx" , "include/eosiolib/core" , \
@@ -207,23 +207,23 @@ def set(contract_workspace_dir):
207
207
208
208
209
209
def config_dir ():
210
- dir = os .path .join (eosfactory_data (), CONFIG_DIR )
211
- if not os .path .exists (dir ):
210
+ path = os .path .join (eosfactory_data (), CONFIG_DIR )
211
+ if not os .path .exists (path ):
212
212
raise errors .Error ('''
213
213
Cannot find the configuration directory
214
214
{}
215
- ''' .format (dir ), translate = False )
216
- return dir
215
+ ''' .format (path ), translate = False )
216
+ return path
217
217
218
218
219
219
def template_dir ():
220
- dir = os .path .join (eosfactory_data (), TEMPLATE_DIR [1 ])
221
- if not os .path .exists (dir ):
220
+ path = os .path .join (eosfactory_data (), TEMPLATE_DIR [1 ])
221
+ if not os .path .exists (path ):
222
222
raise errors .Error ('''
223
223
Cannot find the template directory
224
224
{}
225
- ''' .format (dir ), translate = False )
226
- return dir
225
+ ''' .format (path ), translate = False )
226
+ return path
227
227
228
228
229
229
def eoside_includes_dir ():
@@ -233,12 +233,12 @@ def eoside_includes_dir():
233
233
*INCLUDE* entry in the *config.json* file,
234
234
see :func:`.current_config`.
235
235
'''
236
- dir = includes_ [1 ]
237
- if not os .path .isabs (dir ):
238
- dir = os .path .join (eosfactory_data (), includes_ [1 ])
239
- if not os .path .exists (dir ):
240
- dir = None
241
- return dir
236
+ path = includes_ [1 ]
237
+ if not os .path .isabs (path ):
238
+ path = os .path .join (eosfactory_data (), includes_ [1 ])
239
+ if not os .path .exists (path ):
240
+ path = None
241
+ return path
242
242
243
243
244
244
def eoside_libs_dir ():
@@ -248,12 +248,12 @@ def eoside_libs_dir():
248
248
*LIBS* entry in the *config.json* file,
249
249
see :func:`.current_config`.
250
250
'''
251
- dir = libs_ [1 ]
252
- if not os .path .isabs (dir ):
253
- dir = os .path .join (eosfactory_data (), libs_ [1 ])
254
- if not os .path .exists (dir ):
255
- dir = None
256
- return dir
251
+ path = libs_ [1 ]
252
+ if not os .path .isabs (path ):
253
+ path = os .path .join (eosfactory_data (), libs_ [1 ])
254
+ if not os .path .exists (path ):
255
+ path = None
256
+ return path
257
257
258
258
259
259
def contract_workspace_dir (dont_set_workspace = False ):
@@ -390,9 +390,9 @@ def nodeos_config_dir():
390
390
*LOCAL_NODE_CONFIG_DIR* entry in the *config.json* file,
391
391
see :func:`.current_config`.
392
392
'''
393
- dir = first_valid_path (config_dir_ , raise_error = False )
394
- if dir :
395
- return dir
393
+ path = first_valid_path (config_dir_ , raise_error = False )
394
+ if path :
395
+ return path
396
396
397
397
return config_dir ()
398
398
@@ -587,13 +587,18 @@ def eosio_cpp_version():
587
587
return ["" , EOSIO_CDT_VERSION ]
588
588
589
589
590
- def eosio_cpp_dir ():
590
+ def eosio_cdt_root ():
591
591
'''The path to the *eosio-cpp* installation directory.
592
592
593
593
The setting may be changed with
594
594
*EOSIO_CPP* entry in the *config.json* file,
595
595
see :func:`.current_config`.
596
596
'''
597
+ # find /usr -wholename "*/eosio.cdt/1.6.1"
598
+ config_json = config_map ()
599
+ if eosio_cdt_root_ [0 ] in config_json and config_json [eosio_cdt_root_ [0 ]]:
600
+ return config_json [eosio_cdt_root_ [0 ]]
601
+
597
602
eosio_cpp_version_ = eosio_cpp_version ()
598
603
if not eosio_cpp_version_ :
599
604
raise errors .Error (
@@ -602,20 +607,25 @@ def eosio_cpp_dir():
602
607
''' )
603
608
604
609
version_pattern = re .compile (".+/eosio\.cdt/(\d\.\d\.\d)/$" )
605
- dir = eosio_cpp_dir_ [1 ][0 ]
606
- if not version_pattern .match (dir ):
607
- raise errors .Error (
608
- '''
609
- The assumed pattern
610
- {}
611
- does not match the directory template 'core.config.EOSIO_CPP_DIR'
612
- {}
613
- ''' .format (version_pattern , EOSIO_CPP_DIR ), translate = False
614
- )
615
- dir = dir .replace (
616
- re .findall (version_pattern , dir )[0 ], eosio_cpp_version_ [0 ])
610
+ tested = []
611
+ for path in eosio_cdt_root_ [1 ]:
612
+ tested .append (path )
613
+ if version_pattern .match (path ):
614
+ path = path .replace (
615
+ re .findall (version_pattern , path )[0 ], eosio_cpp_version_ [0 ])
616
+ if (os .path .exists (path )):
617
+ return path
617
618
618
- return dir
619
+ msg = "Cannot determine the installation directory of 'eosio-cdt. Tried:"
620
+ for path in tested :
621
+ msg = '''{}
622
+ {}
623
+ ''' .format (msg , path )
624
+ msg = '''{}
625
+ Define it in the config file
626
+ {}
627
+ ''' .format (msg , config_file ())
628
+ raise errors .Error (msg , translate = False )
619
629
620
630
621
631
def eosio_cpp_includes ():
@@ -625,9 +635,9 @@ def eosio_cpp_includes():
625
635
file, see :func:`.current_config`.
626
636
'''
627
637
list = []
628
- dir = eosio_cpp_dir ()
638
+ path = eosio_cdt_root ()
629
639
for include in eosio_cpp_includes_ [1 ][0 ]:
630
- list .append (dir + include )
640
+ list .append (path + include )
631
641
return list
632
642
633
643
@@ -1064,7 +1074,7 @@ def update_eosio_cpp_includes(c_cpp_properties_path, root=""):
1064
1074
1065
1075
if re .findall (dir_pattern , c_cpp_properties ):
1066
1076
new = c_cpp_properties .replace (re .findall (
1067
- dir_pattern , c_cpp_properties )[0 ], eosio_cpp_dir ())
1077
+ dir_pattern , c_cpp_properties )[0 ], eosio_cdt_root ())
1068
1078
if not new == c_cpp_properties :
1069
1079
with open (c_cpp_properties_path ,'w' ) as f :
1070
1080
f .write (new )
@@ -1082,12 +1092,13 @@ def installation_dependencies(config_map):
1082
1092
'''Verify whether 'eosio' and 'eosio.cpp' packages are properly installed.
1083
1093
'''
1084
1094
eosio_version_ = config_map ["EOSIO_VERSION" ]
1085
- if eosio_version_ :
1095
+ if eosio_version_ and eosio_version_ [ 0 ] :
1086
1096
if len (eosio_version_ ) > 1 :
1087
1097
print ('''NOTE!
1088
1098
The version of the installed 'eosio' package is {} while EOSFactory was tested
1089
1099
with version {}
1090
- ''' .format (eosio_version_ [0 ], eosio_version_ [1 ]))
1100
+ ''' .format (
1101
+ eosio_version_ [0 ], eosio_version_ [1 ]))
1091
1102
else :
1092
1103
print ('''Cannot determine the version of the installed 'eosio' package as 'nodeos' does not response.
1093
1104
''' )
@@ -1184,9 +1195,9 @@ def current_config(contract_dir=None, dont_set_workspace=False):
1184
1195
except :
1185
1196
map [eosio_cpp_ [0 ]] = None
1186
1197
try :
1187
- map [eosio_cpp_dir_ [0 ]] = eosio_cpp_dir ()
1198
+ map [eosio_cdt_root_ [0 ]] = eosio_cdt_root ()
1188
1199
except :
1189
- map [eosio_cpp_dir_ [0 ]] = None
1200
+ map [eosio_cdt_root_ [0 ]] = None
1190
1201
try :
1191
1202
map [eosio_cpp_includes_ [0 ]] = eosio_cpp_includes ()
1192
1203
except :
0 commit comments