Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple compilation units #167

Merged
merged 7 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crytic_compile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from .crytic_compile import CryticCompile, compile_all, is_supported
from .compilation_unit import CompilationUnit
from .cryticparser import cryticparser
from .platform import InvalidCompilation
from .utils.zip import save_to_zip
34 changes: 24 additions & 10 deletions crytic_compile/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
import os
import sys
from typing import TYPE_CHECKING

from pkg_resources import require

Expand All @@ -14,6 +15,10 @@
from crytic_compile.platform import InvalidCompilation
from crytic_compile.utils.zip import ZIP_TYPES_ACCEPTED, save_to_zip

if TYPE_CHECKING:
from crytic_compile import CryticCompile


logging.basicConfig()
LOGGER = logging.getLogger("CryticCompile")
LOGGER.setLevel(logging.INFO)
Expand Down Expand Up @@ -145,6 +150,23 @@ def __call__(self, parser, args, values, option_string=None):
parser.exit()


def _print_filenames(compilation: "CryticCompile"):
printed_filenames = set()
for compilation_id, compilation_unit in compilation.compilation_units.items():
print(
f"Compilation unit: {compilation_id} ({len(compilation_unit.contracts_names)} files, solc {compilation_unit.compiler_version.version})"
)
for contract in compilation_unit.contracts_names:
filename = compilation_unit.filename_of_contract(contract)
unique_id = f"{contract} - {filename} - {compilation_id}"
if unique_id not in printed_filenames:
print(f"\t{contract} -> \n\tAbsolute: {filename.absolute}")
print(f"\t\tRelative: {filename.relative}")
print(f"\t\tShort: {filename.short}")
print(f"\t\tUsed: {filename.used}")
printed_filenames.add(unique_id)


def main():
"""
Main function run from the cli
Expand All @@ -157,19 +179,11 @@ def main():
compilations = compile_all(**vars(args))

# Perform relevant tasks for each compilation
printed_filenames = set()
# print(compilations[0].compilation_units)
for compilation in compilations:
# Print the filename of each contract (no duplicates).
if args.print_filename:
for contract in compilation.contracts_names:
filename = compilation.filename_of_contract(contract)
unique_id = f"{contract} - {filename}"
if unique_id not in printed_filenames:
print(f"{contract} -> \n\tAbsolute: {filename.absolute}")
print(f"\tRelative: {filename.relative}")
print(f"\tShort: {filename.short}")
print(f"\tUsed: {filename.used}")
printed_filenames.add(unique_id)
_print_filenames(compilation)
if args.export_format:
compilation.export(**vars(args))

Expand Down
Loading