Build resize2fs and mkefs with Bazel.

Test: CI
Bug: 204244290
Change-Id: I3751144032b5bb9bd1e08c3d86b6a68d7475124a
diff --git a/bazel.WORKSPACE b/bazel.WORKSPACE
index c8eb09e..4a3c022 100644
--- a/bazel.WORKSPACE
+++ b/bazel.WORKSPACE
@@ -23,10 +23,7 @@
         "deapexer",
         "debugfs",
         "merge_zips",
-        "mke2fs",
-        "resize2fs",
         "sefcontext_compile",
-        "signapk",
         "soong_zip",
         "zip2zip",
     ],
diff --git a/ci/bp2build.sh b/ci/bp2build.sh
index 2ccbf09..cc5f1f9 100755
--- a/ci/bp2build.sh
+++ b/ci/bp2build.sh
@@ -57,13 +57,19 @@
   //system/...
   //tools/apksig/...
   //tools/platform-compat/...
+
+  # These tools only build for host currently
+  -//external/e2fsprogs/misc:all
+  -//external/e2fsprogs/resize:all
+  -//external/e2fsprogs/debugfs:all
+  -//external/e2fsprogs/e2fsck:all
 )
 BUILD_TARGETS="${BUILD_TARGETS_LIST[@]}"
 # Iterate over various architectures supported in the platform build.
