diff options
author | Igor Murashkin <iam@google.com> | 2016-03-24 13:03:16 -0700 |
---|---|---|
committer | Igor Murashkin <iam@google.com> | 2016-03-24 13:06:45 -0700 |
commit | 94770dd065d3cc966479d651c836d1acc960dcdd (patch) | |
tree | e4d09fe0ca9326835cbb22b5aebbf9e446d1ff1a /generate-version-file | |
parent | 5afa1ec040d81a423a7ec16563e339ed7d21c547 (diff) | |
download | testng-94770dd065d3cc966479d651c836d1acc960dcdd.tar.gz |
build: Add support for building testng within the AOSP (host only).
Also abstracts out some dependencies that are unsupported on android
to be behind interfaces. Ant and Bsh support is excluded.
Bug: 27552463
Change-Id: I71b4f3b26b9307b36444cecc75d67de03be9cb24
Diffstat (limited to 'generate-version-file')
-rwxr-xr-x | generate-version-file | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/generate-version-file b/generate-version-file new file mode 100755 index 00000000..d17edc32 --- /dev/null +++ b/generate-version-file @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +# Copyright (C) 2016 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Nominally used to generate the "Version.java" file, but in theory could be used +# for any super simple template generation as well. + +if [[ $# -lt 4 ]]; then + echo "Usage: $(basename $0) <template-file> <template-variable> <value-file> <value-variable>" >&2 + echo "" + echo 'For example, ./generate-version-file src/main/resources/org/testng/internal/VersionTemplateJava "@version@" kobalt/src/Build.kt "VERSION"' + exit 1 +fi + +template_file="$1" +template_variable="$2" +value_file="$3" +value_variable="$4" + +if ! [[ -f $template_file ]]; then + echo "Error: Template file $template_file does not exist." >&2 + exit 1 +fi + +if ! [[ -f $value_file ]]; then + echo "Error: Value file $value_File does not exist." >&2 + exit 1 +fi + +# Read a 'val VERSION = "SOME_VERSION"' from the file, trim down to $SOME_VERSION. +stored_value="$(egrep "val[[:space:]]+$value_variable" "$value_file" | awk 'NF>1{print $NF}' | tr -d '"')" +if [[ $? -ne 0 ]]; then + echo "Error: Could not find value $value_variable in $value_file of syntax 'val $value_variable = \"SOME_VALUE\"'" >&2 + exit 1 +fi + +# Ensure that the template does indeed have @version@ +if ! grep --silent "$template_variable" "$template_file"; then + echo "Error: Template file $template_file has no instances of template variable $template_variable." >&2 + exit 1 +fi + +set -e + +# Apply the template, replacing @version@ with the VERSION. +sed -e "s:$template_variable:$stored_value:g" "$template_file" |