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

Removed limitation on clap version. #43

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
358 changes: 205 additions & 153 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "svd2pac"
version = "0.2.1"
edition = "2021"
rust-version = "1.70"
rust-version = "1.72"
categories = ["command-line-utilities", "development-tools::ffi"]
readme = "README.md"
repository = "https://github.com/Infineon/svd2pac"
Expand All @@ -17,7 +17,7 @@ thiserror = "1.0.40"
svd-parser = { version = "0.14", features = ["derive-from", "expand"] }
tera = "1.19.0"
# clap is limited to to support Aurix Rust compiler v1.0 (-> rustc 1.72)
clap = { version = "~4.4", features = ["derive", "cargo"] }
clap = { version = "4.4", features = ["derive", "cargo"] }
log = { version = "0.4.17", features = ["std"] }
env_logger = "0.10.0"
convert_case = "0.6"
Expand All @@ -35,6 +35,7 @@ toml_edit = "0.19"

[build-dependencies]
rustc_version = "0.4.1"
regex = "1.10"

[profile.dev.package."*"]
codegen-units = 1 # better optimizations
Expand Down
30 changes: 24 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
use regex::Regex;
use rustc_version::version;
use std::env;
const RUSTUP_TOOLCHAIN_ID: &str = "RUSTUP_TOOLCHAIN";
use std::process::Command;

fn detect_aurix_toolchain() -> Result<Option<String>, ()> {
Command::new("rustup")
.args(["toolchain", "list"])
.output()
.map_or(Err(()), |result| {
let re = Regex::new(r"tricore-htc-none.+").unwrap();
let result =
String::from_utf8(result.stdout).expect("Unable to convert to utf8 string");
pellico marked this conversation as resolved.
Show resolved Hide resolved
Ok(re.find(&result).map(|m| m.as_str().to_string()))
})
}

