-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: automatically generate version info
- Loading branch information
Showing
12 changed files
with
237 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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,2 @@ | ||
[alias] | ||
xtask = "run --package xtask --" |
This file contains 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[workspace] | ||
members = ["libIME", "tsfreg"] | ||
members = ["libIME", "tsfreg", "xtask"] | ||
resolver = "2" |
This file contains 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 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 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,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Include> | ||
<?define Version = "24.10.356.55580"?> | ||
</Include> |
This file contains 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 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,8 @@ | ||
#define VER_FILEVERSION 24,10,356,55580 | ||
#define VER_FILEVERSION_STR "24.10.356.55580\0" | ||
#define VER_PRODUCTVERSION 24,10,356,55580 | ||
#define VER_PRODUCTVERSION_STR "24.10.356.55580\0" | ||
#define ABOUT_CAPTION_WITH_VER "關於新酷音輸入法 (24.10.356.55580)\0" | ||
#define ABOUT_VERSION_STR "版本:24.10.356.55580\0" | ||
#define ABOUT_RELEASE_DATE_STR "發行日期:2024 年 12 月 21 日\0" | ||
#define PREFS_TITLE_WITH_VER "設定新酷音輸入法 (24.10.356.55580)\0" |
This file contains 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,10 @@ | ||
[package] | ||
name = "xtask" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
anyhow = "1.0.94" | ||
indoc = "2.0.5" | ||
jiff = "0.1.15" | ||
xflags = "0.3.2" |
This file contains 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,113 @@ | ||
use std::fs::File; | ||
use std::io::Write; | ||
|
||
use jiff::{Timestamp, Zoned}; | ||
|
||
mod flags { | ||
xflags::xflags! { | ||
src "src/main.rs" | ||
|
||
/// cargo-xtask helper | ||
cmd xtask { | ||
/// Update the version.rc file. | ||
cmd update-version { | ||
/// The year of the release. (u32) | ||
required -y, --year YY: u32 | ||
/// The month of the release. (u32) | ||
required -m, --month MM: u32 | ||
/// The revision of the release. (u32) | ||
required -r, --rev REV: u32 | ||
/// Generating release version, or nightly version. | ||
optional --nightly | ||
} | ||
} | ||
} | ||
// generated start | ||
// The following code is generated by `xflags` macro. | ||
// Run `env UPDATE_XFLAGS=1 cargo build` to regenerate. | ||
#[derive(Debug)] | ||
pub struct Xtask { | ||
pub subcommand: XtaskCmd, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum XtaskCmd { | ||
UpdateVersion(UpdateVersion), | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct UpdateVersion { | ||
pub year: u32, | ||
pub month: u32, | ||
pub rev: u32, | ||
pub nightly: bool, | ||
} | ||
|
||
impl Xtask { | ||
#[allow(dead_code)] | ||
pub fn from_env_or_exit() -> Self { | ||
Self::from_env_or_exit_() | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub fn from_env() -> xflags::Result<Self> { | ||
Self::from_env_() | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> { | ||
Self::from_vec_(args) | ||
} | ||
} | ||
// generated end | ||
} | ||
|
||
fn main() -> anyhow::Result<()> { | ||
let flags = flags::Xtask::from_env()?; | ||
|
||
match flags.subcommand { | ||
flags::XtaskCmd::UpdateVersion(update_version) => { | ||
let now = Zoned::now(); | ||
let epoch: Timestamp = now.start_of_day()?.timestamp(); | ||
let year = now.year(); | ||
let month = now.month(); | ||
let day = now.day(); | ||
let day_of_year = now.day_of_year() as u32; | ||
let sec = Timestamp::now().as_second() - epoch.as_second(); | ||
let yy = update_version.year; | ||
let mm = update_version.month; | ||
let rv = if update_version.nightly { | ||
10_000 * update_version.rev + 9_000 + day_of_year | ||
} else { | ||
10_000 * update_version.rev + day_of_year | ||
}; | ||
let mut version_rc = File::create("version.rc")?; | ||
indoc::writedoc!( | ||
version_rc, | ||
r#" | ||
#define VER_FILEVERSION {yy},{mm},{rv},{sec} | ||
#define VER_FILEVERSION_STR "{yy}.{mm}.{rv}.{sec}\0" | ||
#define VER_PRODUCTVERSION {yy},{mm},{rv},{sec} | ||
#define VER_PRODUCTVERSION_STR "{yy}.{mm}.{rv}.{sec}\0" | ||
#define ABOUT_CAPTION_WITH_VER "關於新酷音輸入法 ({yy}.{mm}.{rv}.{sec})\0" | ||
#define ABOUT_VERSION_STR "版本:24.{mm}.{rv}.{sec}\0" | ||
#define ABOUT_RELEASE_DATE_STR "發行日期:{year} 年 {month:02} 月 {day:02} 日\0" | ||
#define PREFS_TITLE_WITH_VER "設定新酷音輸入法 ({yy}.{mm}.{rv}.{sec})\0" | ||
"# | ||
)?; | ||
|
||
let mut version_wxi = File::create("installer/version.wxi")?; | ||
indoc::writedoc!( | ||
version_wxi, | ||
r#" | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Include> | ||
<?define Version = "{yy}.{mm}.{rv}.{sec}"?> | ||
</Include> | ||
"# | ||
)?; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |