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

Fix when Rust app is a workspace #204

Merged
merged 7 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.22.2] - 2024-07-25

### Fixed
yogh333 marked this conversation as resolved.
Show resolved Hide resolved

- Rust app: get target directory from cargo metadata (workspace compatible)

## [1.22.1] - 2024-07-23

### Fixed
Expand Down
17 changes: 16 additions & 1 deletion src/ragger/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from typing import Optional, Tuple, List
from pathlib import Path
from ragger.error import ExceptionRAPDU
import subprocess
import json

ERROR_BOLOS_DEVICE_LOCKED = 0x5515
ERROR_DENIED_BY_USER = 0x5501
Expand Down Expand Up @@ -69,10 +71,23 @@
raise AssertionError(f"{base_dir} is not a directory")
app = base_dir.resolve()
if sdk.lower() == "rust":
"""
When building a Rust app, the resulting binary is located in a target
directory target/<device>/release/<app_name>. app is the Path to the
build directory, where is stored the app's Cargo.toml file.
If the app repository is organized as a workspace crate (several packages,

Check failure on line 78 in src/ragger/utils/misc.py

View workflow job for this annotation

GitHub Actions / Check misspellings

crate ==> create
each package in its own directory with its own Cargo.toml), the binaries are
all stored in the same target directory. 'cargo metadata' is used to get the
target directory full path.
"""
if device == "nanos2":
device = "nanosplus"
app_name = toml.load(base_dir / "Cargo.toml")["package"]["name"]
app = app / "target" / device / "release" / app_name
cmd = ["cargo", "metadata", "--no-deps"]
output = subprocess.check_output(cmd)
metadata = json.loads(output)
target = Path(metadata["target_directory"])
app = target / device / "release" / app_name
yogh333 marked this conversation as resolved.
Show resolved Hide resolved
else:
app = app / "build" / device / "bin" / "app.elf"
if not app.is_file():
Expand Down
12 changes: 8 additions & 4 deletions tests/unit/utils/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import subprocess
from pathlib import Path
from unittest import TestCase
from unittest.mock import MagicMock, patch
Expand Down Expand Up @@ -40,13 +41,16 @@ def test_find_application_ok_c(self):
def test_find_application_ok_rust(self):
device, sdk, appname = "device", "rust", "rustapp"
with temporary_directory() as dir_path:
tmp_dir = (dir_path / "target" / device / "release")
os.chdir(dir_path)
yogh333 marked this conversation as resolved.
Show resolved Hide resolved
cmd = ["cargo", "new", appname]
subprocess.check_output(cmd)
app_path = dir_path / appname
os.chdir(app_path)
yogh333 marked this conversation as resolved.
Show resolved Hide resolved
tmp_dir = (app_path / "target" / device / "release")
tmp_dir.mkdir(parents=True, exist_ok=True)
expected = tmp_dir / appname
expected.touch()
with patch("ragger.utils.misc.toml") as toml_patch:
toml_patch.load.return_value = {"package": {"name": appname}}
result = misc.find_application(dir_path, device, sdk)
result = misc.find_application(app_path, device, sdk)
self.assertEqual(result, expected)

def test_find_application_nok_not_dir(self):
Expand Down
Loading