From a0319758b44d1d2f1639b968164d24b4548d888a Mon Sep 17 00:00:00 2001 From: Sam Alws Date: Thu, 11 May 2023 22:14:15 -0400 Subject: [PATCH 1/2] Fix --allow-paths argument in solc.py --- crytic_compile/platform/solc.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/crytic_compile/platform/solc.py b/crytic_compile/platform/solc.py index eb000442..55d94c01 100644 --- a/crytic_compile/platform/solc.py +++ b/crytic_compile/platform/solc.py @@ -517,15 +517,21 @@ def _run_solc( if not compiler_version.version in [f"0.4.{x}" for x in range(0, 11)]: # Add . as default allowed path if "--allow-paths" not in cmd: - relative_filepath = filename - - if not working_dir: - working_dir = os.getcwd() - - if relative_filepath.startswith(str(working_dir)): - relative_filepath = relative_filepath[len(str(working_dir)) + 1 :] + file_dir_start = os.path.normpath(os.path.dirname(filename)) + file_dir = os.path.abspath(file_dir_start) + if file_dir.find(",") != -1: + try: + file_dir = os.path.relpath(file_dir_start) + except ValueError: + pass + + if file_dir.find(",") == -1: + cmd += ["--allow-paths", ".," + file_dir] + else: + LOGGER.warning( + "Solc filepath contains a comma; omitting the --allow-paths argument. This may result in failed imports.\n" + ) - cmd += ["--allow-paths", ".", relative_filepath] try: # pylint: disable=consider-using-with if env: From 6522b8d7eebcaa8d436b4aa0315f69dafc82d566 Mon Sep 17 00:00:00 2001 From: Sam Alws Date: Thu, 15 Jun 2023 15:31:10 -0400 Subject: [PATCH 2/2] code cleanup: find(...) != -1 -> not in --- crytic_compile/platform/solc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crytic_compile/platform/solc.py b/crytic_compile/platform/solc.py index b568cdb4..71bdd1db 100644 --- a/crytic_compile/platform/solc.py +++ b/crytic_compile/platform/solc.py @@ -444,7 +444,7 @@ def _build_options(compiler_version: CompilerVersion, force_legacy_json: bool) - return "abi,ast,bin,bin-runtime,srcmap,srcmap-runtime,userdoc,devdoc,hashes" -# pylint: disable=too-many-arguments,too-many-locals,too-many-branches +# pylint: disable=too-many-arguments,too-many-locals,too-many-branches,too-many-statements def _run_solc( compilation_unit: "CompilationUnit", filename: str, @@ -523,13 +523,13 @@ def _run_solc( if "--allow-paths" not in cmd: file_dir_start = os.path.normpath(os.path.dirname(filename)) file_dir = os.path.abspath(file_dir_start) - if file_dir.find(",") != -1: + if "," in file_dir: try: file_dir = os.path.relpath(file_dir_start) except ValueError: pass - if file_dir.find(",") == -1: + if "," not in file_dir: cmd += ["--allow-paths", ".," + file_dir] else: LOGGER.warning(