Skip to content

Commit 5fa747c

Browse files
authored
Merge pull request #433 from samalws-tob/relativeFilepath
Fix --allow-paths argument in solc.py
2 parents ce39468 + 6522b8d commit 5fa747c

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

crytic_compile/platform/solc.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def _build_options(compiler_version: CompilerVersion, force_legacy_json: bool) -
444444
return "abi,ast,bin,bin-runtime,srcmap,srcmap-runtime,userdoc,devdoc,hashes"
445445

446446

447-
# pylint: disable=too-many-arguments,too-many-locals,too-many-branches
447+
# pylint: disable=too-many-arguments,too-many-locals,too-many-branches,too-many-statements
448448
def _run_solc(
449449
compilation_unit: "CompilationUnit",
450450
filename: str,
@@ -521,15 +521,21 @@ def _run_solc(
521521
if not compiler_version.version in [f"0.4.{x}" for x in range(0, 11)]:
522522
# Add . as default allowed path
523523
if "--allow-paths" not in cmd:
524-
relative_filepath = filename
525-
526-
if not working_dir:
527-
working_dir = os.getcwd()
528-
529-
if relative_filepath.startswith(str(working_dir)):
530-
relative_filepath = relative_filepath[len(str(working_dir)) + 1 :]
524+
file_dir_start = os.path.normpath(os.path.dirname(filename))
525+
file_dir = os.path.abspath(file_dir_start)
526+
if "," in file_dir:
527+
try:
528+
file_dir = os.path.relpath(file_dir_start)
529+
except ValueError:
530+
pass
531+
532+
if "," not in file_dir:
533+
cmd += ["--allow-paths", ".," + file_dir]
534+
else:
535+
LOGGER.warning(
536+
"Solc filepath contains a comma; omitting the --allow-paths argument. This may result in failed imports.\n"
537+
)
531538

532-
cmd += ["--allow-paths", ".", relative_filepath]
533539
try:
534540
LOGGER.info(
535541
"'%s' running",

0 commit comments

Comments
 (0)