Platform detection check

pull/1384/head
Emilio López 2 years ago
parent 7e6ccbb58d
commit de1b7618b7
  1. 65
      slither/tools/doctor/__main__.py

@ -1,21 +1,9 @@
import argparse import argparse
import logging from pathlib import Path
from crytic_compile import cryticparser from crytic_compile import cryticparser
import crytic_compile.crytic_compile as crytic_compile
from slither.utils.colors import red, yellow, green
logging.basicConfig()
logging.getLogger("Slither").setLevel(logging.INFO)
logger = logging.getLogger("Slither-doctor")
logger.setLevel(logging.INFO)
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
formatter = logging.Formatter("%(message)s")
logger.addHandler(ch)
logger.handlers[0].setFormatter(formatter)
logger.propagate = False
def parse_args(): def parse_args():
@ -36,10 +24,55 @@ def parse_args():
return parser.parse_args() return parser.parse_args()
def detect_platform(project: str, **kwargs):
print("## Project platform")
print()
path = Path(project)
if path.is_file():
print(
yellow(
f"{project!r} is a file. Using it as target will manually compile your code with solc and _not_ use a compilation framework. Is that what you meant to do?"
)
)
return
print(f"Trying to detect project type for {project!r}")
supported_platforms = crytic_compile.get_platforms()
skip_platforms = {"solc", "solc-json", "archive", "standard", "etherscan"}
detected_platforms = {
platform.NAME: platform.is_supported(project, **kwargs)
for platform in supported_platforms
if platform.NAME.lower() not in skip_platforms
}
platform_qty = len([platform for platform, state in detected_platforms.items() if state])
print("Is this project using...")
for platform, state in detected_platforms.items():
print(f" => {platform + '?':<15}{state and green('Yes') or red('No')}")
print()
if platform_qty == 0:
print(red("No platform was detected! This doesn't sound right."))
print(
yellow(
"Are you trying to analyze a folder with standalone solidity files, without using a compilation framework? If that's the case, then this is okay."
)
)
elif platform_qty > 1:
print(red("More than one platform was detected! This doesn't sound right."))
print(red("Please use `--compile-force-framework` in Slither to force the correct framework."))
else:
print(green("A single platform was detected."), yellow("Is it the one you expected?"))
def main(): def main():
args = parse_args() args = parse_args()
print("Hello world") detect_platform(args.project)
# TODO other checks
if __name__ == "__main__": if __name__ == "__main__":

Loading…
Cancel
Save