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

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

            
45
2
    format!(
46
2
        "{}{}{}",
47
2
        std::env::var("CARGO_PKG_VERSION").unwrap_or_default(),
48
        commit_dash,
49
        impl_commit
50
    )
51
2
}