From 594488f8b0d62c1f93739b6aedd0d8b0eecd2c38 Mon Sep 17 00:00:00 2001
From: Tri Vo <trong@google.com>
Date: Mon, 7 May 2018 12:51:52 -0700
Subject: [PATCH] Build sepolicy tools with Android.bp.

Bug: 33691272
Test: make clean && mmma system/sepolicy
Change-Id: I6bbd6271c375338e7d24cd6089c6f826080c98b6
---
 Android.bp               |  4 ---
 tools/Android.bp         | 60 ++++++++++++++++++++++++++++++++++++++++
 tools/Android.mk         | 59 ---------------------------------------
 tools/fc_sort/Android.bp | 26 +++++++++++++++++
 tools/fc_sort/Android.mk | 13 ---------
 5 files changed, 86 insertions(+), 76 deletions(-)
 delete mode 100644 Android.bp
 create mode 100644 tools/Android.bp
 create mode 100644 tools/fc_sort/Android.bp
 delete mode 100644 tools/fc_sort/Android.mk

diff --git a/Android.bp b/Android.bp
deleted file mode 100644
index 17853420b..000000000
--- a/Android.bp
+++ /dev/null
@@ -1,4 +0,0 @@
-subdirs = [
-    "tests",
-    "build",
-]
diff --git a/tools/Android.bp b/tools/Android.bp
new file mode 100644
index 000000000..818430264
--- /dev/null
+++ b/tools/Android.bp
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+cc_defaults {
+    name: "sepolicy_tools_defaults",
+    cflags: [
+        "-Wall",
+        "-Werror",
+    ],
+    static_libs: ["libsepol"],
+    stl: "none",
+    tags: ["optional"],
+}
+
+cc_binary_host {
+    name: "checkseapp",
+    defaults: ["sepolicy_tools_defaults"],
+    srcs: ["check_seapp.c"],
+    whole_static_libs: ["libpcre2"],
+    cflags: ["-DLINK_SEPOL_STATIC"],
+}
+
+cc_binary_host {
+    name: "checkfc",
+    defaults: ["sepolicy_tools_defaults"],
+    srcs: ["checkfc.c"],
+    static_libs: ["libselinux"],
+}
+
+cc_binary_host {
+    name: "sepolicy-check",
+    defaults: ["sepolicy_tools_defaults"],
+    srcs: ["sepolicy-check.c"],
+}
+
+cc_binary_host {
+    name: "version_policy",
+    defaults: ["sepolicy_tools_defaults"],
+    srcs: ["version_policy.c"],
+}
+
+cc_prebuilt_binary {
+    name: "insertkeys.py",
+    srcs: ["insertkeys.py"],
+    tags: ["optional"],
+    host_supported: true,
+}
diff --git a/tools/Android.mk b/tools/Android.mk
index 1948b7ab7..34f43859f 100644
--- a/tools/Android.mk
+++ b/tools/Android.mk
@@ -1,62 +1,3 @@
 LOCAL_PATH:= $(call my-dir)
 
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := checkseapp
-LOCAL_MODULE_TAGS := optional
-LOCAL_CFLAGS := -DLINK_SEPOL_STATIC -Wall -Werror
-LOCAL_SRC_FILES := check_seapp.c
-LOCAL_STATIC_LIBRARIES := libsepol
-LOCAL_WHOLE_STATIC_LIBRARIES := libpcre2
-LOCAL_CXX_STL := none
-
-include $(BUILD_HOST_EXECUTABLE)
-
-###################################
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := checkfc
-LOCAL_MODULE_TAGS := optional
-LOCAL_CFLAGS := -Wall -Werror
-LOCAL_SRC_FILES := checkfc.c
-LOCAL_STATIC_LIBRARIES := libsepol libselinux
-LOCAL_CXX_STL := none
-
-include $(BUILD_HOST_EXECUTABLE)
-
-##################################
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := insertkeys.py
-LOCAL_SRC_FILES := insertkeys.py
-LOCAL_MODULE_CLASS := EXECUTABLES
-LOCAL_IS_HOST_MODULE := true
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_PREBUILT)
-###################################
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := sepolicy-check
-LOCAL_MODULE_TAGS := optional
-LOCAL_CFLAGS := -Wall -Werror
-LOCAL_SRC_FILES := sepolicy-check.c
-LOCAL_STATIC_LIBRARIES := libsepol
-LOCAL_CXX_STL := none
-
-include $(BUILD_HOST_EXECUTABLE)
-
-###################################
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := version_policy
-LOCAL_MODULE_TAGS := optional
-LOCAL_CFLAGS := -Wall -Werror
-LOCAL_SRC_FILES := version_policy.c
-LOCAL_SHARED_LIBRARIES := libsepol
-LOCAL_CXX_STL := none
-
-include $(BUILD_HOST_EXECUTABLE)
-
-
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tools/fc_sort/Android.bp b/tools/fc_sort/Android.bp
new file mode 100644
index 000000000..acecc9707
--- /dev/null
+++ b/tools/fc_sort/Android.bp
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+cc_binary_host {
+    name: "fc_sort",
+    srcs: ["fc_sort.c"],
+    stl: "none",
+    tags: ["optional"],
+    cflags: [
+        "-Wall",
+        "-Werror",
+    ],
+}
diff --git a/tools/fc_sort/Android.mk b/tools/fc_sort/Android.mk
deleted file mode 100644
index 6b4ed23ad..000000000
--- a/tools/fc_sort/Android.mk
+++ /dev/null
@@ -1,13 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := fc_sort
-LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := fc_sort.c
-LOCAL_CFLAGS := -Wall -Werror
-LOCAL_CXX_STL := none
-
-include $(BUILD_HOST_EXECUTABLE)
-
-###################################
-- 
GitLab