-tools/bazel --max_idle_secs=5 build ${FLAGS} --platforms //build/bazel/platforms:android_x86 -k ${BUILD_TARGETS}
-tools/bazel --max_idle_secs=5 build ${FLAGS} --platforms //build/bazel/platforms:android_x86_64 -k ${BUILD_TARGETS}
-tools/bazel --max_idle_secs=5 build ${FLAGS} --platforms //build/bazel/platforms:android_arm -k ${BUILD_TARGETS}
-tools/bazel --max_idle_secs=5 build ${FLAGS} --platforms //build/bazel/platforms:android_arm64 -k ${BUILD_TARGETS}
+tools/bazel --max_idle_secs=5 build ${FLAGS} --platforms //build/bazel/platforms:android_x86 -k -- ${BUILD_TARGETS}
+tools/bazel --max_idle_secs=5 build ${FLAGS} --platforms //build/bazel/platforms:android_x86_64 -k -- ${BUILD_TARGETS}
+tools/bazel --max_idle_secs=5 build ${FLAGS} --platforms //build/bazel/platforms:android_arm -k -- ${BUILD_TARGETS}
+tools/bazel --max_idle_secs=5 build ${FLAGS} --platforms //build/bazel/platforms:android_arm64 -k -- ${BUILD_TARGETS}
 
 HOST_INCOMPATIBLE_TARGETS=(
   # TODO(b/217756861): Apex toolchain is incompatible with host arches but apex modules do
diff --git a/rules/apex.bzl b/rules/apex.bzl
index 323b5c0..4dbd86c 100644
--- a/rules/apex.bzl
+++ b/rules/apex.bzl
@@ -173,6 +173,8 @@
     # the creation of an apex
     avbtool_files = apex_toolchain.avbtool[DefaultInfo].files_to_run
     e2fsdroid_files = apex_toolchain.e2fsdroid[DefaultInfo].files_to_run
+    mke2fs_files = apex_toolchain.mke2fs[DefaultInfo].files_to_run
+    resize2fs_files = apex_toolchain.resize2fs[DefaultInfo].files_to_run
     apexer_tool_paths = [
         # These are built by make_injection
         apex_toolchain.apexer.dirname,
@@ -180,6 +182,8 @@
         # These are real Bazel targets
         avbtool_files.executable.dirname,
         e2fsdroid_files.executable.dirname,
+        mke2fs_files.executable.dirname,
+        resize2fs_files.executable.dirname,
     ]
 
     args.add_all(["--apexer_tool_path", ":".join(apexer_tool_paths)])
@@ -200,11 +204,11 @@
     tools = [
         avbtool_files,
         e2fsdroid_files,
+        mke2fs_files,
+        resize2fs_files,
 
         apex_toolchain.apexer,
-        apex_toolchain.mke2fs,
         apex_toolchain.sefcontext_compile,
-        apex_toolchain.resize2fs,
         apex_toolchain.aapt2,
     ]
 
diff --git a/rules/apex/BUILD b/rules/apex/BUILD
index e220afd..b72cdbc 100644
--- a/rules/apex/BUILD
+++ b/rules/apex/BUILD
@@ -26,8 +26,8 @@
     aapt2 = "@make_injection//:host/linux-x86/bin/aapt2",
     avbtool = "//external/avb:avbtool",
     apexer = "@make_injection//:host/linux-x86/bin/apexer",
-    mke2fs = "@make_injection//:host/linux-x86/bin/mke2fs",
-    resize2fs = "@make_injection//:host/linux-x86/bin/resize2fs",
+    mke2fs = "//external/e2fsprogs/misc:mke2fs",
+    resize2fs = "//external/e2fsprogs/resize:resize2fs",
     e2fsdroid = "//external/e2fsprogs/contrib/android:e2fsdroid",
     sefcontext_compile = "@make_injection//:host/linux-x86/bin/sefcontext_compile",
     conv_apex_manifest = "@make_injection//:host/linux-x86/bin/conv_apex_manifest",
@@ -64,14 +64,14 @@
         "test.pem",
         "//external/avb:avbtool",
         "//external/e2fsprogs/contrib/android:e2fsdroid",
+        "//external/e2fsprogs/misc:mke2fs",
+        "//external/e2fsprogs/resize:resize2fs",
         "@make_injection//:host/linux-x86/bin/aapt2",
         "@make_injection//:host/linux-x86/bin/apex_compression_tool",
         "@make_injection//:host/linux-x86/bin/apexer",
         "@make_injection//:host/linux-x86/bin/conv_apex_manifest",
         "@make_injection//:host/linux-x86/bin/deapexer",
         "@make_injection//:host/linux-x86/bin/debugfs",
-        "@make_injection//:host/linux-x86/bin/mke2fs",
-        "@make_injection//:host/linux-x86/bin/resize2fs",
         "@make_injection//:host/linux-x86/bin/sefcontext_compile",
         "@make_injection//:host/linux-x86/bin/soong_zip",
         "//prebuilts/sdk/current:public/android.jar",
diff --git a/rules/apex/toolchain.bzl b/rules/apex/toolchain.bzl
index c56c66a..04c7f4d 100644
--- a/rules/apex/toolchain.bzl
+++ b/rules/apex/toolchain.bzl
@@ -37,8 +37,8 @@
             aapt2 = ctx.file.aapt2,
             avbtool = ctx.attr.avbtool,
             apexer = ctx.file.apexer,
-            mke2fs = ctx.file.mke2fs,
-            resize2fs = ctx.file.resize2fs,
+            mke2fs = ctx.attr.mke2fs,
+            resize2fs = ctx.attr.resize2fs,
             e2fsdroid = ctx.attr.e2fsdroid,
             sefcontext_compile = ctx.file.sefcontext_compile,
             conv_apex_manifest = ctx.file.conv_apex_manifest,
@@ -55,8 +55,8 @@
         "aapt2": attr.label(allow_single_file = True, cfg = "host", executable = True),
         "avbtool": attr.label(cfg = "host", executable = True),
         "apexer": attr.label(allow_single_file = True, cfg = "host", executable = True),
-        "mke2fs": attr.label(allow_single_file = True, cfg = "host", executable = True),
-        "resize2fs": attr.label(allow_single_file = True, cfg = "host", executable = True),
+        "mke2fs": attr.label(cfg = "host", executable = True),
+        "resize2fs": attr.label(cfg = "host", executable = True),
         "e2fsdroid": attr.label(cfg = "host", executable = True),
         "sefcontext_compile": attr.label(allow_single_file = True, cfg = "host", executable = True),
         "conv_apex_manifest": attr.label(allow_single_file = True, cfg = "host", executable = True),