Skip to content

Commit 5d579ad

Browse files
[Patch] Version & file support.
[Patch] Version & file support.
2 parents c6b4360 + 6b83a61 commit 5d579ad

5 files changed

Lines changed: 59 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ GPL-3.0 - See [LICENSE](LICENSE) for details.
4242
- **Alpha (Protostar)**: `protostar-x.x.x`
4343
- **Beta (Nova)**: `nova-x.x.x`
4444
- **Release (Supernova)**: `supernova-x.x.x`
45-
- **Snapshots (Pulsar)**: `type-x.x.x-pulsar.YYMMDD`
45+
- **Snapshots (Pulsar)**: `type-x.x.x-pulsar.YYMMDD.GITHASH`
4646

4747
Current version: **nebula-0.0.0**
4848
Snapshot/Github Actions Build version scheme: **nebula-0.0.1-pulsar.YYMMDD**

STRUCTURE.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,17 @@ cargo build
156156
# Release build
157157
cargo build --release
158158

159-
# Snapshot build (optimized but with pulsar timestamp)
159+
# Snapshot build (optimized with pulsar timestamp and git commit hash)
160160
SNAPSHOT=1 cargo build --profile=snapshot
161161
```
162162

163+
Version format:
164+
- **Debug**: `nebula-X.Y.Z-pulsar.YYMMDD`
165+
- **Snapshot**: `nebula-X.Y.Z-pulsar.YYMMDD.GITHASH`
166+
- **Release**: `nebula-X.Y.Z`
167+
168+
The git commit hash ensures snapshot builds have a unique identifier that stays the same unless changes are committed.
169+
163170
## Testing
164171

165172
```bash

build.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// build.rs
2+
// Cargo build script to capture git information at compile time
3+
4+
use std::process::Command;
5+
6+
fn main() {
7+
// Get git commit hash (short version)
8+
if let Ok(output) = Command::new("git")
9+
.args(&["rev-parse", "--short", "HEAD"])
10+
.output()
11+
{
12+
if output.status.success() {
13+
let git_hash = String::from_utf8_lossy(&output.stdout);
14+
let git_hash = git_hash.trim();
15+
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
16+
}
17+
}
18+
19+
// Rerun if git HEAD changes (commits made)
20+
println!("cargo:rerun-if-changed=.git/HEAD");
21+
println!("cargo:rerun-if-changed=.git/refs/heads");
22+
}

src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ fn main() {
4444
// Try to read and execute the file
4545
let filename = &args[1];
4646

47+
// Check if file has .nvq extension
48+
if !filename.ends_with(".nvq") {
49+
eprintln!("Error: File must have .nvq extension");
50+
eprintln!("Usage: noviq <file.nvq>");
51+
process::exit(1);
52+
}
53+
4754
match fs::read_to_string(filename) {
4855
Ok(contents) => {
4956
if let Err(e) = execute_program(&contents) {

src/utils/version.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
///
77
/// Handles version string generation based on build type:
88
/// - Release builds: nebula-X.Y.Z
9-
/// - Debug/Snapshot builds: nebula-X.Y.Z-pulsar.YYMMDD
9+
/// - Debug builds: nebula-X.Y.Z-pulsar.YYMMDD
10+
/// - Snapshot builds: nebula-X.Y.Z-pulsar.YYMMDD.BUILD
1011
1112
/// Get the current version string for Noviq
1213
pub fn get_version() -> String {
@@ -17,8 +18,13 @@ pub fn get_version() -> String {
1718
// Check if SNAPSHOT environment variable is set during build
1819
let is_snapshot = option_env!("SNAPSHOT").is_some();
1920

20-
if is_snapshot || cfg!(debug_assertions) {
21-
// Snapshot or Debug build - use snapshot format
21+
if is_snapshot {
22+
// Snapshot build - include date and build number
23+
let date = chrono::Local::now().format("%y%m%d").to_string();
24+
let build_number = get_build_number();
25+
format!("{}-pulsar.{}.{}", base_version, date, build_number)
26+
} else if cfg!(debug_assertions) {
27+
// Debug build - use snapshot format without build number
2228
let date = chrono::Local::now().format("%y%m%d").to_string();
2329
format!("{}-pulsar.{}", base_version, date)
2430
} else {
@@ -27,6 +33,18 @@ pub fn get_version() -> String {
2733
}
2834
}
2935

36+
/// Get build number based on git commit hash
37+
/// Returns the short git hash if available, otherwise "dev"
38+
fn get_build_number() -> String {
39+
// Try to get git commit hash at compile time
40+
if let Some(git_hash) = option_env!("GIT_HASH") {
41+
git_hash.to_string()
42+
} else {
43+
// Fallback to "dev" if git hash not available
44+
"dev".to_string()
45+
}
46+
}
47+
3048
/// Get package name
3149
pub fn get_package_name() -> &'static str {
3250
env!("CARGO_PKG_NAME")

0 commit comments

Comments
 (0)