fn main() {
// To avoid warnings related unexpected cfgs when compiling with rustc >=1.80
// we want to be still compatible with Hightec Rust compiler presently supporting 1.72 version.
Expand All @@ -9,9 +22,14 @@ fn main() {
println!("cargo:rustc-check-cfg=cfg(aurix_tests)");
}
// In case of Aurix toolchain enable test of code generated for Aurix microcontroller
let rustup_toolchain = env::var(RUSTUP_TOOLCHAIN_ID)
.unwrap_or_else(|_| format!("Unable to to get environment variable {RUSTUP_TOOLCHAIN_ID}"));
if rustup_toolchain.contains("tricore") {
println!("cargo:rustc-cfg=aurix_tests");
match detect_aurix_toolchain() {
Err(_) => println!(
"cargo::warning=rustup not available unable to detect presence of Aurix toolchain"
),
Ok(Some(aurix_toolchain)) => {
println!("cargo:rustc-cfg=aurix_tests");
println!("cargo:rustc-env=AURIX_TOOLCHAIN={}", aurix_toolchain);
}
Ok(None) => (),
}
}
58 changes: 43 additions & 15 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fs;
use std::path::Path;
use std::process::Command;
use std::process::{exit, Command};

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

/// execute cargo build and check that build is successfull
pub fn assert_cargo_build(package_folder: tempfile::TempDir) {
pub fn assert_cargo_build(package_folder: &tempfile::TempDir, toolchain_override: Option<String>) {
Command::new("cargo")
.arg("clean")
.current_dir(package_folder.path())
.output()
.expect("Failed to clean package");
// Run cargo to build
let mut command = Command::new("cargo");
let toolchain_id = if let Some(ref toolchain_id) = toolchain_override {
command.arg(format!("+{}", toolchain_id));
toolchain_id
} else {
"default"
};
command.arg("build");
command.current_dir(package_folder.path());
let exec_result = command.output();

if exec_result.is_err() {
// This to preserve the project for further debugging
let _ = package_folder.into_path();
panic!("Failed to execute");
eprintln!("Failed to execute using toolchain: {}", toolchain_id);
// This to preserve the temp folders for further debugging
exit(-1);
}
let output_result = exec_result.unwrap();
if !output_result.status.success() {
Expand All @@ -45,29 +56,46 @@ pub fn assert_cargo_build(package_folder: tempfile::TempDir) {
.expect("Failed to parse stderr returned from cargo build");
eprintln!("Failed compilation of test project stdout: {}", stdout_msg);
eprintln!("Failed compilation of test project stderr: {}", stderr_msg);
// This to preserve the project for further debugging
let _ = package_folder.into_path();
panic!("Failed compilation of test project");
eprintln!(
"Failed compilation of test project using toolchain: {}",
toolchain_id
);
// This to preserve the temp folders for further debugging
exit(-1);
}
}

#[allow(dead_code)]
pub fn assert_cargo_test(package_folder: tempfile::TempDir) {
pub fn assert_cargo_test(package_folder: &tempfile::TempDir, toolchain_override: Option<String>) {
Command::new("cargo")
.arg("clean")
.current_dir(package_folder.path())
.output()
.expect("Failed to clean package");
// Run cargo to build
let mut command = Command::new("cargo");
let toolchain_id = if let Some(ref toolchain_id) = toolchain_override {
command.arg(format!("+{}", toolchain_id));
toolchain_id
} else {
"default"
};
command.arg("test");
command.current_dir(package_folder.path());

let exec_result = command.output();

if exec_result.is_err() {
// This to preserve the project for further debugging
let _ = package_folder.into_path();
panic!("Failed to execute tests");
eprintln!("Failed to execute tests using toolchain: {}", toolchain_id);
// This to preserve the temp folders for further debugging
exit(-1);
}
if !exec_result.unwrap().status.success() {
// This to preserve the project for further debugging
let _ = package_folder.into_path();
panic!("Failed running tests of test project");
eprintln!(
"Failed running tests of test project using toolchain: {}",
toolchain_id
);
// This to preserve the temp folders for further debugging
exit(-1);
}
}
10 changes: 8 additions & 2 deletions tests/test_basic_svd_aurix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ fn compile_generated_aurix() {
)
.expect("Failed to copy required files to build cargo project");

assert_cargo_build(generated_code_folder);
assert_cargo_build(
&generated_code_folder,
Some(env!("AURIX_TOOLCHAIN").to_string()),
);
}

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

assert_cargo_build(generated_code_folder);
assert_cargo_build(
&generated_code_folder,
Some(env!("AURIX_TOOLCHAIN").to_string()),
);
}
3 changes: 1 addition & 2 deletions tests/test_basic_svd_cortex_m.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![cfg(not(aurix_tests))]
mod common;
use common::*;
use fs_extra::dir::CopyOptions;
Expand Down Expand Up @@ -30,5 +29,5 @@ fn compile_generated_cortex_m() {

let license_path = generated_pack_folder.join("LICENSE.txt");
assert!(license_path.exists(), "Not found LICENSE.txt");
assert_cargo_build(workspace_folder);
assert_cargo_build(&workspace_folder, None);
}
7 changes: 6 additions & 1 deletion tests/test_basic_svd_generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ fn compile_generated_generic() {

let license_path = generated_code_folder.path().join("LICENSE.txt");
assert!(license_path.exists(), "Not found LICENSE.txt");
assert_cargo_build(generated_code_folder);
assert_cargo_build(&generated_code_folder, None);
#[cfg(aurix_tests)]
assert_cargo_build(
&generated_code_folder,
Some(env!("AURIX_TOOLCHAIN").to_string()),
);
}

#[test]
Expand Down
14 changes: 12 additions & 2 deletions tests/test_basic_svd_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ fn compile_generated_tracing() {
)
.expect("Failed to copy generated files to test cargo project");

assert_cargo_build(generated_code_folder);
assert_cargo_test(generated_test_folder);
assert_cargo_build(&generated_code_folder, None);
#[cfg(aurix_tests)]
assert_cargo_build(
&generated_code_folder,
Some(env!("AURIX_TOOLCHAIN").to_string()),
);
assert_cargo_test(&generated_test_folder, None);
#[cfg(aurix_tests)]
assert_cargo_test(
&generated_test_folder,
Some(env!("AURIX_TOOLCHAIN").to_string()),
);
}
Loading