aboutsummaryrefslogtreecommitdiff
path: root/generate-version-file
diff options
context:
space:
mode:
authorIgor Murashkin <iam@google.com>2016-03-16 14:11:09 -0700
committerIgor Murashkin <iam@google.com>2016-03-21 16:22:29 -0700
commit5aa66a3827c97e22b9e79981d02f0ceb4f67ae93 (patch)
tree539bd2b8093c1eea4a8253c90efaffe800502dcf /generate-version-file
parentfa1d2ba08cc2e5f66039294dd7887f9bd5cc6d89 (diff)
downloadtestng-5aa66a3827c97e22b9e79981d02f0ceb4f67ae93.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: I71b4f3b26b9307b36444cecc75d67de03be9cb23
Diffstat (limited to 'generate-version-file')
-rwxr-xr-xgenerate-version-file57
1 files changed, 57 insertions, 0 deletions
diff --git a/generate-version-file b/generate-version-file
new file mode 100755
index 00000000..345ad5a8
--- /dev/null
+++ b/generate-version-file
@@ -0,0 +1,57 @@
+#!/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
+
+# Apply the template, replacing @version@ with the VERSION.
+sed "$template_file" -e "s:$template_variable:$stored_value:g"