Skip to content

Commit 6c044df

Browse files
all tested
1 parent cc1239a commit 6c044df

File tree

3 files changed

+162
-127
lines changed

3 files changed

+162
-127
lines changed

eosfactory/core/config.py

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
CONFIG_JSON = "config.json"
2727
CONTRACTS_DIR = "contracts/"
2828
TEMPLATE_DIR = ("TEMPLATE_DIR", "templates/contracts")
29-
EOSIO_CPP_DIR = "/usr/opt/eosio.cdt/0.0.0/"
3029

3130
eosfactory_data_ = ("EOSFACTORY_DATA_DIR",
3231
[os.path.expandvars("${HOME}/.local/" + EOSFACTORY_DIR),\
@@ -58,7 +57,8 @@
5857
["nodeos","/usr/bin/nodeos", "/usr/local/bin/nodeos"])
5958
eosio_cpp_ = ("EOSIO_CPP",
6059
["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"])
6262
eosio_cpp_includes_ = (
6363
"EOSIO_CPP_INCLUDES",
6464
[["include", "include/libcxx", "include/eosiolib/core", \
@@ -207,23 +207,23 @@ def set(contract_workspace_dir):
207207

208208

209209
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):
212212
raise errors.Error('''
213213
Cannot find the configuration directory
214214
{}
215-
'''.format(dir), translate=False)
216-
return dir
215+
'''.format(path), translate=False)
216+
return path
217217

218218

219219
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):
222222
raise errors.Error('''
223223
Cannot find the template directory
224224
{}
225-
'''.format(dir), translate=False)
226-
return dir
225+
'''.format(path), translate=False)
226+
return path
227227

228228

229229
def eoside_includes_dir():
@@ -233,12 +233,12 @@ def eoside_includes_dir():
233233
*INCLUDE* entry in the *config.json* file,
234234
see :func:`.current_config`.
235235
'''
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
242242

243243

244244
def eoside_libs_dir():
@@ -248,12 +248,12 @@ def eoside_libs_dir():
248248
*LIBS* entry in the *config.json* file,
249249
see :func:`.current_config`.
250250
'''
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
257257

258258

259259
def contract_workspace_dir(dont_set_workspace=False):
@@ -390,9 +390,9 @@ def nodeos_config_dir():
390390
*LOCAL_NODE_CONFIG_DIR* entry in the *config.json* file,
391391
see :func:`.current_config`.
392392
'''
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
396396

397397
return config_dir()
398398

@@ -587,13 +587,18 @@ def eosio_cpp_version():
587587
return ["", EOSIO_CDT_VERSION]
588588

589589

590-
def eosio_cpp_dir():
590+
def eosio_cdt_root():
591591
'''The path to the *eosio-cpp* installation directory.
592592
593593
The setting may be changed with
594594
*EOSIO_CPP* entry in the *config.json* file,
595595
see :func:`.current_config`.
596596
'''
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+
597602
eosio_cpp_version_ = eosio_cpp_version()
598603
if not eosio_cpp_version_:
599604
raise errors.Error(
@@ -602,20 +607,25 @@ def eosio_cpp_dir():
602607
''')
603608

604609
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
617618

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)
619629

620630

621631
def eosio_cpp_includes():
@@ -625,9 +635,9 @@ def eosio_cpp_includes():
625635
file, see :func:`.current_config`.
626636
'''
627637
list = []
628-
dir = eosio_cpp_dir()
638+
path = eosio_cdt_root()
629639
for include in eosio_cpp_includes_[1][0]:
630-
list.append(dir + include)
640+
list.append(path + include)
631641
return list
632642

633643

@@ -1064,7 +1074,7 @@ def update_eosio_cpp_includes(c_cpp_properties_path, root=""):
10641074

10651075
if re.findall(dir_pattern, c_cpp_properties):
10661076
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())
10681078
if not new == c_cpp_properties:
10691079
with open(c_cpp_properties_path,'w') as f:
10701080
f.write(new)
@@ -1082,12 +1092,13 @@ def installation_dependencies(config_map):
10821092
'''Verify whether 'eosio' and 'eosio.cpp' packages are properly installed.
10831093
'''
10841094
eosio_version_ = config_map["EOSIO_VERSION"]
1085-
if eosio_version_:
1095+
if eosio_version_ and eosio_version_[0]:
10861096
if len(eosio_version_) > 1:
10871097
print('''NOTE!
10881098
The version of the installed 'eosio' package is {} while EOSFactory was tested
10891099
with version {}
1090-
'''.format(eosio_version_[0], eosio_version_[1]))
1100+
'''.format(
1101+
eosio_version_[0], eosio_version_[1]))
10911102
else:
10921103
print('''Cannot determine the version of the installed 'eosio' package as 'nodeos' does not response.
10931104
''')
@@ -1184,9 +1195,9 @@ def current_config(contract_dir=None, dont_set_workspace=False):
11841195
except:
11851196
map[eosio_cpp_[0]] = None
11861197
try:
1187-
map[eosio_cpp_dir_[0]] = eosio_cpp_dir()
1198+
map[eosio_cdt_root_[0]] = eosio_cdt_root()
11881199
except:
1189-
map[eosio_cpp_dir_[0]] = None
1200+
map[eosio_cdt_root_[0]] = None
11901201
try:
11911202
map[eosio_cpp_includes_[0]] = eosio_cpp_includes()
11921203
except:

