Skip to content

Commit

Permalink
Fix when Rust app is a workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
yogh333 committed Jul 25, 2024
1 parent 5275ad1 commit 842683d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
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

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

## [1.22.1] - 2024-07-23

### Fixed
Expand Down
8 changes: 7 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 @@ -72,7 +74,11 @@ def find_application(base_dir: Path, device: str, sdk: str) -> 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
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)
cmd = ["cargo", "new", appname]
subprocess.check_output(cmd)
app_path = dir_path / appname
os.chdir(app_path)
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

0 comments on commit 842683d

Please sign in to comment.