Skip to content
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

[tech] Add a precise git_version to transit-model #754

Merged
merged 5 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ typed_index_collection = "1"
walkdir = "2"
wkt = "0.8"
zip = { version = "0.5", default-features = false, features = ["deflate"] }
git-version = "0.3"

[[test]]
name = "write_netex_france"
Expand Down
1 change: 1 addition & 0 deletions gtfs2netexfr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ slog-stdlog = "4.0"
slog-term = "2.4"
structopt = "0.3"
transit_model = { version = "0.34", path = "../", features = ["proj"] }
lazy_static = "1"
10 changes: 9 additions & 1 deletion gtfs2netexfr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@ use std::path::PathBuf;
use structopt::StructOpt;
use transit_model::{read_utils, Result};

lazy_static::lazy_static! {
pub static ref GIT_VERSION: String = transit_model::binary_full_version(env!("CARGO_PKG_VERSION"));
}

fn get_version() -> &'static str {
&GIT_VERSION
}

#[derive(Debug, StructOpt)]
#[structopt(name = "gtfs2netexfr", about = "Convert a GTFS to NeTEx France.")]
#[structopt(name = "gtfs2netexfr", about = "Convert a GTFS to NeTEx France.", version = get_version())]
struct Opt {
/// Input directory.
#[structopt(short, long, parse(from_os_str), default_value = ".")]
Expand Down
1 change: 1 addition & 0 deletions gtfs2ntfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ slog-stdlog = "4.0"
slog-term = "2.4"
structopt = "0.3"
transit_model = { version = "0.34", path = "../" }
lazy_static = "1"
10 changes: 9 additions & 1 deletion gtfs2ntfs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@ use std::path::PathBuf;
use structopt::StructOpt;
use transit_model::{read_utils, transfers::generates_transfers, PrefixConfiguration, Result};

lazy_static::lazy_static! {
pub static ref GIT_VERSION: String = transit_model::binary_full_version(env!("CARGO_PKG_VERSION"));
}

fn get_version() -> &'static str {
&GIT_VERSION
}

#[derive(Debug, StructOpt)]
#[structopt(name = "gtfs2ntfs", about = "Convert a GTFS to an NTFS.")]
#[structopt(name = "gtfs2ntfs", about = "Convert a GTFS to an NTFS.", version = get_version())]
struct Opt {
/// Input directory.
#[structopt(short, long, parse(from_os_str), default_value = ".")]
Expand Down
1 change: 1 addition & 0 deletions ntfs2gtfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ slog-stdlog = "4.0"
slog-term = "2.4"
structopt = "0.3"
transit_model = { version = "0.34", path = "../" }
lazy_static = "1"
10 changes: 9 additions & 1 deletion ntfs2gtfs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ use std::path::PathBuf;
use structopt::StructOpt;
use transit_model::Result;

lazy_static::lazy_static! {
pub static ref GIT_VERSION: String = transit_model::binary_full_version(env!("CARGO_PKG_VERSION"));
}

fn get_version() -> &'static str {
&GIT_VERSION
}

#[derive(Debug, StructOpt)]
#[structopt(name = "ntfs2gtfs", about = "Convert an NTFS to a GTFS.")]
#[structopt(name = "ntfs2gtfs", about = "Convert an NTFS to a GTFS.", version = get_version())]
struct Opt {
/// Input directory.
#[structopt(short, long, parse(from_os_str), default_value = ".")]
Expand Down
1 change: 1 addition & 0 deletions ntfs2netexfr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ slog-stdlog = "4.0"
slog-term = "2.4"
structopt = "0.3"
transit_model = { version = "0.34", path = "../", features = ["proj"] }
lazy_static = "1"
10 changes: 9 additions & 1 deletion ntfs2netexfr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ use std::path::PathBuf;
use structopt::StructOpt;
use transit_model::Result;

lazy_static::lazy_static! {
pub static ref GIT_VERSION: String = transit_model::binary_full_version(env!("CARGO_PKG_VERSION"));
}

fn get_version() -> &'static str {
&GIT_VERSION
}

