From 5c5e79cdf615ca3d26d59956eac2578805b2242f Mon Sep 17 00:00:00 2001
From: Jeff Vander Stoep <jeffv@google.com>
Date: Fri, 22 Sep 2017 14:36:02 -0700
Subject: [PATCH] Move python scripts to python_binary_host build rule

Fixes: 65263013
Test: build
Change-Id: I0ec412481c5990927fcbee7c4303bee2da876210
---
 Android.mk       | 10 ++++----
 tests/Android.bp | 63 ++++++++++++++++++++++++++++++------------------
 2 files changed, 44 insertions(+), 29 deletions(-)

diff --git a/Android.mk b/Android.mk
index 6a61d8680..196909737 100644
--- a/Android.mk
+++ b/Android.mk
@@ -223,7 +223,7 @@ LOCAL_REQUIRED_MODULES += \
     plat_seapp_contexts \
     plat_service_contexts \
     plat_hwservice_contexts \
-    searchpolicy.py \
+    searchpolicy \
     vndservice_contexts \
 
 ifneq ($(PRODUCT_FULL_TREBLE),true)
@@ -1183,10 +1183,10 @@ sepolicy_tests := $(intermediates)/sepolicy_tests
 $(sepolicy_tests): PRIVATE_PLAT_FC := $(built_plat_fc)
 $(sepolicy_tests): PRIVATE_NONPLAT_FC := $(built_nonplat_fc)
 $(sepolicy_tests): PRIVATE_SEPOLICY := $(built_sepolicy)
-$(sepolicy_tests): $(HOST_OUT_EXECUTABLES)/sepolicy_tests.py \
+$(sepolicy_tests): $(HOST_OUT_EXECUTABLES)/sepolicy_tests \
 $(built_plat_fc) $(built_nonplat_fc) $(built_sepolicy)
 	@mkdir -p $(dir $@)
-	$(hide) python $(HOST_OUT_EXECUTABLES)/sepolicy_tests.py -l $(HOST_OUT)/lib64 -f $(PRIVATE_PLAT_FC) -f $(PRIVATE_NONPLAT_FC) -p $(PRIVATE_SEPOLICY)
+	$(hide) python $(HOST_OUT_EXECUTABLES)/sepolicy_tests -l $(HOST_OUT)/lib64 -f $(PRIVATE_PLAT_FC) -f $(PRIVATE_NONPLAT_FC) -p $(PRIVATE_SEPOLICY)
 	$(hide) touch $@
 
 ##################################
@@ -1298,11 +1298,11 @@ $(treble_sepolicy_tests): PRIVATE_FAKE_TREBLE := --fake-treble
 else
 $(treble_sepolicy_tests): PRIVATE_FAKE_TREBLE :=
 endif
-$(treble_sepolicy_tests): $(HOST_OUT_EXECUTABLES)/treble_sepolicy_tests.py \
+$(treble_sepolicy_tests): $(HOST_OUT_EXECUTABLES)/treble_sepolicy_tests \
 $(built_plat_fc) $(built_nonplat_fc) $(built_sepolicy) $(built_plat_sepolicy) \
 $(built_26.0_plat_sepolicy) $(26.0_compat) $(26.0_mapping.combined.cil)
 	@mkdir -p $(dir $@)
-	$(hide) python $(HOST_OUT_EXECUTABLES)/treble_sepolicy_tests.py -l \
+	$(hide) python $(HOST_OUT_EXECUTABLES)/treble_sepolicy_tests -l \
 		$(HOST_OUT)/lib64 -f $(PRIVATE_PLAT_FC) -f $(PRIVATE_NONPLAT_FC) \
 		-b $(PRIVATE_PLAT_SEPOLICY) -m $(PRIVATE_COMBINED_MAPPING) \
 		-o $(PRIVATE_SEPOLICY_OLD) -p $(PRIVATE_SEPOLICY) \
diff --git a/tests/Android.bp b/tests/Android.bp
index 0c5e412dc..4a2b4f1f2 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -15,36 +15,51 @@ cc_library_host_shared {
     },
 }
 
-cc_prebuilt_binary {
-    name: "mini_parser.py",
-    srcs: ["mini_parser.py"],
-    host_supported: true,
+python_defaults {
+    name: "py2_only",
+    version: {
+        py2: {
+            enabled: true,
+        },
+        py3: {
+            enabled: false,
+        },
+    },
 }
 
-cc_prebuilt_binary {
-    name: "policy.py",
-    srcs: ["policy.py"],
-    host_supported: true,
-    required: ["libsepolwrap"],
+python_binary_host {
+    name: "mini_parser",
+    srcs: ["mini_parser.py"],
+    defaults: ["py2_only"],
 }
 
-cc_prebuilt_binary {
-    name: "treble_sepolicy_tests.py",
-    srcs: ["treble_sepolicy_tests.py"],
-    host_supported: true,
-    required: ["mini_parser.py", "policy.py"],
+python_binary_host {
+    name: "treble_sepolicy_tests",
+    srcs: [
+        "treble_sepolicy_tests.py",
+        "mini_parser.py",
+        "policy.py",
+    ],
+    required: ["libsepolwrap"],
+    defaults: ["py2_only"],
 }
 
-cc_prebuilt_binary {
-    name: "sepolicy_tests.py",
-    srcs: ["sepolicy_tests.py"],
-    host_supported: true,
-    required: ["policy.py"],
+python_binary_host {
+    name: "sepolicy_tests",
+    srcs: [
+        "sepolicy_tests.py",
+        "policy.py",
+    ],
+    required: ["libsepolwrap"],
+    defaults: ["py2_only"],
 }
 
-cc_prebuilt_binary {
-    name: "searchpolicy.py",
-    srcs: ["searchpolicy.py"],
-    host_supported: true,
-    required: ["policy.py"],
+python_binary_host {
+    name: "searchpolicy",
+    srcs: [
+        "searchpolicy.py",
+        "policy.py",
+    ],
+    required: ["libsepolwrap"],
+    defaults: ["py2_only"],
 }
-- 
GitLab