OSDN Git Service

Add two awk scripts that will be used by the ndk debugging helper scripts.
authorDavid 'Digit' Turner <digit@google.com>
Wed, 7 Apr 2010 01:14:38 +0000 (18:14 -0700)
committerDavid 'Digit' Turner <digit@google.com>
Wed, 7 Apr 2010 23:43:49 +0000 (16:43 -0700)
Change-Id: I9b1d6f39fd33f5b7cbc2e875a292f5901780ce26

build/core/extract-package-name.awk [new file with mode: 0644]
build/core/extract-package-pid.awk [new file with mode: 0644]

diff --git a/build/core/extract-package-name.awk b/build/core/extract-package-name.awk
new file mode 100644 (file)
index 0000000..6107ea7
--- /dev/null
@@ -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 (file)
index 0000000..5f5b523
--- /dev/null
@@ -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
+}