파일 목록이 있고 모든 파일에 대해 일부 프로그램을 실행하고 싶지만 변경된 경우에만 실행하고 싶습니다. 그래서 모든 파일을 벡터에 넣고 다음과 같이 반복했습니다.
// build.rs
let files = vec![
"fileA",
"fileB",
];
for file in files{
println!("cargo:rerun-if-changed={}", file);
let output = Command::new("glslangValidator")
.args(&["-V", file, "-o", file])
.output()
.expect("failed to run glslangValidator");
}
이것은 작동하지만 목록에서 하나만 변경된 경우에도 모든 파일에 대해 빌드 프로세스가 실행됩니다 . 대신 빌드간에 변경된 파일에 대해서만glslangValidator
호출 되고 싶습니다 .
호출하는 명령이 출력 파일을 생성하는 경우 일반적인 기술은 출력 파일의 수정 날짜를 소스 파일의 수정 날짜와 비교하는 것입니다.
출력 파일이 소스 파일보다 오래되었거나 출력 파일이없는 경우에만 도구를 호출하면됩니다.
예:
fn is_input_file_outdated<P1, P2>(input: P1, output: P2) -> io::Result<bool>
where
P1: AsRef<Path>,
P2: AsRef<Path>,
{
let out_meta = fs::metadata(output);
if let Ok(meta) = out_meta {
let output_mtime = meta.modified()?;
// if input file is more recent than our output, we are outdated
let input_meta = fs::metadata(input)?;
let input_mtime = input_meta.modified()?;
Ok(input_mtime > output_mtime)
} else {
// output file not found, we are outdated
Ok(true)
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다