Skip to content

Commit

Permalink
Merge pull request #46 from squidowl/ci/version
Browse files Browse the repository at this point in the history
Add version
  • Loading branch information
casperstorm committed Jun 23, 2023
2 parents c8d63fb + 31e57eb commit f8b6b2d
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023.1-alpha1
2 changes: 1 addition & 1 deletion assets/halloy.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
<developer_name>The Squidowl Development Team</developer_name>

<releases>
<release version="0.1.0-9025433" date="2023-06-23" />
<release version="2023.1-alpha1" date="2023-06-23" />
</releases>
</component>
51 changes: 51 additions & 0 deletions data/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use std::path::Path;
use std::process::Command;

const VERSION: &str = include_str!("../VERSION");

fn main() {
let git_hash = Command::new("git")
.args(["describe", "--always", "--dirty", "--exclude='*'"])
.output()
.ok()
.filter(|output| output.status.success())
.and_then(|x| String::from_utf8(x.stdout).ok());

println!("cargo:rerun-if-changed=../VERSION");
println!("cargo:rustc-env=VERSION={}", VERSION);

if let Some(hash) = git_hash.as_ref() {
println!("cargo:rustc-env=GIT_HASH={}", hash);
}

if git_hash.is_none() {
return;
}

let Some(git_dir): Option<String> = Command::new("git")
.args(["rev-parse", "--git-dir"])
.output()
.ok()
.filter(|output| output.status.success())
.and_then(|x| String::from_utf8(x.stdout).ok())
else{ return; };
// If heads starts pointing at something else (different branch)
// we need to return
let head = Path::new(&git_dir).join("HEAD");
if head.exists() {
println!("cargo:rerun-if-changed={}", head.display());
}
// if the thing head points to (branch) itself changes
// we need to return
let Some(head_ref): Option<String> = Command::new("git")
.args(["symbolic-ref", "HEAD"])
.output()
.ok()
.filter(|output| output.status.success())
.and_then(|x| String::from_utf8(x.stdout).ok())
else{ return; };
let head_ref = Path::new(&git_dir).join(head_ref);
if head_ref.exists() {
println!("cargo:rerun-if-changed={}", head_ref.display());
}
}
15 changes: 13 additions & 2 deletions data/src/environment.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
use std::env;
use std::path::{Path, PathBuf};

pub fn config_dir() -> Option<PathBuf> {
pub const VERSION: &str = env!("VERSION");
pub const GIT_HASH: Option<&str> = option_env!("GIT_HASH");

pub fn formatted_version() -> String {
let hash = GIT_HASH
.map(|hash| format!(" ({hash})"))
.unwrap_or_default();

format!("{}{hash}", VERSION)
}

pub(crate) fn config_dir() -> Option<PathBuf> {
// HOST_* checked first for flatpak
#[cfg(target_os = "linux")]
{
Expand All @@ -18,7 +29,7 @@ pub fn config_dir() -> Option<PathBuf> {
}
}

pub fn data_dir() -> Option<PathBuf> {
pub(crate) fn data_dir() -> Option<PathBuf> {
// HOST_* checked first for flatpak
#[cfg(target_os = "linux")]
{
Expand Down
2 changes: 1 addition & 1 deletion data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub mod client;
pub mod command;
mod compression;
pub mod config;
mod environment;
pub mod environment;
pub mod history;
pub mod input;
pub mod log;
Expand Down
23 changes: 20 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ mod screen;
mod theme;
mod widget;

use std::env;

use data::config::{self, Config};
use data::stream;
use iced::widget::container;
Expand All @@ -21,16 +23,31 @@ use self::screen::dashboard;
pub use self::theme::Theme;
use self::widget::Element;

pub const VERSION: &str = env!("CARGO_PKG_VERSION");

pub fn main() -> iced::Result {
let mut args = env::args();
args.next();

let version = args
.next()
.map(|s| s == "--version" || s == "-V")
.unwrap_or_default();

if version {
println!("halloy {}", data::environment::formatted_version());

return Ok(());
}

#[cfg(debug_assertions)]
let is_debug = true;
#[cfg(not(debug_assertions))]
let is_debug = false;

logger::setup(is_debug).expect("setup logging");
log::info!("application ({}) has started", VERSION);
log::info!(
"halloy {} has started",
data::environment::formatted_version()
);

if let Err(error) = Halloy::run(settings()) {
log::error!("{}", error.to_string());
Expand Down

0 comments on commit f8b6b2d

Please sign in to comment.