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 c227d6c..3336aa9 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) @@ -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 @@ -118,7 +108,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, @@ -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/main.py b/multiversx_sdk_rust_contract_builder/main.py index 755eefa..f0e88bc 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 = Path(packaged.metadata.build_options.get("buildRootFolder", build_root)) metadata = BuildMetadata.from_env() 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