diff options
author | David 'Digit' Turner <digit@google.com> | 2010-04-06 18:14:38 -0700 |
---|---|---|
committer | David 'Digit' Turner <digit@google.com> | 2010-04-07 16:43:49 -0700 |
commit | 67c22255b157f1945d478b5cc44f603352b0d8b5 (patch) | |
tree | 8990c39c122abbe320ea29ab93194ad272725c58 | |
parent | f2debec88ac7dabc769cf53a32a46706513ddd03 (diff) | |
download | ndk-67c22255b157f1945d478b5cc44f603352b0d8b5.tar.gz |
Add two awk scripts that will be used by the ndk debugging helper scripts.
Change-Id: I9b1d6f39fd33f5b7cbc2e875a292f5901780ce26
-rw-r--r-- | build/core/extract-package-name.awk | 49 | ||||
-rw-r--r-- | build/core/extract-package-pid.awk | 40 |
2 files changed, 89 insertions, 0 deletions
diff --git a/build/core/extract-package-name.awk b/build/core/extract-package-name.awk new file mode 100644 index 000000000..6107ea758 --- /dev/null +++ b/build/core/extract-package-name.awk @@ -0,0 +1,49 @@ +# Copyright (C) 2010 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. +# +# A nawk/gawk script used to extract the package name from an application's +# manifest (i.e. AndroidManifest.xml). +# +# The name itself is the value of the 'package' attribute in the +# 'manifest' element. +# + +BEGIN { + FS=" " + in_manifest=0 + package_regex1="package=\"([[:alnum:].]+)\"" + package_regex2="package=\'([[:alnum:].]+)\'" + PACKAGE="<none>" +} + +/<manifest/ { + in_manifest=1 +} + +in_manifest == 1 && /package=/ { + if (match($0,package_regex1)) { + PACKAGE=substr($0,RSTART+9,RLENGTH-10) + } + else if (match($0,package_regex2)) { + PACKAGE=substr($0,RSTART+9,RLENGTH-10) + } +} + +in_manifest == 1 && />/ { + in_manifest=0 +} + +END { + print PACKAGE +} diff --git a/build/core/extract-package-pid.awk b/build/core/extract-package-pid.awk new file mode 100644 index 000000000..5f5b52386 --- /dev/null +++ b/build/core/extract-package-pid.awk @@ -0,0 +1,40 @@ +# Copyright (C) 2010 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. +# + +# Extract the pid of a given package name. This assumes that the +# input is the product of 'adb shell ps' and that the PACKAGE variable +# has been initialized to the package's name. In other words, this should +# be used as: +# +# adb shell ps | awk -f <this-script> -v PACKAGE=<name> +# +# The printed value will be 0 if the package is not found. +# + +BEGIN { + PID=0 + FS=" " +} + +# We use the fact that the 9th column of the 'ps' output +# contains the package name, while the 2nd one contains the pid +# +$9 == PACKAGE { + PID=$2 +} + +END { + print PID +} |