Skip to content

Commit

Permalink
models: rerun if variant/mod links change
Browse files Browse the repository at this point in the history
We don't expect these links to change outside of this script, but if they do,
we need to rerun this build.rs and reset the links properly.
  • Loading branch information
tjkirch committed Feb 17, 2021
1 parent 79465cd commit 30d16ae
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions sources/models/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ use std::os::unix::fs::symlink;
use std::path::{Path, PathBuf};
use std::process;

const VARIANT_LINK: &str = "src/variant/current";
const MOD_LINK: &str = "src/variant/mod.rs";
const VARIANT_ENV: &str = "VARIANT";

fn main() {
// Tell cargo when we have to rerun, regardless of early-exit below.
println!("cargo:rerun-if-env-changed={}", VARIANT_ENV);
println!("cargo:rerun-if-changed={}", VARIANT_LINK);
println!("cargo:rerun-if-changed={}", MOD_LINK);

// This build.rs runs once as a build-dependency of storewolf, and again as a (regular)
// dependency of storewolf. There's no reason to do this work twice.
Expand Down Expand Up @@ -53,7 +57,6 @@ fn link_current_variant() {
});

// Point to the source for the requested variant
let variant_link = "src/variant/current";
let variant_target = format!("../{}", variant);

// Make sure requested variant exists
Expand All @@ -64,17 +67,16 @@ fn link_current_variant() {
}

// Create the symlink for the following `cargo build` to use for its source code
symlink_force(&variant_target, variant_link).unwrap_or_else(|e| {
eprintln!("Failed to create symlink at '{}' pointing to '{}' - we need this to support different API models for different variants. Error: {}", variant_link, variant_target, e);
symlink_force(&variant_target, VARIANT_LINK).unwrap_or_else(|e| {
eprintln!("Failed to create symlink at '{}' pointing to '{}' - we need this to support different API models for different variants. Error: {}", VARIANT_LINK, variant_target, e);
process::exit(1);
});

// Also create the link for mod.rs so Rust can import source from the "current" link
// created above.
let mod_link = "src/variant/mod.rs";
let mod_target = "../variant_mod.rs";
symlink_force(&mod_target, mod_link).unwrap_or_else(|e| {
eprintln!("Failed to create symlink at '{}' pointing to '{}' - we need this to build a Rust module structure through the `current` link. Error: {}", mod_link, mod_target, e);
symlink_force(&mod_target, MOD_LINK).unwrap_or_else(|e| {
eprintln!("Failed to create symlink at '{}' pointing to '{}' - we need this to build a Rust module structure through the `current` link. Error: {}", MOD_LINK, mod_target, e);
process::exit(1);
});
}
Expand Down

0 comments on commit 30d16ae

Please sign in to comment.