Skip to content

Commit

Permalink
Merge pull request #57 from multiversx/skip-rust-target-folder
Browse files Browse the repository at this point in the history
Skip Rust files from "target" folder
  • Loading branch information
andreibancioiu authored May 8, 2024
2 parents a70c86a + 59a43f2 commit 50a6d69
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install pytest
- name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM ubuntu:22.04

# Constants
ARG BUILDER_NAME="multiversx/sdk-rust-contract-builder:v6.1.1"
ARG BUILDER_NAME="multiversx/sdk-rust-contract-builder:v6.1.2"
ARG VERSION_RUST="nightly-2023-12-11"
ARG VERSION_BINARYEN="version_112"
ARG DOWNLOAD_URL_BINARYEN="https://github.com/WebAssembly/binaryen/releases/download/${VERSION_BINARYEN}/binaryen-${VERSION_BINARYEN}-x86_64-linux.tar.gz"
Expand Down
29 changes: 27 additions & 2 deletions integration_tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

from integration_tests.config import PARENT_OUTPUT_FOLDER
from integration_tests.shared import download_project_repository, run_docker
from multiversx_sdk_rust_contract_builder.packaged_source_code import \
PackagedSourceCode


def test_with_symlinks():
workspace_parent = download_project_repository("https://github.com/multiversx/mx-contracts-rs/archive/refs/tags/v0.45.2.2.zip", "test_with_symlinks")
workspace = workspace_parent / "mx-contracts-rs-0.45.2.2"
workspace_parent = download_project_repository("https://github.com/multiversx/mx-contracts-rs/archive/refs/tags/v0.45.4.zip", "test_with_symlinks")
workspace = workspace_parent / "mx-contracts-rs-0.45.4"

output_folder = PARENT_OUTPUT_FOLDER / "test_with_symlinks"
shutil.rmtree(output_folder, ignore_errors=True)
Expand All @@ -31,3 +33,26 @@ def test_with_symlinks():
)

assert (output_folder / "artifacts.json").exists()


def test_has_correct_packaged_source():
workspace_parent = download_project_repository("https://github.com/multiversx/mx-contracts-rs/archive/refs/tags/v0.45.4.zip", "test_with_symlinks")
workspace = workspace_parent / "mx-contracts-rs-0.45.4"

output_folder = PARENT_OUTPUT_FOLDER / "test_has_correct_packaged_source"
shutil.rmtree(output_folder, ignore_errors=True)
output_folder.mkdir(parents=True, exist_ok=True)

run_docker(
project_path=workspace,
packaged_src_path=None,
contract_name="adder",
image="sdk-rust-contract-builder:next",
output_folder=output_folder
)

packaged_source_code = PackagedSourceCode.from_file(output_folder / "adder" / "adder-0.0.0.source.json")

for entry in packaged_source_code.entries:
assert not str(entry.path).startswith("target"), f"Unexpected file: {entry.path}"
assert entry.is_test_file == ("test" in str(entry.path)), f"Unexpected is_test_file marker for: {entry.path}"
4 changes: 2 additions & 2 deletions multiversx_sdk_rust_contract_builder/packaged_source_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ def from_dict(cls, dict: Dict[str, Any]) -> 'PackagedSourceCodeEntry':
path = Path(dict.get("path", ""))
content = base64.b64decode(dict.get("content", ""))
module = Path(dict.get("module", ""))
dependency_depth = dict.get("dependency_depth", sys.maxsize)
is_test_file = dict.get("is_test_file", False)
dependency_depth = dict.get("dependencyDepth", sys.maxsize)
is_test_file = dict.get("isTestFile", False)

return PackagedSourceCodeEntry(path, content, module, dependency_depth, is_test_file)

Expand Down
25 changes: 16 additions & 9 deletions multiversx_sdk_rust_contract_builder/source_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_source_code_files(
source_code_files: List[SourceCodeFile] = []

# First, add the contract itself
files = get_all_files(contract_folder, _is_source_code_file)
files = _get_source_code_files(contract_folder)
for file in files:
source_code_files.append(SourceCodeFile(file, contract_folder, 0))

Expand All @@ -42,28 +42,35 @@ def get_source_code_files(
if not dependency_folder.exists():
raise ErrKnown(f"Dependency does not exist: {dependency_folder}")

files = get_all_files(dependency_folder, _is_source_code_file)
files = _get_source_code_files(dependency_folder)
for file in files:
source_code_files.append(SourceCodeFile(file, dependency_folder, dependency_depth))

# Finally, add remaining files (unrelated to contract), if desired
files_related_to_contract = set(file.path for file in source_code_files)

if include_unrelated_to_contract:
all_files = get_all_files(project_folder, _is_source_code_file)
all_files = _get_source_code_files(project_folder)
for file in all_files:
if file not in files_related_to_contract:
source_code_files.append(SourceCodeFile(file, contract_folder, sys.maxsize))

return source_code_files


def _is_source_code_file(path: Path) -> bool:
if path.suffix == ".rs":
return True
if path.name in ["Cargo.toml", "Cargo.lock", "multicontract.toml", "sc-config.toml", CONTRACT_CONFIG_FILENAME]:
return True
return False
def _get_source_code_files(project_folder: Path) -> List[Path]:
all_files = get_all_files(project_folder)

def is_source_code_file(path: Path) -> bool:
if path.is_relative_to(project_folder / "target"):
return False
if path.suffix == ".rs":
return True
if path.name in ["Cargo.toml", "Cargo.lock", "multicontract.toml", "sc-config.toml", CONTRACT_CONFIG_FILENAME]:
return True
return False

return [path for path in all_files if is_source_code_file(path)]


def _get_local_dependencies(project_folder: Path, contract_folder: Path) -> List[Dict[str, Any]]:
Expand Down

0 comments on commit 50a6d69

Please sign in to comment.