Merge "Convert external/smali to Android.bp"
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..40faeef
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,28 @@
+// Copyright (C) 2017 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.
+
+filegroup {
+    name: "smali_script",
+    srcs: ["scripts/smali"],
+}
+
+filegroup {
+    name: "baksmali_script",
+    srcs: ["scripts/baksmali"],
+}
+
+filegroup {
+    name: "smali_build.gradle",
+    srcs: ["build.gradle"],
+}
diff --git a/baksmali/Android.bp b/baksmali/Android.bp
new file mode 100644
index 0000000..7f95539
--- /dev/null
+++ b/baksmali/Android.bp
@@ -0,0 +1,44 @@
+// 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.
+
+//create a new baksmali.properties file using the correct version
+genrule {
+    name: "baksmali_version",
+    srcs: [":smali_build.gradle"],
+    out: ["baksmali.properties"],
+    cmd: "echo \"application.version=$$(grep -o -e \"^version = '\\(.*\\)'\" $(in) | grep -o -e \"[0-9.]\\+\")-aosp\" > $(out)",
+}
+
+// build baksmali jar
+// ============================================================
+
+java_binary_host {
+    name: "baksmali",
+
+    srcs: [
+        "src/main/java/**/*.java",
+    ],
+
+    manifest: "manifest.txt",
+
+    static_libs: [
+        "dexlib2",
+        "smali-util",
+        "jcommander",
+    ],
+
+    java_resources: [":baksmali_version"],
+
+    wrapper: ":baksmali_script",
+}
diff --git a/baksmali/Android.mk b/baksmali/Android.mk
deleted file mode 100644
index 5e828ed..0000000
--- a/baksmali/Android.mk
+++ /dev/null
@@ -1,62 +0,0 @@
-# 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.
-
-LOCAL_PATH := $(call my-dir)
-
-# build baksmali jar
-# ============================================================
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := baksmalilib
-
-LOCAL_MODULE_TAGS := optional
-
-#LOCAL_MODULE_CLASS and LOCAL_IS_HOST_MODULE must be defined before calling $(local-intermediates-dir)
-LOCAL_MODULE_CLASS := JAVA_LIBRARIES
-LOCAL_IS_HOST_MODULE := true
-
-intermediates := $(call local-intermediates-dir,COMMON)
-
-LOCAL_SRC_FILES := \
-	$(call all-java-files-under, src/main/java) \
-	$(call all-java-files-under, ../util/src/main/java)
-
-LOCAL_JAR_MANIFEST := manifest.txt
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
-	dexlib2 \
-	jcommander-host
-
-#create a new baksmali.properties file using the correct version
-$(intermediates)/resources/baksmali.properties: $(LOCAL_PATH)/../build.gradle
-	$(hide) mkdir -p $(dir $@)
-	$(hide) echo "application.version=$$(grep -o -e "^version = '\(.*\)'" $< | grep -o -e "[0-9.]\+")-aosp" >$@
-
-LOCAL_JAVA_RESOURCE_FILES := $(intermediates)/resources/baksmali.properties
-
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-
-
-# copy baksmali script
-# ============================================================
-
-include $(CLEAR_VARS)
-LOCAL_IS_HOST_MODULE := true
-LOCAL_MODULE_CLASS := EXECUTABLES
-LOCAL_MODULE := baksmali
-LOCAL_SRC_FILES := ../scripts/baksmali
-LOCAL_REQUIRED_MODULES := baksmalilib
-include $(BUILD_PREBUILT)
diff --git a/deodexerant/Android.bp b/deodexerant/Android.bp
new file mode 100644
index 0000000..48d6fe2
--- /dev/null
+++ b/deodexerant/Android.bp
@@ -0,0 +1,44 @@
+// Copyright 2011, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//    * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//    * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+//    * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+cc_binary {
+    name: "deodexerant",
+
+    srcs: ["deodexerant.c"],
+
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-incompatible-pointer-types-discards-qualifiers",
+        "-Wno-main-return-type",
+        "-Wno-unused-parameter",
+    ],
+
+    ldflags: ["-Wl,--hash-style=sysv"],
+}
diff --git a/deodexerant/Android.mk b/deodexerant/Android.mk
deleted file mode 100644
index 34585fa..0000000
--- a/deodexerant/Android.mk
+++ /dev/null
@@ -1,50 +0,0 @@
-# Copyright 2011, Google Inc.
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-#    * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#    * Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the following disclaimer
-# in the documentation and/or other materials provided with the
-# distribution.
-#    * Neither the name of Google Inc. nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := deodexerant
-
-LOCAL_SRC_FILES:= deodexerant.c
-
-LOCAL_SHARED_LIBRARIES := libdl
-
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_CFLAGS := \
-    -Wall -Werror \
-    -Wno-incompatible-pointer-types-discards-qualifiers \
-    -Wno-main-return-type \
-    -Wno-unused-parameter \
-
-LOCAL_LDFLAGS := -Wl,--hash-style=sysv
-
-include $(BUILD_EXECUTABLE)
diff --git a/dexlib2/Android.bp b/dexlib2/Android.bp
new file mode 100644
index 0000000..e9fab20
--- /dev/null
+++ b/dexlib2/Android.bp
@@ -0,0 +1,32 @@
+// Copyright (C) 2014 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.
+
+// build dexlib2 jar
+// ============================================================
+
+java_library_host {
+    name: "dexlib2",
+
+    srcs: [
+        "src/main/java/**/*.java",
+    ],
+
+    static_libs: [
+        "commons-cli-1.2",
+        "guava",
+        "jcommander",
+        "jsr305",
+        "smali-util",
+    ],
+}
diff --git a/dexlib2/Android.mk b/dexlib2/Android.mk
deleted file mode 100644
index e55aa47..0000000
--- a/dexlib2/Android.mk
+++ /dev/null
@@ -1,40 +0,0 @@
-# Copyright (C) 2014 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.
-
-LOCAL_PATH := $(call my-dir)
-
-# build dexlib2 jar
-# ============================================================
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := dexlib2
-
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_MODULE_CLASS := JAVA_LIBRARIES
-LOCAL_IS_HOST_MODULE := true
-
-LOCAL_SRC_FILES := \
-	$(call all-java-files-under, src/main/java) \
-	$(call all-java-files-under, ../util/src/main/java)
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
-	commons-cli-1.2 \
-	guavalib \
-	jcommander-host \
-	jsr305lib
-
-
-include $(BUILD_HOST_JAVA_LIBRARY)
\ No newline at end of file
diff --git a/smali/Android.bp b/smali/Android.bp
new file mode 100644
index 0000000..4bbfa1b
--- /dev/null
+++ b/smali/Android.bp
@@ -0,0 +1,44 @@
+// 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.
+
+genrule {
+    name: "smali_version",
+    srcs: [":smali_build.gradle"],
+    out: ["smali.properties"],
+    cmd: "echo \"application.version=$$(grep -o -e \"^version = '\\(.*\\)'\" $(in) | grep -o -e \"[0-9.]\\+\")-aosp\" > $(out)",
+}
+
+// build smali jar
+// ============================================================
+
+java_binary_host {
+    name: "smali",
+
+    srcs: [
+        "src/main/java/**/*.java",
+    ],
+
+    manifest: "manifest.txt",
+
+    static_libs: [
+        "antlr-runtime",
+        "dexlib2",
+        "jcommander",
+        "smali-util",
+    ],
+
+    java_resources: [":smali_version"],
+
+    wrapper: ":smali_script",
+}
diff --git a/smali/Android.mk b/smali/Android.mk
deleted file mode 100644
index 1a8d71c..0000000
--- a/smali/Android.mk
+++ /dev/null
@@ -1,68 +0,0 @@
-# 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.
-
-LOCAL_PATH := $(call my-dir)
-
-# build smali jar
-# ============================================================
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := smalilib
-
-LOCAL_MODULE_TAGS := optional
-
-#LOCAL_MODULE_CLASS and LOCAL_IS_HOST_MODULE must be defined before calling $(local-intermediates-dir)
-LOCAL_MODULE_CLASS := JAVA_LIBRARIES
-LOCAL_IS_HOST_MODULE := true
-
-intermediates := $(call local-intermediates-dir,COMMON)
-
-GEN := $(addprefix $(intermediates)/, \
-			smaliParser.java \
-			smaliTreeWalker.java \
-        )
-
-LOCAL_SRC_FILES := \
-	$(call all-java-files-under, src/main/java) \
-	$(call all-java-files-under, ../util/src/main/java)
-
-LOCAL_JAR_MANIFEST := manifest.txt
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
-	antlr-runtime \
-	dexlib2 \
-	jcommander-host
-
-#create a new smali.properties file using the correct version
-$(intermediates)/resources/smali.properties: $(LOCAL_PATH)/../build.gradle
-	$(hide) mkdir -p $(dir $@)
-	$(hide) echo "application.version=$$(grep -o -e "^version = '\(.*\)'" $< | grep -o -e "[0-9.]\+")-aosp" >$@
-
-LOCAL_JAVA_RESOURCE_FILES := $(intermediates)/resources/smali.properties
-
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-
-
-# copy smali script
-# ============================================================
-
-include $(CLEAR_VARS)
-LOCAL_IS_HOST_MODULE := true
-LOCAL_MODULE_CLASS := EXECUTABLES
-LOCAL_MODULE := smali
-LOCAL_SRC_FILES := ../scripts/smali
-LOCAL_REQUIRED_MODULES := smalilib
-include $(BUILD_PREBUILT)
diff --git a/util/Android.bp b/util/Android.bp
new file mode 100644
index 0000000..dc945c2
--- /dev/null
+++ b/util/Android.bp
@@ -0,0 +1,23 @@
+// Copyright (C) 2017 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.
+
+java_library_host {
+    name: "smali-util",
+    srcs: ["src/main/java/**/*.java"],
+    libs: [
+        "guava",
+        "jcommander",
+        "jsr305",
+    ],
+}