1# Copyright 2022 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15#!/usr/bin/env bash 16# 17# Bump the version. 18# 19# The CARGO_PKG_VERSION is not available for Android.bp builds 20# so bump versions using a script. 21# 22 23# Absolute path to this script 24SCRIPT=$(dirname $(readlink -f "$0")) 25export CARGO=$SCRIPT/../rust/daemon/Cargo.toml 26export CARGO_CLI=$SCRIPT/../rust/cli/Cargo.toml 27export CARGO_COMMON=$SCRIPT/../rust/common/Cargo.toml 28export VERSION=$SCRIPT/../rust/daemon/src/version.rs 29python <<EOF 30import re 31import os 32 33m = None 34for cargo in [os.environ["CARGO_COMMON"], os.environ["CARGO_CLI"], os.environ["CARGO"]]: 35 with open(cargo, "r+") as f: 36 37 version = re.compile(r'^version\s=\s"(\d+)\.(\d+)\.(\d+)"$') 38 39 lines = f.readlines() 40 for i, line in enumerate(lines): 41 # Check if the line contains the string "version = " 42 # and replace 43 m = version.match(line) 44 if m: 45 lines[i] = 'version = "{0}.{1}.{2}"\n'.format(m[1], m[2], int(m[3]) + 1) 46 break 47 48 f.seek(0) 49 f.writelines(lines) 50 51with open(os.environ["VERSION"], "r+") as f: 52 lines = f.readlines() 53 for i, line in enumerate(lines): 54 if line.startswith("pub const VERSION"): 55 lines[i] = 'pub const VERSION: &str = "{0}.{1}.{2}";\n'.format( 56 m[1], m[2], (int(m[3]) + 1)) 57 break 58 59 f.seek(0) 60 f.writelines(lines) 61 62EOF 63