crytic / crytic-compile

Abstraction layer for smart contract build systems
GNU Affero General Public License v3.0
157 stars 84 forks source link

traverse file tree to discover config file #538

Open 0xalpharush opened 10 months ago

0xalpharush commented 10 months ago
          On a second look, I think target is always a directory here, so scratch that last part of my comment.

Unrelated to this PR, but I think the check here may be a bit off, wouldn't it make more sense to look for the foundry/etc project in the path of the file rather than in cwd? e.g. if the file is /a/b/c/d/contracts/foo.sol, I'd check to see if any of [/a/b/c/d/contracts, /a/b/c/d, /a/b/c, /a/b, /a, /] is a project. Most users are probably going to be running the tool with cwd=the project folder, so it may work as-is now, but it doesn't feel completely correct.

_Originally posted by @elopez in https://github.com/crytic/crytic-compile/pull/515#discussion_r1386619499_

Something like this:

                config_root = self._working_dir
                while os.path.realpath(config_root) != os.path.realpath("/"):
                    platform_wd = next(
                        (
                            p(target)
                            for p in get_platforms()
                            if p.is_supported(str(config_root), **kwargs)
                        ),
                        None,
                    )
                    if platform_wd:
                        break
                    config_root = os.path.dirname(config_root)

We should search for the config file before falling back to best-effort, standard json compilation here: https://github.com/crytic/crytic-compile/blob/3a4b0de72ad418b60b9ef8c38d7de31ed39e3898/crytic_compile/crytic_compile.py#L719