Skip to content

Commit

Permalink
Merge pull request #61 from multiversx/cleanup-partial-package
Browse files Browse the repository at this point in the history
Do not generate the "*.partial-source.json" anymore (bad, and not used)
  • Loading branch information
andreibancioiu authored May 28, 2024
2 parents 50a6d69 + 79ff809 commit 2ec2f7f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 25 deletions.
1 change: 0 additions & 1 deletion multiversx_sdk_rust_contract_builder/build_outcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 2 additions & 14 deletions multiversx_sdk_rust_contract_builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -71,23 +71,13 @@ 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(),
build_options=options.to_dict(),
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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions multiversx_sdk_rust_contract_builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
16 changes: 6 additions & 10 deletions multiversx_sdk_rust_contract_builder/source_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []

Expand All @@ -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

Expand Down

0 comments on commit 2ec2f7f

Please sign in to comment.