Building 70 Projects ranging from beginner to advanced so anyone can — learn from, build upon, use as a reference, or even copy directly. Owned by my cybersecurity company 👇
Go aicertificationcloud-engineeringcybercybersecuritycybersecurity-analystcybersecurity-certificationcybersecurity-certificationscybersecurity-educationcybersecurity-jobscybersecurity-portfoliocybersecurity-projectscybersecurity-toolsgrchackinglearningpentestingproject-repositoryprojetcspython
// ©AngelaMos | 2026
// relink_generator.rs
use std::path::{Path, PathBuf};
use std::process::Command;
use lisdex_build::plan::Generator;
use lisdex_core::scratch;
const MARKER: &str = "lisdex_replay_marker";
const PLAIN_SOURCE: &str = "int alpha(int x) { return x + 1; }\n";
const OBJECT: &str = "a.o";
const SOURCE: &str = "a.c";
fn lab(label: &str) -> PathBuf {
let dir = scratch::path(label);
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
std::fs::write(dir.join(SOURCE), PLAIN_SOURCE).unwrap();
dir
}
fn run(program: &str, args: &[&str], cwd: &Path) -> bool {
Command::new(program)
.args(args)
.current_dir(cwd)
.status()
.unwrap_or_else(|err| panic!("{program} is required by this test: {err}"))
.success()
}
fn replay_over(dir: &Path) {
let instrumented = dir.join("a_instrumented.c");
std::fs::write(
&instrumented,
format!("{PLAIN_SOURCE}int {MARKER}(void) {{ return 42; }}\n"),
)
.unwrap();
assert!(run("cc", &["-c", "a_instrumented.c", "-o", OBJECT], dir));
assert!(
object_holds_marker(dir),
"the replay itself did not land, so the test that follows would prove nothing"
);
}
fn object_holds_marker(dir: &Path) -> bool {
let bytes = std::fs::read(dir.join(OBJECT)).unwrap();
bytes
.windows(MARKER.len())
.any(|window| window == MARKER.as_bytes())
}
#[test]
fn ninja_rebuilds_a_replayed_object_and_make_leaves_it_alone() {
let ninja_dir = lab("relink-ninja");
std::fs::write(
ninja_dir.join("build.ninja"),
format!(
"rule cc\n command = cc -MD -MF $out.d -c $in -o $out\n depfile = $out.d\n \
deps = gcc\n\nbuild {OBJECT}: cc {SOURCE}\n"
),
)
.unwrap();
assert!(run("ninja", &[], &ninja_dir));
replay_over(&ninja_dir);
assert!(run("ninja", &[], &ninja_dir));
let ninja_kept = object_holds_marker(&ninja_dir);
let make_dir = lab("relink-make");
std::fs::write(
make_dir.join("Makefile"),
format!("all: {OBJECT}\n\n{OBJECT}: {SOURCE}\n\tcc -c {SOURCE} -o {OBJECT}\n"),
)
.unwrap();
assert!(run("make", &[], &make_dir));
replay_over(&make_dir);
assert!(run("make", &[], &make_dir));
let make_kept = object_holds_marker(&make_dir);
assert!(
!ninja_kept,
"ninja no longer rebuilds an output whose bytes changed underneath it, so the \
compile-commands-replay tier is refusing ninja-backed trees for a reason that has \
stopped being true"
);
assert!(
make_kept,
"make rebuilt a replayed object it should have accepted as newer than its source, so \
the make-backed replay path is broken too and refusing only ninja is not enough"
);
assert_ne!(
Generator::Ninja.rebuilds_externally_modified_outputs(),
Generator::Makefiles.rebuilds_externally_modified_outputs(),
"the predicate the ladder gates on must distinguish the two generators this test just \
measured apart"
);
assert!(Generator::Ninja.rebuilds_externally_modified_outputs());
assert!(!Generator::Makefiles.rebuilds_externally_modified_outputs());
}