diff --git a/Cargo.lock b/Cargo.lock index 38ca92fefd..3248861ba6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4188,7 +4188,7 @@ dependencies = [ [[package]] name = "mm2_bin_lib" -version = "0.1.0" +version = "1.0.0-beta" dependencies = [ "chrono", "common", diff --git a/azure-pipelines-android-job.yml b/azure-pipelines-android-job.yml index 80ff96fc72..817cc9582a 100644 --- a/azure-pipelines-android-job.yml +++ b/azure-pipelines-android-job.yml @@ -23,7 +23,7 @@ jobs: echo "##vso[task.setvariable variable=COMMIT_HASH]${TAG}" displayName: Setup ENV - bash: | - VERSION=2.1.$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_android_armv7_CI + VERSION=$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_android_armv7_CI if ! grep -q $VERSION MM_VERSION; then echo $VERSION > MM_VERSION fi @@ -34,7 +34,7 @@ jobs: env: MANUAL_MM_VERSION: true - bash: | - VERSION=2.1.$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_android_aarch64_CI + VERSION=$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_android_aarch64_CI if ! grep -q $VERSION MM_VERSION; then echo $VERSION > MM_VERSION fi diff --git a/azure-pipelines-build-stage-job.yml b/azure-pipelines-build-stage-job.yml index bbb704c242..8cdcc82e9e 100644 --- a/azure-pipelines-build-stage-job.yml +++ b/azure-pipelines-build-stage-job.yml @@ -35,7 +35,7 @@ jobs: - bash: | rm -rf upload mkdir upload - VERSION=2.1.$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_$(Agent.OS)_CI + VERSION=$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_$(Agent.OS)_CI if ! grep -q $VERSION MM_VERSION; then echo $VERSION > MM_VERSION fi diff --git a/azure-pipelines-ios-job.yml b/azure-pipelines-ios-job.yml index 8c6126f686..d513287742 100644 --- a/azure-pipelines-ios-job.yml +++ b/azure-pipelines-ios-job.yml @@ -23,7 +23,7 @@ jobs: echo "##vso[task.setvariable variable=COMMIT_HASH]${TAG}" displayName: Setup ENV - bash: | - VERSION=2.1.$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_ios_aarch64_CI + VERSION=$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_ios_aarch64_CI if ! grep -q $VERSION MM_VERSION; then echo $VERSION > MM_VERSION fi diff --git a/azure-pipelines-release-stage-job.yml b/azure-pipelines-release-stage-job.yml index 1f766a6591..06ef60c34e 100644 --- a/azure-pipelines-release-stage-job.yml +++ b/azure-pipelines-release-stage-job.yml @@ -41,7 +41,7 @@ jobs: mkdir upload displayName: 'Recreate upload dir' - bash: | - VERSION=2.1.$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_$(Agent.OS)_Debug + VERSION=$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_$(Agent.OS)_Debug if ! grep -q $VERSION MM_VERSION; then echo $VERSION > MM_VERSION fi @@ -83,7 +83,7 @@ jobs: condition: and( eq( variables['Agent.OS'], 'Windows_NT' ), eq( variables['DEBUG_UPLOADED'], '' ) ) - bash: | rm -f MM_VERSION - VERSION=2.1.$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_$(Agent.OS)_Release + VERSION=$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_$(Agent.OS)_Release if ! grep -q $VERSION MM_VERSION; then echo $VERSION > MM_VERSION fi diff --git a/azure-pipelines-wasm-stage-job.yml b/azure-pipelines-wasm-stage-job.yml index cb7aef5fd7..350b194eae 100644 --- a/azure-pipelines-wasm-stage-job.yml +++ b/azure-pipelines-wasm-stage-job.yml @@ -35,7 +35,7 @@ jobs: - bash: | rm -rf upload mkdir upload - VERSION=2.1.$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_$(Agent.OS)_Release + VERSION=$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_$(Agent.OS)_Release if ! grep -q $VERSION MM_VERSION; then echo $VERSION > MM_VERSION fi diff --git a/mm2src/mm2_bin_lib/Cargo.toml b/mm2src/mm2_bin_lib/Cargo.toml index 932b7bb76b..c2788a80c3 100644 --- a/mm2src/mm2_bin_lib/Cargo.toml +++ b/mm2src/mm2_bin_lib/Cargo.toml @@ -5,7 +5,8 @@ [package] name = "mm2_bin_lib" -version = "0.1.0" +version = "1.0.0-beta" +authors = ["James Lee", "Artem Pikulin", "Artem Grinblat", "Omar S.", "Onur Ozkan", "Alina Sharon", "Caglar Kaya", "Cipi", "Sergey Boiko", "Samuel Onoja", "Roman Sztergbaum", "Kadan Stadelmann "] edition = "2018" default-run = "mm2" diff --git a/mm2src/mm2_bin_lib/build.rs b/mm2src/mm2_bin_lib/build.rs index 41b95486b4..c05c39a364 100644 --- a/mm2src/mm2_bin_lib/build.rs +++ b/mm2src/mm2_bin_lib/build.rs @@ -46,36 +46,29 @@ fn root() -> PathBuf { /// we might skip synchronizing the Git repository there), /// but if it is, then we're going to check if the “MM_DATETIME” and the Git data match. fn mm_version() -> String { - // We fetch the actual git version here, - // with `git log '--pretty=format:%h' -n 1` for the nightlies, - // and a release tag when building from some kind of a stable branch, - // though we should keep the ability for the tooling to provide the “MM_VERSION” - // externally, because moving the entire ".git" around is not always practical. - let mut version = "UNKNOWN".to_string(); - let mut command = Command::new("git"); - command.arg("log").arg("--pretty=format:%h").arg("-n1"); - if let Ok(go) = command.output() { - if go.status.success() { - version = from_utf8(&go.stdout).unwrap().trim().to_string(); - if !Regex::new(r"^\w+$").unwrap().is_match(&version) { - panic!("{}", version) - } - } - } + // Reading version of `mm2_bin_lib` from cargo manifest + let mut version = env!("CARGO_PKG_VERSION").to_owned(); let mm_version_p = root().join("../../MM_VERSION"); let v_file = String::from_utf8(slurp(&mm_version_p)).unwrap(); - let v_file = v_file.trim().to_string(); - // if there is no MM_VERSION file there is no need to create it + + // if there is MM_VERSION file, that means CI wants to put a tag to version if !v_file.is_empty() { - if !v_file.contains(&version) { - // If the file doesn't contain the latest commit hash then this is a local build - // and the env version variable should be "v_file"_"version" as "v_file" is the version from the local file - // and "version" is the latest commit hash - version = format!("{}_{}", v_file, version); - } else { - // If the file contains the latest commit hash then this is a CI build and the version generated by CI should be written to env - version = v_file; + version = format!("{}_{}", version, v_file.trim()); + } + // put commit tag to the version + else { + let mut command = Command::new("git"); + command.arg("log").arg("--pretty=format:%h").arg("-n1"); + if let Ok(go) = command.output() { + if go.status.success() { + let commit_hash = from_utf8(&go.stdout).unwrap().trim().to_string(); + if !Regex::new(r"^\w+$").unwrap().is_match(&commit_hash) { + panic!("{}", commit_hash) + } + + version = format!("{version}_{commit_hash}"); + } } } diff --git a/mm2src/mm2_main/src/mm2.rs b/mm2src/mm2_main/src/mm2.rs index 8544420b59..2281cd11a9 100644 --- a/mm2src/mm2_main/src/mm2.rs +++ b/mm2src/mm2_main/src/mm2.rs @@ -339,7 +339,6 @@ pub fn mm2_main(version: String, datetime: String) { use libc::c_char; init_crash_reports(); - log!("AtomicDEX MarketMaker {} DT {}", version, datetime); // Temporarily simulate `argv[]` for the C version of the main method. let args: Vec = env::args() @@ -376,15 +375,23 @@ pub fn mm2_main(version: String, datetime: String) { return; } + if first_arg == Some("--version") || first_arg == Some("-v") || first_arg == Some("version") { + println!("AtomicDEX API: {version}"); + return; + } + if first_arg == Some("--help") || first_arg == Some("-h") || first_arg == Some("help") { help(); return; } + if cfg!(windows) && first_arg == Some("/?") { help(); return; } + log!("AtomicDEX API {} DT {}", version, datetime); + if let Err(err) = run_lp_main(first_arg, &|_| (), version, datetime) { log!("{}", err); exit(1);