Skip to content

Commit

Permalink
Merge pull request #433 from samalws-tob/relativeFilepath
Browse files Browse the repository at this point in the history
Fix --allow-paths argument in solc.py
  • Loading branch information
montyly authored Jun 23, 2023
2 parents ce39468 + 6522b8d commit 5fa747c
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions crytic_compile/platform/solc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -521,15 +521,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 "," in file_dir:
try:
file_dir = os.path.relpath(file_dir_start)
except ValueError:
pass

if "," not in file_dir:
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:
LOGGER.info(
"'%s' running",
Expand Down

0 comments on commit 5fa747c

Please sign in to comment.