Skip to content

Commit fbad738

Browse files
authored
Merge pull request #610 from crytic/foundry-detect-out
Auto-detect Foundry `out` directory
2 parents a52de85 + b491c24 commit fbad738

File tree

4 files changed

+49
-18
lines changed

4 files changed

+49
-18
lines changed

crytic_compile/cryticparser/defaults.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"hardhat_cache_directory": None,
4545
"hardhat_artifacts_directory": None,
4646
"foundry_ignore_compile": False,
47-
"foundry_out_directory": "out",
47+
"foundry_out_directory": None,
4848
"foundry_compile_all": False,
4949
"export_dir": "crytic-export",
5050
"compile_libraries": None,

crytic_compile/platform/abstract_platform.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class PlatformConfig:
4242
tests_path: str = "test"
4343
libs_path: List[str] = field(default_factory=lambda: ["lib"])
4444
scripts_path: str = "script"
45+
out_path: str = "out"
4546

4647

4748
class AbstractPlatform(metaclass=abc.ABCMeta):

crytic_compile/platform/foundry.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
5353
"ignore_compile", False
5454
)
5555

56-
out_directory = kwargs.get("foundry_out_directory", "out")
56+
foundry_config = None
5757

5858
if ignore_compile:
5959
LOGGER.info(
@@ -74,21 +74,25 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
7474

7575
compile_all = kwargs.get("foundry_compile_all", False)
7676

77-
if not targeted_build and not compile_all:
78-
foundry_config = self.config(self._project_root)
79-
if foundry_config:
80-
compilation_command += [
81-
"--skip",
82-
f"./{foundry_config.tests_path}/**",
83-
f"./{foundry_config.scripts_path}/**",
84-
"--force",
85-
]
77+
foundry_config = self.config(self._project_root)
78+
79+
if not targeted_build and not compile_all and foundry_config:
80+
compilation_command += [
81+
"--skip",
82+
f"./{foundry_config.tests_path}/**",
83+
f"./{foundry_config.scripts_path}/**",
84+
"--force",
85+
]
8686

8787
run(
8888
compilation_command,
8989
cwd=self._project_root,
9090
)
9191

92+
out_directory_detected = foundry_config.out_path if foundry_config else "out"
93+
out_directory_config = kwargs.get("foundry_out_directory", None)
94+
out_directory = out_directory_config if out_directory_config else out_directory_detected
95+
9296
build_directory = Path(
9397
self._project_root,
9498
out_directory,
@@ -195,6 +199,7 @@ def config(working_dir: Union[str, Path]) -> Optional[PlatformConfig]:
195199
result.tests_path = json_config.get("test")
196200
result.libs_path = json_config.get("libs")
197201
result.scripts_path = json_config.get("script")
202+
result.out_path = json_config.get("out")
198203

199204
return result
200205

scripts/ci_test_foundry.sh

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/usr/bin/env bash
2-
32
### Test foundry integration
3+
set -Eeuxo pipefail
44

55

6-
cd /tmp || exit 255
6+
## test 1 - same folder
77

8+
cd /tmp || exit 255
89
mkdir forge_test
910
cd forge_test || exit 255
10-
forge init --no-commit
11+
forge init
1112

1213
crytic-compile .
1314
if [ $? -ne 0 ]
@@ -16,11 +17,35 @@ then
1617
exit 255
1718
fi
1819

19-
mkdir /tmp/forge_test/test_2
20-
rsync -a --exclude='test_2' ./ /tmp/forge_test/test_2/
21-
crytic-compile ./test_2
20+
21+
## test 2 - same folder, different out dir
22+
23+
cd /tmp || exit 255
24+
mkdir forge_test2
25+
cd forge_test2 || exit 255
26+
forge init
27+
28+
sed -i 's/^out\s*=.*$/out = "foobar"/' foundry.toml
29+
30+
crytic-compile .
2231
if [ $? -ne 0 ]
2332
then
2433
echo "foundry test 2 failed"
2534
exit 255
26-
fi
35+
fi
36+
37+
## test 3 - different folder
38+
39+
cd /tmp || exit 255
40+
mkdir forge_test3
41+
cd forge_test3 || exit 255
42+
forge init
43+
44+
cd /tmp || exit 255
45+
46+
crytic-compile ./forge_test3
47+
if [ $? -ne 0 ]
48+
then
49+
echo "foundry test 3 failed"
50+
exit 255
51+
fi

0 commit comments

Comments
 (0)