Skip to content

Commit 4b59f9b

Browse files
committed
Removed limitation on clap version.
Upgraded all dependencies No need to switch default toolchain to test generated packages with Aurix compiler.
1 parent 95c8337 commit 4b59f9b

File tree

8 files changed

+302
-183
lines changed

8 files changed

+302
-183
lines changed

Cargo.lock

Lines changed: 205 additions & 153 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "svd2pac"
33
version = "0.2.1"
44
edition = "2021"
5-
rust-version = "1.70"
5+
rust-version = "1.72"
66
categories = ["command-line-utilities", "development-tools::ffi"]
77
readme = "README.md"
88
repository = "https://github.com/Infineon/svd2pac"
@@ -17,7 +17,7 @@ thiserror = "1.0.40"
1717
svd-parser = { version = "0.14", features = ["derive-from", "expand"] }
1818
tera = "1.19.0"
1919
# clap is limited to to support Aurix Rust compiler v1.0 (-> rustc 1.72)
20-
clap = { version = "~4.4", features = ["derive", "cargo"] }
20+
clap = { version = "4.4", features = ["derive", "cargo"] }
2121
log = { version = "0.4.17", features = ["std"] }
2222
env_logger = "0.10.0"
2323
convert_case = "0.6"
@@ -35,6 +35,7 @@ toml_edit = "0.19"
3535

3636
[build-dependencies]
3737
rustc_version = "0.4.1"
38+
regex = "1.10"
3839

3940
[profile.dev.package."*"]
4041
codegen-units = 1 # better optimizations

