add a flag for changing targets gracefully

at the moment an SVD pointer hangs out that messes builds up
when changing targets (sometimes) -- this is the pointer that
includes extra files in the build for targets that have disjoint
RTL sources. add a flag for cleaning this up.
This commit is contained in:
bunnie 2024-05-07 00:57:24 +08:00
parent b1cc676345
commit 114a2c40bd
2 changed files with 22 additions and 5 deletions

View file

@ -146,6 +146,7 @@ pub(crate) struct Builder {
no_image: bool,
/// when Some, specifies a swap region as offset, size
swap: Option<(u32, u32)>,
change_target: bool,
}
impl Builder {
@ -174,6 +175,7 @@ impl Builder {
dry_run: false,
no_image: false,
swap: None,
change_target: false,
}
}
@ -226,6 +228,11 @@ impl Builder {
self
}
pub fn set_change_target_flag(&mut self) -> &mut Builder {
self.change_target = true;
self
}
/// Set a minimum xous version. This is the minimum Xous version necessary to read
/// the PDDB that is generated by this build. The purpose of this is so that we can
/// trim migration code out of the PDDB: when we have a breaking change to the PDDB,
@ -764,6 +771,15 @@ impl Builder {
println!("Dry run requested: only building and not running");
}
} else {
let svd_spec_path = format!(
"target/{}/{}/build/SVD_PATH",
self.target.as_ref().expect("target"),
self.stream.as_str()
);
if self.change_target {
std::fs::remove_file(&svd_spec_path).ok(); // don't fail if the file does not exist
}
// ------ build the kernel ------
let mut kernel_extra = vec![];
if self.kernel_disable_defaults {
@ -823,11 +839,6 @@ impl Builder {
}
// ---------- extract SVD file path, as computed by utralib ----------
let svd_spec_path = format!(
"target/{}/{}/build/SVD_PATH",
self.target.as_ref().expect("target"),
self.stream.as_str()
);
let mut svd_spec_file = OpenOptions::new().read(true).open(svd_spec_path)?;
let mut svd_path_str = String::new();
svd_spec_file.read_to_string(&mut svd_path_str)?;

View file

@ -193,6 +193,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
if env::args().filter(|x| x == "--offline").count() != 0 {
builder.add_global_flag("--offline");
}
if env::args().filter(|x| x == "--change-target").count() != 0 {
builder.set_change_target_flag();
}
// manage an ugly patch we have to do to selectively configure AES for only cramium-soc targets
match builder::search_in_file("services/aes/Cargo.toml", "default = []") {
@ -596,6 +599,7 @@ fn print_help() {
[--gdb-stub]
[--debug-loader]
[--offline]
[--change-target]
[cratespecs] is a list of 0 or more items of the following syntax:
[name] crate 'name' to be built from local source
@ -620,6 +624,8 @@ be merged in with explicit app/service treatment with the following flags:
[--debug-loader] Enable debug printing in the loader
[--offline] Avoid network traffic
[--swap offset:size] Specify a region for swap memory. The behavior of this depends on the target.
[--change-target] Used to clean the cached target/*/*/build/SVD_PATH when changing build targets.
This will also force a full rebuild every time the flag is specified.
- An 'app' must be enumerated in apps/manifest.json.
A pre-processor configures the launch menu based on the list of specified apps.