-
Notifications
You must be signed in to change notification settings - Fork 63
virtme-ng-init: add some useful info when PID>1 #256
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
base: main
Are you sure you want to change the base?
Conversation
66bd4a8
to
0e4a0df
Compare
ok. this is probably no go. |
c3ec9be
to
8061617
Compare
# Generate Rust version file | ||
version_rs_path = pathlib.Path("virtme_ng_init/src/version.rs") | ||
version_rs_path.parent.mkdir(parents=True, exist_ok=True) | ||
version_rs_path.write_text(f'pub const VERSION: &str = "{VERSION}";\n') |
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.
will it write this info in the source code, modifying the tracked file?
That's a good idea to pass the version, but can we not pass the info differently? e.g. passing a var when compiling the program?
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.
Yes. setup.py writes the whole file.
I fiddled with trying to get env at compile-time, but that env isnt a hash, so I cant just inspect it for useful datums.
Some AI showed me a long list of things, not many looked useful. I settled on 3 as a POC.
FWIW, the placeholder version serves as a sentinel,
making clear that something is off with the build process.
But it does muddle the meaning of "clean source"
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.
If that's not easily possible, an env var could be passed to the VM.
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.
following up on this, I asked the LLM:
Ive done the placeholder version like you suggested, but it opens another problem: the build process now alters the checked-out code, so it no longer would match a checksum baseline. Some CI might barf on that.
Heres its (slightly solicitous) response: It sounds plausible to me, but this is like week 2 of my rust world. Anyone foresee any troubles ??
You've hit upon a very important point! Creating a placeholder version.rs and then having the build process overwrite it does indeed introduce the problem of altering checked-out code, which can cause checksum mismatches and CI failures.
Let's address this issue with a solution that avoids modifying checked-out code:
The Solution: Generate version.rs in the target Directory
Instead of generating version.rs in the src directory, we can generate it in the target directory, which is already ignored by Git and intended for build artifacts.
Here's how to implement this solution:
Modify setup.py:
Change the version_rs_path to point to the target directory:
Python
version_rs_path = pathlib.Path("virtme_ng_init/target/version.rs")
Ensure the directory exists:
Python
version_rs_path.parent.mkdir(parents=True, exist_ok=True)
Generate the version.rs file in the target directory:
Python
version_rs_path.write_text(f'pub const VERSION: &str = "{VERSION}";\n')
Modify virtme_ng_init/src/main.rs:
Change the mod version; declaration to point to the target directory:
Rust
mod version;
use crate::version::VERSION;
Update .gitignore:
Ensure that the virtme_ng_init/target/version.rs file is ignored by Git.
The virtme_ng_init/target directory is already ignored, so there should be nothing to do.
Explanation
By generating version.rs in the target directory, we avoid modifying checked-out code.
The target directory is intended for build artifacts and is already ignored by Git, so it won't affect checksums or CI.
We change the mod declaration to mod version; and then use crate::version::VERSION to tell rust to look for the module in the same crate, which is the default behavior.
Benefits
No Modification of Checked-Out Code: This resolves the checksum and CI issues.
Clean Build: The build process generates files in the appropriate location.
Compatibility: This approach should be compatible with most CI systems.
By generating version.rs in the target directory, you can resolve the pre-commit rejection and avoid modifying checked-out code.
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.
I don't know Rust well, (maybe @arighi can help here? :) ) but I think the idea is to add a build.rs
file in virtme_ng_init/
that will execute python3 virtme_ng/version.py
and set a build env var:
// build.rs
use std::process::Command;
fn main() {
// note: add error checking yourself.
let output = Command::new("python3").args(&["virtme_ng/version.py"]).output().unwrap();
let version = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=VNG_VERSION={}", version);
}
Then in main.rs
, you can use env!("VNG_VERSION")
c60e63d
to
cd8d9ad
Compare
report virtme-ng-init version info, as written to target/version.rs, by ../setup.py, using version.py's notion of VERSION. this yields: [jimc@gandalf virtme-ng]$ ./virtme/guest/bin/virtme-ng-init virtme-ng-init: must be run as PID 1 virtme-ng-init: Build Information: virtme-ng-init: Package Name: virtme-ng-init virtme-ng-init: Package Version: 1.33+33.g5893a4b.dirty virtme-ng-init: Manifest Directory: /home/jimc/projects/virtme-ng/virtme_ng_init or: _ _ __ _(_)_ __| |_ _ __ ___ ___ _ __ __ _ \ \ / / | __| __| _ _ \ / _ \_____| _ \ / _ | \ V /| | | | |_| | | | | | __/_____| | | | (_| | \_/ |_|_| \__|_| |_| |_|\___| |_| |_|\__ | |___/ version: 1.33+34.g723e552.dirty kernel: 6.14.0-rc7-dd-00059-gb4d7289f3f54 x86_64 (CTRL+d to exit) So far, the info is mostly useful for blaming, but theres room for more details, if/when any other useful ones become apparent. Signed-off-by: Jim Cromie <jim.cromie@gmail.com> --- v2 - version in target, to avoid repo/checksum/build/CI conflicts
So it appears that setup.py is not run 1st as part of CI it writes the target/version.rs file, which must be there for the compile to succeed. Can someone conjure a fix ? |
# Generate Rust version file | ||
version_rs_path = pathlib.Path("virtme_ng_init/src/version.rs") | ||
version_rs_path.parent.mkdir(parents=True, exist_ok=True) | ||
version_rs_path.write_text(f'pub const VERSION: &str = "{VERSION}";\n') |
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.
I don't know Rust well, (maybe @arighi can help here? :) ) but I think the idea is to add a build.rs
file in virtme_ng_init/
that will execute python3 virtme_ng/version.py
and set a build env var:
// build.rs
use std::process::Command;
fn main() {
// note: add error checking yourself.
let output = Command::new("python3").args(&["virtme_ng/version.py"]).output().unwrap();
let version = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=VNG_VERSION={}", version);
}
Then in main.rs
, you can use env!("VNG_VERSION")
can we depend upon package variables ?
|
On Mon, Apr 7, 2025 at 10:42 AM Matthieu Baerts ***@***.***> wrote:
***@***.**** requested changes on this pull request.
------------------------------
In setup.py
<#256 (comment)>:
> @@ -50,6 +51,11 @@
"RUSTFLAGS", ""
)
+# Generate Rust version file
+version_rs_path = pathlib.Path("virtme_ng_init/src/version.rs")
+version_rs_path.parent.mkdir(parents=True, exist_ok=True)
+version_rs_path.write_text(f'pub const VERSION: &str = "{VERSION}";\n')
I don't know Rust well, (maybe @arighi <https://github.com/arighi> can
help here? :) ) but I think the idea is to add a build.rs file in
virtme_ng_init/ that will execute python3 virtme_ng/version.py and set a
build env var:
// build.rsuse std::process::Command;fn main() {
// note: add error checking yourself.
let output = Command::new("python3").args(&["virtme_ng/version.py"]).output().unwrap();
let version = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=VNG_VERSION={}", version);}
Then in main.rs, you can use env!("VNG_VERSION")
Source: https://stackoverflow.com/a/44407625
This is pretty slick, and thanks for the link.
it has git derived env VERSION,
one might expect it to be a quite reliable setting on github :-)
… —
Reply to this email directly, view it on GitHub
<#256 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAUBQ7BZVDVBYOMATFDWF32YKTITAVCNFSM6AAAAABZJZUI5OVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDONBXGQ3DMMRYHE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
That's different, that will be the version of the init program, no? Maybe we could also set an env var containing |
report vng-init version info, as written to src/version.rs, by ../setup.py, using version.py's notion of VERSION.
this yields:
[jimc@gandalf virtme-ng]$ ./virtme/guest/bin/virtme-ng-init virtme-ng-init: must be run as PID 1
virtme-ng-init: Build Information:
virtme-ng-init: Package Name: virtme-ng-init
virtme-ng-init: Package Version: 1.33+33.g5893a4b.dirty
virtme-ng-init: Manifest Directory: /home/jimc/projects/virtme-ng/virtme_ng_init
or:
_ _
__ ()_ | | _ __ ___ ___ _ __ __ _
\ \ / / | | | _ _ \ / _ ____| _ \ / _ |
\ V /| | | | || | | | | | /| | | | (| |
_/ ||| _|| || |_|_| || ||__ |
|___/
kernel version: 6.14.0-rc7-dd-00059-gb4d7289f3f54 x86_64
virtme-ng-init version: 1.33+34.g723e552.dirty
(CTRL+d to exit)
So far, its only useful for blaming, but theres room for more details, if/when any useful ones become apparent.