eosfactory/core/teos.py

Lines changed: 24 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ def build(
269269
print("######## command line sent to eosio-cpp:")
270270
print(" ".join(command_line))
271271

272-
eosio_cpp(command_line, build_dir)
273-
272+
utils.long_process(command_line, build_dir, is_verbose=True,
273+
prompt="eosio-cpp")
274274
if not compile_only:
275275
if "wasm" in target_path:
276276
logger.TRACE('''
@@ -502,107 +502,54 @@ def get_pid(name=None):
502502
return [int(pid) for pid in stdout.split()]
503503

504504

505-
def eosio_cpp(command_line, build_dir):
506-
stop = False
507-
PERIOD = 2
508-
def thread_function(name):
509-
while True:
510-
print(".", end="", flush=True)
511-
time.sleep(PERIOD)
512-
if stop:
513-
break
514-
515-
cwd = os.path.join(build_dir, "cwd")
516-
if os.path.exists(cwd):
517-
try:
518-
shutil.rmtree(cwd)
519-
except Exception as e:
520-
raise errors.Error('''
521-
Cannot remove the directory {}.
522-
error message:
523-
==============
524-
{}
525-
'''.format(cwd, str(e)))
526-
os.mkdir(cwd)
527-
528-
threading.Thread(target=thread_function, args=(1,)).start()
529-
p = subprocess.run(
530-
command_line,
531-
cwd=cwd,
532-
stdout=subprocess.PIPE,
533-
stderr=subprocess.PIPE)
534-
535-
stop = True
536-
time.sleep(PERIOD)
537-
print()
538-
stdout = p.stdout.decode("ISO-8859-1")
539-
stderr = p.stderr.decode("ISO-8859-1")
540-
returncode = p.returncode
541-
print(stdout)
542-
shutil.rmtree(cwd)
543-
544-
if returncode:
545-
raise errors.Error('''
546-
command line:
547-
=============
548-
{}
549-
550-
error message:
551-
==============
552-
{}
553-
'''.format(" ".join(command_line), stderr))
554-
555-
return returncode
556-
557-
558505
def get_target_dir(source_dir):
559506

560-
dir = os.path.join(source_dir, "build")
561-
if os.path.exists(dir):
562-
return dir
507+
path = os.path.join(source_dir, "build")
508+
if os.path.exists(path):
509+
return path
563510

564-
dir = os.path.join(source_dir, "..", "build")
565-
if os.path.exists(dir):
566-
return dir
511+
path = os.path.join(source_dir, "..", "build")
512+
if os.path.exists(path):
513+
return path
567514

568515
try:
569-
os.mkdir(dir)
516+
os.mkdir(path)
570517
except Exception as e:
571518
raise errors.Error(str(e))
572519

573-
return dir
520+
return path
574521

575522

576523
def get_recardian_dir(source_dir):
577524

578-
dir = os.path.join(source_dir, "..", "ricardian")
579-
if os.path.exists(dir):
580-
return dir
525+
path = os.path.join(source_dir, "..", "ricardian")
526+
if os.path.exists(path):
527+
return path
581528

582-
dir = os.path.join(source_dir, "ricardian")
583-
if not os.path.exists(dir):
529+
path = os.path.join(source_dir, "ricardian")
530+
if not os.path.exists(path):
584531
try:
585-
os.mkdir(dir)
532+
os.mkdir(path)
586533
except Exception as e:
587534
raise errors.Error(str(e))
588535

589-
return dir
536+
return path
590537

591538

592539
def get_include_dir(source_dir):
593540

594-
dir = os.path.join(source_dir, "..", "include")
595-
if os.path.exists(dir):
596-
return dir
541+
path = os.path.join(source_dir, "..", "include")
542+
if os.path.exists(path):
543+
return path
597544

598-
dir = os.path.join(source_dir, "include")
599-
if not os.path.exists(dir):
545+
path = os.path.join(source_dir, "include")
546+
if not os.path.exists(path):
600547
try:
601-
os.mkdir(dir)
548+
os.mkdir(path)
602549
except Exception as e:
603550
raise errors.Error(str(e))
604551

605-
return dir
552+
return path
606553

607554

608555
def args(clear=False):

0 commit comments

Comments
 (0)