build.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1+
use regex::Regex;
12
use rustc_version::version;
2-
use std::env;
3-
const RUSTUP_TOOLCHAIN_ID: &str = "RUSTUP_TOOLCHAIN";
3+
use std::process::Command;
4+
5+
fn detect_aurix_toolchain() -> Result<Option<String>, ()> {
6+
Command::new("rustup")
7+
.args(["toolchain", "list"])
8+
.output()
9+
.map_or(Err(()), |result| {
10+
let re = Regex::new(r"tricore-htc-none.+").unwrap();
11+
let result =
12+
String::from_utf8(result.stdout).expect("Unable to convert to utf8 string");
13+
Ok(re.find(&result).map(|m| m.as_str().to_string()))
14+
})
15+
}
16+
417
fn main() {
518
// To avoid warnings related unexpected cfgs when compiling with rustc >=1.80
619
// we want to be still compatible with Hightec Rust compiler presently supporting 1.72 version.
@@ -9,9 +22,14 @@ fn main() {
922
println!("cargo:rustc-check-cfg=cfg(aurix_tests)");
1023
}
1124
// In case of Aurix toolchain enable test of code generated for Aurix microcontroller
12-
let rustup_toolchain = env::var(RUSTUP_TOOLCHAIN_ID)
13-
.unwrap_or_else(|_| format!("Unable to to get environment variable {RUSTUP_TOOLCHAIN_ID}"));
14-
if rustup_toolchain.contains("tricore") {
15-
println!("cargo:rustc-cfg=aurix_tests");
25+
match detect_aurix_toolchain() {
26+
Err(_) => println!(
27+
"cargo::warning=rustup not available unable to detect presence of Aurix toolchain"
28+
),
29+
Ok(Some(aurix_toolchain)) => {
30+
println!("cargo:rustc-cfg=aurix_tests");
31+
println!("cargo:rustc-env=AURIX_TOOLCHAIN={}", aurix_toolchain);
32+
}
33+
Ok(None) => (),
1634
}
1735
}

tests/common/mod.rs

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::fs;
22
use std::path::Path;
3-
use std::process::Command;
3+
use std::process::{exit, Command};
44

55
#[allow(dead_code)]
66
pub fn assert_files_eq<T: AsRef<Path>, Q: AsRef<Path>>(ref_file: T, gen_file: Q) {
@@ -25,17 +25,28 @@ pub fn assert_files_eq<T: AsRef<Path>, Q: AsRef<Path>>(ref_file: T, gen_file: Q)
2525
}
2626

2727
/// execute cargo build and check that build is successfull
28-
pub fn assert_cargo_build(package_folder: tempfile::TempDir) {
28+
pub fn assert_cargo_build(package_folder: &tempfile::TempDir, toolchain_override: Option<String>) {
29+
Command::new("cargo")
30+
.arg("clean")
31+
.current_dir(package_folder.path())
32+
.output()
33+
.expect("Failed to clean package");
2934
// Run cargo to build
3035
let mut command = Command::new("cargo");
36+
let toolchain_id = if let Some(ref toolchain_id) = toolchain_override {
37+
command.arg(format!("+{}", toolchain_id));
38+
toolchain_id
39+
} else {
40+
"default"
41+
};
3142
command.arg("build");
3243
command.current_dir(package_folder.path());
3344
let exec_result = command.output();
3445

3546
if exec_result.is_err() {
36-
// This to preserve the project for further debugging
37-
let _ = package_folder.into_path();
38-
panic!("Failed to execute");
47+
eprintln!("Failed to execute using toolchain: {}", toolchain_id);
48+
// This to preserve the temp folders for further debugging
49+
exit(-1);
3950
}
4051
let output_result = exec_result.unwrap();
4152
if !output_result.status.success() {
@@ -45,29 +56,46 @@ pub fn assert_cargo_build(package_folder: tempfile::TempDir) {
4556
.expect("Failed to parse stderr returned from cargo build");
4657
eprintln!("Failed compilation of test project stdout: {}", stdout_msg);
4758
eprintln!("Failed compilation of test project stderr: {}", stderr_msg);
48-
// This to preserve the project for further debugging
49-
let _ = package_folder.into_path();
50-
panic!("Failed compilation of test project");
59+
eprintln!(
60+
"Failed compilation of test project using toolchain: {}",
61+
toolchain_id
62+
);
63+
// This to preserve the temp folders for further debugging
64+
exit(-1);
5165
}
5266
}
5367

5468
#[allow(dead_code)]
55-
pub fn assert_cargo_test(package_folder: tempfile::TempDir) {
69+
pub fn assert_cargo_test(package_folder: &tempfile::TempDir, toolchain_override: Option<String>) {
70+
Command::new("cargo")
71+
.arg("clean")
72+
.current_dir(package_folder.path())
73+
.output()
74+
.expect("Failed to clean package");
5675
// Run cargo to build
5776
let mut command = Command::new("cargo");
77+
let toolchain_id = if let Some(ref toolchain_id) = toolchain_override {
78+
command.arg(format!("+{}", toolchain_id));
79+
toolchain_id
80+
} else {
81+
"default"
82+
};
5883
command.arg("test");
5984
command.current_dir(package_folder.path());
6085

6186
let exec_result = command.output();
6287

6388
if exec_result.is_err() {
64-
// This to preserve the project for further debugging
65-
let _ = package_folder.into_path();
66-
panic!("Failed to execute tests");
89+
eprintln!("Failed to execute tests using toolchain: {}", toolchain_id);
90+
// This to preserve the temp folders for further debugging
91+
exit(-1);
6792
}
6893
if !exec_result.unwrap().status.success() {
69-
// This to preserve the project for further debugging
70-
let _ = package_folder.into_path();
71-
panic!("Failed running tests of test project");
94+
eprintln!(
95+
"Failed running tests of test project using toolchain: {}",
96+
toolchain_id
97+
);
98+
// This to preserve the temp folders for further debugging
99+
exit(-1);
72100
}
73101
}

tests/test_basic_svd_aurix.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ fn compile_generated_aurix() {
5757
)
5858
.expect("Failed to copy required files to build cargo project");
5959

60-
assert_cargo_build(generated_code_folder);
60+
assert_cargo_build(
61+
&generated_code_folder,
62+
Some(env!("AURIX_TOOLCHAIN").to_string()),
63+
);
6164
}
6265

6366
/// Generate PAC with tracing code but feature is disabled
@@ -112,5 +115,8 @@ fn compile_generated_aurix_tracing() {
112115
)
113116
.expect("Failed to copy required files to build cargo project");
114117

115-
assert_cargo_build(generated_code_folder);
118+
assert_cargo_build(
119+
&generated_code_folder,
120+
Some(env!("AURIX_TOOLCHAIN").to_string()),
121+
);
116122
}

tests/test_basic_svd_cortex_m.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![cfg(not(aurix_tests))]
21
mod common;
32
use common::*;
43
use fs_extra::dir::CopyOptions;
@@ -30,5 +29,5 @@ fn compile_generated_cortex_m() {
3029

3130
let license_path = generated_pack_folder.join("LICENSE.txt");
3231
assert!(license_path.exists(), "Not found LICENSE.txt");
33-
assert_cargo_build(workspace_folder);
32+
assert_cargo_build(&workspace_folder, None);
3433
}

tests/test_basic_svd_generic.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ fn compile_generated_generic() {
5050

5151
let license_path = generated_code_folder.path().join("LICENSE.txt");
5252
assert!(license_path.exists(), "Not found LICENSE.txt");
53-
assert_cargo_build(generated_code_folder);
53+
assert_cargo_build(&generated_code_folder, None);
54+
#[cfg(aurix_tests)]
55+
assert_cargo_build(
56+
&generated_code_folder,
57+
Some(env!("AURIX_TOOLCHAIN").to_string()),
58+
);
5459
}
5560

5661
#[test]

tests/test_basic_svd_tracing.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ fn compile_generated_tracing() {
6262
)
6363
.expect("Failed to copy generated files to test cargo project");
6464

65-
assert_cargo_build(generated_code_folder);
66-
assert_cargo_test(generated_test_folder);
65+
assert_cargo_build(&generated_code_folder, None);
66+
#[cfg(aurix_tests)]
67+
assert_cargo_build(
68+
&generated_code_folder,
69+
Some(env!("AURIX_TOOLCHAIN").to_string()),
70+
);
71+
assert_cargo_test(&generated_test_folder, None);
72+
#[cfg(aurix_tests)]
73+
assert_cargo_test(
74+
&generated_test_folder,
75+
Some(env!("AURIX_TOOLCHAIN").to_string()),
76+
);
6777
}

0 commit comments

Comments
 (0)