mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-12 07:14:38 +00:00
build: update rerun-if conditions to watch .git/HEAD in colocated repo
Since .git/HEAD is less frequently updated, this should avoid unneeded recompilation on test-only changes. This only applies to colocated repo. For non-colocated repo, maybe we can watch src/ and ../lib/src files? This also adds $NIX_JJ_GIT_HASH to reflect hash changes (and to not rerun if no .git nor .jj directory exists.)
This commit is contained in:
parent
aae14b24e0
commit
5e22e67584
1 changed files with 14 additions and 2 deletions
16
cli/build.rs
16
cli/build.rs
|
@ -12,11 +12,15 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
use std::path::Path;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use cargo_metadata::MetadataCommand;
|
use cargo_metadata::MetadataCommand;
|
||||||
|
|
||||||
|
const GIT_HEAD_PATH: &str = "../.git/HEAD";
|
||||||
|
const JJ_OP_HEADS_PATH: &str = "../.jj/repo/op_heads/heads";
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
let path = std::env::var("CARGO_MANIFEST_DIR").unwrap();
|
let path = std::env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||||
let meta = MetadataCommand::new()
|
let meta = MetadataCommand::new()
|
||||||
|
@ -27,6 +31,16 @@ fn main() -> std::io::Result<()> {
|
||||||
let root = meta.root_package().unwrap();
|
let root = meta.root_package().unwrap();
|
||||||
let version = &root.version;
|
let version = &root.version;
|
||||||
|
|
||||||
|
if Path::new(GIT_HEAD_PATH).exists() {
|
||||||
|
// In colocated repo, .git/HEAD should reflect the working-copy parent.
|
||||||
|
println!("cargo:rerun-if-changed={GIT_HEAD_PATH}");
|
||||||
|
} else if Path::new(JJ_OP_HEADS_PATH).exists() {
|
||||||
|
// op_heads changes when working-copy files are mutated, which is way more
|
||||||
|
// frequent than .git/HEAD.
|
||||||
|
println!("cargo:rerun-if-changed={JJ_OP_HEADS_PATH}");
|
||||||
|
}
|
||||||
|
println!("cargo:rerun-if-env-changed=NIX_JJ_GIT_HASH");
|
||||||
|
|
||||||
if let Some(git_hash) = get_git_hash() {
|
if let Some(git_hash) = get_git_hash() {
|
||||||
println!("cargo:rustc-env=JJ_VERSION={}-{}", version, git_hash);
|
println!("cargo:rustc-env=JJ_VERSION={}-{}", version, git_hash);
|
||||||
} else {
|
} else {
|
||||||
|
@ -55,14 +69,12 @@ fn get_git_hash() -> Option<String> {
|
||||||
.output()
|
.output()
|
||||||
{
|
{
|
||||||
if output.status.success() {
|
if output.status.success() {
|
||||||
println!("cargo:rerun-if-changed=../.jj/repo/op_heads/heads/");
|
|
||||||
return Some(String::from_utf8(output.stdout).unwrap());
|
return Some(String::from_utf8(output.stdout).unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(output) = Command::new("git").args(["rev-parse", "HEAD"]).output() {
|
if let Ok(output) = Command::new("git").args(["rev-parse", "HEAD"]).output() {
|
||||||
if output.status.success() {
|
if output.status.success() {
|
||||||
println!("cargo:rerun-if-changed=../.git/HEAD");
|
|
||||||
let line = str::from_utf8(&output.stdout).unwrap();
|
let line = str::from_utf8(&output.stdout).unwrap();
|
||||||
return Some(line.trim_end().to_owned());
|
return Some(line.trim_end().to_owned());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue