From f05796568de8525d3069bfa2f04cd565bf23c608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Fri, 10 May 2024 16:56:05 +0300 Subject: [PATCH 1/3] Handle custom build root. --- multiversx_sdk_rust_contract_builder/builder.py | 2 +- multiversx_sdk_rust_contract_builder/main.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/multiversx_sdk_rust_contract_builder/builder.py b/multiversx_sdk_rust_contract_builder/builder.py index c227d6c..2628a01 100644 --- a/multiversx_sdk_rust_contract_builder/builder.py +++ b/multiversx_sdk_rust_contract_builder/builder.py @@ -118,7 +118,7 @@ def ensure_distinct_contract_names(contracts_folders: List[Path]): def copy_project_folder_to_build_folder(project_folder: Path, build_root_folder: Path): shutil.rmtree(build_root_folder, ignore_errors=True) - build_root_folder.mkdir() + build_root_folder.mkdir(parents=True, exist_ok=True) shutil.copytree( project_folder, build_root_folder, diff --git a/multiversx_sdk_rust_contract_builder/main.py b/multiversx_sdk_rust_contract_builder/main.py index 755eefa..36818fc 100644 --- a/multiversx_sdk_rust_contract_builder/main.py +++ b/multiversx_sdk_rust_contract_builder/main.py @@ -50,6 +50,7 @@ def main(cli_args: List[str]): shutil.rmtree(HARDCODED_UNWRAP_FOLDER, ignore_errors=True) packaged = PackagedSourceCode.from_file(packaged_src_path) packaged.unwrap_to_filesystem(HARDCODED_UNWRAP_FOLDER) + build_root = packaged.metadata.build_options.get("buildRootFolder", build_root) metadata = BuildMetadata.from_env() From 5accc1b84a9a2236e764da0724bc8ca142e6a3a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Mon, 27 May 2024 20:34:05 +0300 Subject: [PATCH 2/3] Fix passing of custom build root. --- multiversx_sdk_rust_contract_builder/builder.py | 2 +- multiversx_sdk_rust_contract_builder/main.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/multiversx_sdk_rust_contract_builder/builder.py b/multiversx_sdk_rust_contract_builder/builder.py index 2628a01..2c6be5d 100644 --- a/multiversx_sdk_rust_contract_builder/builder.py +++ b/multiversx_sdk_rust_contract_builder/builder.py @@ -33,7 +33,7 @@ def build_project( cargo_target_dir = options.cargo_target_dir.expanduser().resolve() no_wasm_opt = options.no_wasm_opt specific_contract = options.specific_contract - build_root_folder = options.build_root_folder + build_root_folder = options.build_root_folder.expanduser().resolve() ensure_output_folder_is_empty(parent_output_folder) diff --git a/multiversx_sdk_rust_contract_builder/main.py b/multiversx_sdk_rust_contract_builder/main.py index 36818fc..f0e88bc 100644 --- a/multiversx_sdk_rust_contract_builder/main.py +++ b/multiversx_sdk_rust_contract_builder/main.py @@ -50,7 +50,7 @@ def main(cli_args: List[str]): shutil.rmtree(HARDCODED_UNWRAP_FOLDER, ignore_errors=True) packaged = PackagedSourceCode.from_file(packaged_src_path) packaged.unwrap_to_filesystem(HARDCODED_UNWRAP_FOLDER) - build_root = packaged.metadata.build_options.get("buildRootFolder", build_root) + build_root = Path(packaged.metadata.build_options.get("buildRootFolder", build_root)) metadata = BuildMetadata.from_env() From 79ff809ed9f486d2912d5ecdf9802e8008feae9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Tue, 28 May 2024 09:12:40 +0300 Subject: [PATCH 3/3] Do not generate the partial packaged source code anymore. --- .../build_outcome.py | 1 - multiversx_sdk_rust_contract_builder/builder.py | 12 ------------ .../source_code.py | 16 ++++++---------- 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/multiversx_sdk_rust_contract_builder/build_outcome.py b/multiversx_sdk_rust_contract_builder/build_outcome.py index 7f7450b..8c7be03 100644 --- a/multiversx_sdk_rust_contract_builder/build_outcome.py +++ b/multiversx_sdk_rust_contract_builder/build_outcome.py @@ -70,7 +70,6 @@ def many_from_folders(cls, build_folder: Path, output_folder: Path) -> Dict[str, entry.codehash = find_file_in_folder(output_folder, f"{contract_name}.codehash.txt").read_text() entry.bytecode_path = BuildArtifact.find_in_output(f"{contract_name}.wasm", output_folder) entry.abi_path = BuildArtifact.find_in_output(f"{contract_name}.abi.json", output_folder) - # This is the whole project source code. The file *.partial-source.json is not listed here - so that it's advertised as little as possible. entry.src_package_path = BuildArtifact.find_in_output("*.source.json", output_folder) result[contract_name] = entry diff --git a/multiversx_sdk_rust_contract_builder/builder.py b/multiversx_sdk_rust_contract_builder/builder.py index 2c6be5d..3336aa9 100644 --- a/multiversx_sdk_rust_contract_builder/builder.py +++ b/multiversx_sdk_rust_contract_builder/builder.py @@ -71,7 +71,6 @@ def build_project( # The bundle (packaged source code) is created after build, so that Cargo.lock files are included (if previously missing). create_packaged_source_code( parent_project_folder=project_within_build_folder, - package_whole_project_src=True, contract_folder=contract_build_subfolder, output_folder=output_subfolder, build_metadata=metadata.to_dict(), @@ -79,15 +78,6 @@ def build_project( package_filename=f"{contract_name}-{contract_version}.source.json" ) - create_packaged_source_code( - parent_project_folder=project_within_build_folder, - package_whole_project_src=False, - contract_folder=contract_build_subfolder, - output_folder=output_subfolder, - build_metadata=metadata.to_dict(), - build_options=options.to_dict(), - package_filename=f"{contract_name}-{contract_version}.partial-source.json" - ) outcome.gather_artifacts(contract_build_subfolder, output_subfolder) return outcome @@ -175,7 +165,6 @@ def build_contract(build_folder: Path, output_folder: Path, cargo_target_dir: Pa def create_packaged_source_code( parent_project_folder: Path, - package_whole_project_src: bool, contract_folder: Path, output_folder: Path, build_metadata: Dict[str, Any], @@ -185,7 +174,6 @@ def create_packaged_source_code( source_code_files = source_code.get_source_code_files( project_folder=parent_project_folder, contract_folder=contract_folder, - include_unrelated_to_contract=package_whole_project_src ) contract_name, contract_version = get_contract_name_and_version(contract_folder) diff --git a/multiversx_sdk_rust_contract_builder/source_code.py b/multiversx_sdk_rust_contract_builder/source_code.py index 1fde9c8..db9f77b 100644 --- a/multiversx_sdk_rust_contract_builder/source_code.py +++ b/multiversx_sdk_rust_contract_builder/source_code.py @@ -17,12 +17,9 @@ def get_source_code_files( project_folder: Path, contract_folder: Path, - include_unrelated_to_contract: bool ) -> List[SourceCodeFile]: """ Returns the source code files of the specified contract. - - If `include_unrelated_to_contract` is True, also returns project files that are not strictly related to the specified contract. """ source_code_files: List[SourceCodeFile] = [] @@ -46,14 +43,13 @@ def get_source_code_files( 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) + # Finally, add remaining files from the project + already_added_files = set(file.path for file in source_code_files) - if include_unrelated_to_contract: - 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)) + all_files = _get_source_code_files(project_folder) + for file in all_files: + if file not in already_added_files: + source_code_files.append(SourceCodeFile(file, contract_folder, sys.maxsize)) return source_code_files