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
2
fn main() {
18
    #[cfg(feature = "include-git-hash-in-version")]
19
    {
20
        substrate_build_script_utils::generate_cargo_keys();
21
        // For the node/worker version check, make sure we always rebuild the node and binary workers
22
        // when the version changes.
23
        substrate_build_script_utils::rerun_if_git_head_changed();
24
    }
25
    #[cfg(not(feature = "include-git-hash-in-version"))]
26
2
    {
27
2
        let commit = "dev";
28
2
        println!("cargo:rustc-env=SUBSTRATE_CLI_COMMIT_HASH={commit}");
29
2
        println!(
30
2
            "cargo:rustc-env=SUBSTRATE_CLI_IMPL_VERSION={}",
31
2
            get_version(&commit)
32
2
        );
33
2
        // Never re-run this build script
34
2
        println!("cargo:rerun-if-changed=build.rs");
35
2
    }
36
2
}
37

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

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