1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

            
4
// Tanssi is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

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

            
14
// You should have received a copy of the GNU General Public License
15
// along with Tanssi.  If not, see <http://www.gnu.org/licenses/>
16

            
17
fn main() {
18
    #[cfg(feature = "include-git-hash-in-version")]
19
    {
20
        substrate_build_script_utils::generate_cargo_keys();
21
        substrate_build_script_utils::rerun_if_git_head_changed();
22
    }
23
    #[cfg(not(feature = "include-git-hash-in-version"))]
24
    {
25
        let commit = "dev";
26
        println!("cargo:rustc-env=SUBSTRATE_CLI_COMMIT_HASH={commit}");
27
        println!(
28
            "cargo:rustc-env=SUBSTRATE_CLI_IMPL_VERSION={}",
29
            get_version(&commit)
30
        );
31
        // Never re-run this build script
32
        println!("cargo:rerun-if-changed=build.rs");
33
    }
34
}
35

            
36
#[cfg(not(feature = "include-git-hash-in-version"))]
37
fn get_version(impl_commit: &str) -> String {
38
    let commit_dash = if impl_commit.is_empty() { "" } else { "-" };
39

            
40
    format!(
41
        "{}{}{}",
42
        std::env::var("CARGO_PKG_VERSION").unwrap_or_default(),
43
        commit_dash,
44
        impl_commit
45
    )
46
}