#[derive(Debug, StructOpt)]
#[structopt(name = "ntfs2netexfr", about = "Convert a NTFS to NeTEx France.")]
#[structopt(name = "ntfs2netexfr", about = "Convert a NTFS to NeTEx France.", version = get_version())]
struct Opt {
/// Input directory.
#[structopt(short, long, parse(from_os_str), default_value = ".")]
Expand Down
1 change: 1 addition & 0 deletions ntfs2ntfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ slog-stdlog = "4.0"
slog-term = "2.4"
structopt = "0.3"
transit_model = { version = "0.34", path = "../" }
lazy_static = "1"
10 changes: 9 additions & 1 deletion ntfs2ntfs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ use std::path::PathBuf;
use structopt::StructOpt;
use transit_model::{transfers::generates_transfers, Result};

lazy_static::lazy_static! {
pub static ref GIT_VERSION: String = transit_model::binary_full_version(env!("CARGO_PKG_VERSION"));
}

fn get_version() -> &'static str {
&GIT_VERSION
}
pbougue marked this conversation as resolved.
Show resolved Hide resolved

#[derive(Debug, StructOpt)]
#[structopt(name = "ntfs2ntfs", about = "Convert an NTFS to an NTFS.")]
#[structopt(name = "ntfs2ntfs", about = "Convert an NTFS to an NTFS.", version = get_version())]
struct Opt {
/// Input directory.
#[structopt(short = "i", long = "input", parse(from_os_str), default_value = ".")]
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub mod read_utils;
pub mod test_utils;
pub mod transfers;
pub mod validity_period;
mod version_utils;
pub mod vptranslator;

/// Current version of the NTFS format
Expand All @@ -82,3 +83,5 @@ pub type Error = failure::Error;
pub type Result<T, E = Error> = std::result::Result<T, E>;

pub use crate::model::Model;

pub use crate::version_utils::{binary_full_version, GIT_VERSION};
25 changes: 25 additions & 0 deletions src/version_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (C) 2017 Kisio Digital and/or its affiliates.
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Affero General Public License as published by the
// Free Software Foundation, version 3.

// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
// details.

// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>
//! Some utility to get the transit_model version

/// Precise git version of transit_model
/// the version will be:
/// v{last github tag}-{commit number}-{commit hash}{"-modified" if some changes have been done since last commit}
pub const GIT_VERSION: &str =
pbougue marked this conversation as resolved.
Show resolved Hide resolved
git_version::git_version!(args = ["--tags", "--dirty=-modified"], fallback = "unknown");
pbougue marked this conversation as resolved.
Show resolved Hide resolved

/// get the binary version and the transit_model version
pub fn binary_full_version(binary_version: &str) -> String {
format!("{} (transit_model = {})", binary_version, GIT_VERSION)
}
Comment on lines +23 to +25
Copy link
Contributor

@pbougue pbougue Mar 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be able to track more than one deps (and reuse it in binaries using libs that depends on tm), should we already do something like:

Suggested change
pub fn binary_full_version(binary_version: &str) -> String {
format!("{} (transit_model = {})", binary_version, GIT_VERSION)
}
pub fn binary_full_version(binary_version: &str, other_deps_versions: &str) -> String {
format!("{} ({} transit_model = {})", binary_version, other_deps_versions, GIT_VERSION)
}

The deps-separating , could be handled via an option on other_deps_versions, or just asked-for into this other_deps_versions (like this suggestion).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hum don't you think the other dependency will have it's own way of tracking the version? i don't really think it's the right place to put it but maybe we can talk about it.

Copy link
Contributor

@pbougue pbougue Mar 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so the plan in binaries-that-depends-on-lib-depending-on-TM is to pass GIT_VERSION of the lib-depending-on-TM into binary_version (and forget about CARGO_PKG_VERSION of binaries).