Refactor zipalign to allow unit tests

Test: Self-tested
Bug: NA
Change-Id: I322b78c5e18082f7abf7427cdc62dbabcb18b4a0
diff --git a/tools/zipalign/Android.bp b/tools/zipalign/Android.bp
index 8e6196d..3eb660d 100644
--- a/tools/zipalign/Android.bp
+++ b/tools/zipalign/Android.bp
@@ -4,20 +4,31 @@
 // Zip alignment tool
 //
 
-cc_binary_host {
-    name: "zipalign",
+cc_defaults {
+    name: "zipalign_defaults",
+    target: {
+        windows: {
+            host_ldlibs: ["-lpthread"],
+            enabled: true,
+        },
+    },
+}
 
+cc_library_host_static {
+    name: "libzipalign",
     srcs: [
         "ZipAlign.cpp",
         "ZipEntry.cpp",
         "ZipFile.cpp",
     ],
-
+    export_include_dirs: [
+        "include",
+    ],
     cflags: ["-Wall", "-Werror"],
 
     // NOTE: Do not add any shared_libs dependencies because they will break the
     // static_sdk_tools target.
-    static_libs: [
+    whole_static_libs: [
         "libutils",
         "libcutils",
         "liblog",
@@ -26,11 +37,32 @@
         "libbase",
         "libzopfli",
     ],
+    defaults: ["zipalign_defaults"],
+}
 
-    target: {
-        windows: {
-            host_ldlibs: ["-lpthread"],
-            enabled: true,
-        },
-    },
+cc_binary_host {
+    name: "zipalign",
+    srcs: [
+        "ZipAlignMain.cpp",
+    ],
+    cflags: ["-Wall", "-Werror"],
+    static_libs: [
+        "libzipalign",
+    ],
+    defaults: ["zipalign_defaults"],
+}
+
+cc_test_host {
+    name: "zipalign_tests",
+    srcs: [
+        "tests/src/*_test.cpp",
+    ],
+    static_libs: [
+        "libzipalign",
+        "libgmock",
+    ],
+    data: [
+         "tests/data/unaligned.zip",
+    ],
+    defaults: ["zipalign_defaults"],
 }