-
Notifications
You must be signed in to change notification settings - Fork 50
Add crate version and commit hash to ldk-server #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
benthecarman
wants to merge
2
commits into
lightningdevkit:main
Choose a base branch
from
benthecarman:commit-hash
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+122
−3
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // This file is Copyright its original authors, visible in version control | ||
| // history. | ||
| // | ||
| // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE | ||
| // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
| // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option. | ||
| // You may not use this file except in accordance with one or both of these | ||
| // licenses. | ||
|
|
||
| use std::env; | ||
| use std::path::Path; | ||
| use std::process::Command; | ||
|
|
||
| fn main() { | ||
| println!("cargo:rerun-if-changed=build.rs"); | ||
| println!("cargo:rerun-if-env-changed=GIT_HASH"); | ||
|
|
||
| // Re-run the build script whenever the checked-out commit changes so the | ||
| // embedded hash never goes stale. HEAD lives in the (possibly worktree-local) | ||
| // git dir, while branch refs and packed-refs live in the common git dir. | ||
| if let Some(git_dir) = git_output(&["rev-parse", "--git-dir"]) { | ||
| watch_if_exists(&Path::new(&git_dir).join("HEAD")); | ||
| } | ||
| if let Some(common_dir) = git_output(&["rev-parse", "--git-common-dir"]) { | ||
| let common_dir = Path::new(&common_dir); | ||
| watch_if_exists(&common_dir.join("packed-refs")); | ||
| // If HEAD points at a ref, watch that ref file too (it changes on commit). | ||
| if let Some(ref_path) = git_output(&["symbolic-ref", "-q", "HEAD"]) { | ||
| watch_if_exists(&common_dir.join(ref_path)); | ||
| } | ||
| } | ||
|
|
||
| if env::var("GIT_HASH").is_err() { | ||
| let git_hash = git_output(&["rev-parse", "HEAD"]).unwrap_or_else(|| "unknown".to_string()); | ||
| println!("cargo:rustc-env=GIT_HASH={git_hash}"); | ||
| } | ||
| } | ||
|
|
||
| /// Runs `git` with the given args, returning the trimmed stdout on success or | ||
| /// `None` if git is unavailable, exits non-zero, or produces no output. | ||
| fn git_output(args: &[&str]) -> Option<String> { | ||
| let output = Command::new("git").args(args).output().ok()?; | ||
| if !output.status.success() { | ||
| return None; | ||
| } | ||
| let stdout = String::from_utf8_lossy(&output.stdout).trim().to_string(); | ||
| if stdout.is_empty() { | ||
| None | ||
| } else { | ||
| Some(stdout) | ||
| } | ||
| } | ||
|
|
||
| fn watch_if_exists(path: &Path) { | ||
| if path.exists() { | ||
| println!("cargo:rerun-if-changed={}", path.display()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // This file is Copyright its original authors, visible in version control | ||
| // history. | ||
| // | ||
| // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE | ||
| // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
| // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option. | ||
| // You may not use this file except in accordance with one or both of these | ||
| // licenses. | ||
|
|
||
| use std::env; | ||
| use std::path::Path; | ||
| use std::process::Command; | ||
|
|
||
| fn main() { | ||
| println!("cargo:rerun-if-changed=build.rs"); | ||
| println!("cargo:rerun-if-env-changed=GIT_HASH"); | ||
|
|
||
| // Re-run the build script whenever the checked-out commit changes so the | ||
| // embedded hash never goes stale. HEAD lives in the (possibly worktree-local) | ||
| // git dir, while branch refs and packed-refs live in the common git dir. | ||
| if let Some(git_dir) = git_output(&["rev-parse", "--git-dir"]) { | ||
| watch_if_exists(&Path::new(&git_dir).join("HEAD")); | ||
| } | ||
| if let Some(common_dir) = git_output(&["rev-parse", "--git-common-dir"]) { | ||
| let common_dir = Path::new(&common_dir); | ||
| watch_if_exists(&common_dir.join("packed-refs")); | ||
| // If HEAD points at a ref, watch that ref file too (it changes on commit). | ||
| if let Some(ref_path) = git_output(&["symbolic-ref", "-q", "HEAD"]) { | ||
| watch_if_exists(&common_dir.join(ref_path)); | ||
| } | ||
| } | ||
|
|
||
| if env::var("GIT_HASH").is_err() { | ||
| let git_hash = git_output(&["rev-parse", "HEAD"]).unwrap_or_else(|| "unknown".to_string()); | ||
| println!("cargo:rustc-env=GIT_HASH={git_hash}"); | ||
| } | ||
| } | ||
|
|
||
| /// Runs `git` with the given args, returning the trimmed stdout on success or | ||
| /// `None` if git is unavailable, exits non-zero, or produces no output. | ||
| fn git_output(args: &[&str]) -> Option<String> { | ||
| let output = Command::new("git").args(args).output().ok()?; | ||
| if !output.status.success() { | ||
| return None; | ||
| } | ||
| let stdout = String::from_utf8_lossy(&output.stdout).trim().to_string(); | ||
| if stdout.is_empty() { | ||
| None | ||
| } else { | ||
| Some(stdout) | ||
| } | ||
| } | ||
|
|
||
| fn watch_if_exists(path: &Path) { | ||
| if path.exists() { | ||
| println!("cargo:rerun-if-changed={}", path.display()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,7 @@ use crate::util::tls::get_or_generate_tls_config; | |
| use crate::util::{systemd, write_new}; | ||
|
|
||
| const API_KEY_FILE: &str = "api_key"; | ||
| const FULL_VERSION: &str = concat!(env!("CARGO_PKG_VERSION"), " (", env!("GIT_HASH"), ")"); | ||
|
|
||
| pub fn get_default_data_dir() -> Option<PathBuf> { | ||
| #[cfg(target_os = "macos")] | ||
|
|
@@ -241,7 +242,7 @@ fn main() { | |
| let (event_sender, _) = broadcast::channel::<EventEnvelope>(1024); | ||
| let (shutdown_tx, shutdown_rx) = tokio::sync::watch::channel(false); | ||
|
|
||
| info!("Starting up..."); | ||
| info!("Starting ldk-server version {FULL_VERSION}"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also do this when we rotate the logs ?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can do after #189 |
||
| match node.start() { | ||
| Ok(()) => {}, | ||
| Err(e) => { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make sure to update
GIT_HASHifHEADchanges after the first from-clean build. Here it seemsHEADcould change, and we'd ship a binary with a wrong rev ?Or perhaps
cargo installalways re-runsbuild.rsso we might be good here.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also trying to understand how this triggers. After
build.rssetsGIT_HASH, what other thing could causeGIT_HASHto change, and triggerbuild.rsagain ?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made it so it watches the git hash file so if it changes then we recalc