Skip to content

Commit

Permalink
all tested
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanzarembinski committed May 2, 2019
1 parent cc1239a commit 6c044df
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 127 deletions.
103 changes: 57 additions & 46 deletions eosfactory/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
CONFIG_JSON = "config.json"
CONTRACTS_DIR = "contracts/"
TEMPLATE_DIR = ("TEMPLATE_DIR", "templates/contracts")
EOSIO_CPP_DIR = "/usr/opt/eosio.cdt/0.0.0/"

eosfactory_data_ = ("EOSFACTORY_DATA_DIR",
[os.path.expandvars("${HOME}/.local/" + EOSFACTORY_DIR),\
Expand Down Expand Up @@ -58,7 +57,8 @@
["nodeos","/usr/bin/nodeos", "/usr/local/bin/nodeos"])
eosio_cpp_ = ("EOSIO_CPP",
["eosio-cpp", "/usr/bin/eosio-cpp", "/usr/local/bin/eosio-cpp"])
eosio_cpp_dir_ = ("EOSIO_CPP_DIR", [EOSIO_CPP_DIR])
eosio_cdt_root_ = ("EOSIO_CDT_ROOT",
["/usr/opt/eosio.cdt/0.0.0/", "/usr/local/Cellar/eosio.cdt/0.0.0"])
eosio_cpp_includes_ = (
"EOSIO_CPP_INCLUDES",
[["include", "include/libcxx", "include/eosiolib/core", \
Expand Down Expand Up @@ -207,23 +207,23 @@ def set(contract_workspace_dir):


def config_dir():
dir = os.path.join(eosfactory_data(), CONFIG_DIR)
if not os.path.exists(dir):
path = os.path.join(eosfactory_data(), CONFIG_DIR)
if not os.path.exists(path):
raise errors.Error('''
Cannot find the configuration directory
{}
'''.format(dir), translate=False)
return dir
'''.format(path), translate=False)
return path


def template_dir():
dir = os.path.join(eosfactory_data(), TEMPLATE_DIR[1])
if not os.path.exists(dir):
path = os.path.join(eosfactory_data(), TEMPLATE_DIR[1])
if not os.path.exists(path):
raise errors.Error('''
Cannot find the template directory
{}
'''.format(dir), translate=False)
return dir
'''.format(path), translate=False)
return path


def eoside_includes_dir():
Expand All @@ -233,12 +233,12 @@ def eoside_includes_dir():
*INCLUDE* entry in the *config.json* file,
see :func:`.current_config`.
'''
dir = includes_[1]
if not os.path.isabs(dir):
dir = os.path.join(eosfactory_data(), includes_[1])
if not os.path.exists(dir):
dir = None
return dir
path = includes_[1]
if not os.path.isabs(path):
path = os.path.join(eosfactory_data(), includes_[1])
if not os.path.exists(path):
path = None
return path


def eoside_libs_dir():
Expand All @@ -248,12 +248,12 @@ def eoside_libs_dir():
*LIBS* entry in the *config.json* file,
see :func:`.current_config`.
'''
dir = libs_[1]
if not os.path.isabs(dir):
dir = os.path.join(eosfactory_data(), libs_[1])
if not os.path.exists(dir):
dir = None
return dir
path = libs_[1]
if not os.path.isabs(path):
path = os.path.join(eosfactory_data(), libs_[1])
if not os.path.exists(path):
path = None
return path


def contract_workspace_dir(dont_set_workspace=False):
Expand Down Expand Up @@ -390,9 +390,9 @@ def nodeos_config_dir():
*LOCAL_NODE_CONFIG_DIR* entry in the *config.json* file,
see :func:`.current_config`.
'''
dir = first_valid_path(config_dir_, raise_error=False)
if dir:
return dir
path = first_valid_path(config_dir_, raise_error=False)
if path:
return path

return config_dir()

Expand Down Expand Up @@ -587,13 +587,18 @@ def eosio_cpp_version():
return ["", EOSIO_CDT_VERSION]


def eosio_cpp_dir():
def eosio_cdt_root():
'''The path to the *eosio-cpp* installation directory.
The setting may be changed with
*EOSIO_CPP* entry in the *config.json* file,
see :func:`.current_config`.
'''
# find /usr -wholename "*/eosio.cdt/1.6.1"
config_json = config_map()
if eosio_cdt_root_[0] in config_json and config_json[eosio_cdt_root_[0]]:
return config_json[eosio_cdt_root_[0]]

eosio_cpp_version_ = eosio_cpp_version()
if not eosio_cpp_version_:
raise errors.Error(
Expand All @@ -602,20 +607,25 @@ def eosio_cpp_dir():
''')

version_pattern = re.compile(".+/eosio\.cdt/(\d\.\d\.\d)/$")
dir = eosio_cpp_dir_[1][0]
if not version_pattern.match(dir):
raise errors.Error(
'''
The assumed pattern
{}
does not match the directory template 'core.config.EOSIO_CPP_DIR'
{}
'''.format(version_pattern, EOSIO_CPP_DIR), translate=False
)
dir = dir.replace(
re.findall(version_pattern, dir)[0], eosio_cpp_version_[0])
tested = []
for path in eosio_cdt_root_[1]:
tested.append(path)
if version_pattern.match(path):
path = path.replace(
re.findall(version_pattern, path)[0], eosio_cpp_version_[0])
if(os.path.exists(path)):
return path

return dir
msg = "Cannot determine the installation directory of 'eosio-cdt. Tried:"
for path in tested:
msg = '''{}
{}
'''.format(msg, path)
msg = '''{}
Define it in the config file
{}
'''.format(msg, config_file())
raise errors.Error(msg, translate=False)


def eosio_cpp_includes():
Expand All @@ -625,9 +635,9 @@ def eosio_cpp_includes():
file, see :func:`.current_config`.
'''
list = []
dir = eosio_cpp_dir()
path = eosio_cdt_root()
for include in eosio_cpp_includes_[1][0]:
list.append(dir + include)
list.append(path + include)
return list


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

if re.findall(dir_pattern, c_cpp_properties):
new = c_cpp_properties.replace(re.findall(
dir_pattern, c_cpp_properties)[0], eosio_cpp_dir())
dir_pattern, c_cpp_properties)[0], eosio_cdt_root())
if not new == c_cpp_properties:
with open(c_cpp_properties_path,'w') as f:
f.write(new)
Expand All @@ -1082,12 +1092,13 @@ def installation_dependencies(config_map):
'''Verify whether 'eosio' and 'eosio.cpp' packages are properly installed.
'''
eosio_version_ = config_map["EOSIO_VERSION"]
if eosio_version_:
if eosio_version_ and eosio_version_[0]:
if len(eosio_version_) > 1:
print('''NOTE!
The version of the installed 'eosio' package is {} while EOSFactory was tested
with version {}
'''.format(eosio_version_[0], eosio_version_[1]))
'''.format(
eosio_version_[0], eosio_version_[1]))
else:
print('''Cannot determine the version of the installed 'eosio' package as 'nodeos' does not response.
''')
Expand Down Expand Up @@ -1184,9 +1195,9 @@ def current_config(contract_dir=None, dont_set_workspace=False):
except:
map[eosio_cpp_[0]] = None
try:
map[eosio_cpp_dir_[0]] = eosio_cpp_dir()
map[eosio_cdt_root_[0]] = eosio_cdt_root()
except:
map[eosio_cpp_dir_[0]] = None
map[eosio_cdt_root_[0]] = None
try:
map[eosio_cpp_includes_[0]] = eosio_cpp_includes()
except:
Expand Down
101 changes: 24 additions & 77 deletions eosfactory/core/teos.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ def build(
print("######## command line sent to eosio-cpp:")
print(" ".join(command_line))

eosio_cpp(command_line, build_dir)

utils.long_process(command_line, build_dir, is_verbose=True,
prompt="eosio-cpp")
if not compile_only:
if "wasm" in target_path:
logger.TRACE('''
Expand Down Expand Up @@ -502,107 +502,54 @@ def get_pid(name=None):
return [int(pid) for pid in stdout.split()]


def eosio_cpp(command_line, build_dir):
stop = False
PERIOD = 2
def thread_function(name):
while True:
print(".", end="", flush=True)
time.sleep(PERIOD)
if stop:
break

cwd = os.path.join(build_dir, "cwd")
if os.path.exists(cwd):
try:
shutil.rmtree(cwd)
except Exception as e:
raise errors.Error('''
Cannot remove the directory {}.
error message:
==============
{}
'''.format(cwd, str(e)))
os.mkdir(cwd)

threading.Thread(target=thread_function, args=(1,)).start()
p = subprocess.run(
command_line,
cwd=cwd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)

stop = True
time.sleep(PERIOD)
print()
stdout = p.stdout.decode("ISO-8859-1")
stderr = p.stderr.decode("ISO-8859-1")
returncode = p.returncode
print(stdout)
shutil.rmtree(cwd)

if returncode:
raise errors.Error('''
command line:
=============
{}
error message:
==============
{}
'''.format(" ".join(command_line), stderr))

return returncode


def get_target_dir(source_dir):

dir = os.path.join(source_dir, "build")
if os.path.exists(dir):
return dir
path = os.path.join(source_dir, "build")
if os.path.exists(path):
return path

dir = os.path.join(source_dir, "..", "build")
if os.path.exists(dir):
return dir
path = os.path.join(source_dir, "..", "build")
if os.path.exists(path):
return path

try:
os.mkdir(dir)
os.mkdir(path)
except Exception as e:
raise errors.Error(str(e))

return dir
return path


def get_recardian_dir(source_dir):

dir = os.path.join(source_dir, "..", "ricardian")
if os.path.exists(dir):
return dir
path = os.path.join(source_dir, "..", "ricardian")
if os.path.exists(path):
return path

dir = os.path.join(source_dir, "ricardian")
if not os.path.exists(dir):
path = os.path.join(source_dir, "ricardian")
if not os.path.exists(path):
try:
os.mkdir(dir)
os.mkdir(path)
except Exception as e:
raise errors.Error(str(e))

return dir
return path


def get_include_dir(source_dir):

dir = os.path.join(source_dir, "..", "include")
if os.path.exists(dir):
return dir
path = os.path.join(source_dir, "..", "include")
if os.path.exists(path):
return path

dir = os.path.join(source_dir, "include")
if not os.path.exists(dir):
path = os.path.join(source_dir, "include")
if not os.path.exists(path):
try:
os.mkdir(dir)
os.mkdir(path)
except Exception as e:
raise errors.Error(str(e))

return dir
return path


def args(clear=False):
Expand Down
Loading

0 comments on commit 6c044df

Please sign in to comment.