From 5cfe9125531ca19c5a0d4da158181bf6c1243822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thi=C3=A9baud=20Weksteen?= Date: Tue, 19 Apr 2022 15:10:52 +1000 Subject: [PATCH] Reland refactoring of sources in Android.bp Move sources files to the default libselinux rule so that other binaries may reuse the same defaults (i.e., unittests). The majority of sources can be compiled for the host. Bug: 234313751 Test: local build for aosp_bramble-userdebug Test: TH Change-Id: I0b76bf79ceabd6096ab4ef03f0c8648d0636a310 --- libselinux/Android.bp | 181 +++++++++------------- libselinux/src/android/android_common.h | 7 - libselinux/src/android/android_platform.c | 6 +- 3 files changed, 78 insertions(+), 116 deletions(-) diff --git a/libselinux/Android.bp b/libselinux/Android.bp index 69ed5002..7d6a6e6a 100644 --- a/libselinux/Android.bp +++ b/libselinux/Android.bp @@ -45,6 +45,9 @@ common_CFLAGS = [ "-Wno-error=missing-noreturn", "-Wno-error=unused-function", "-Wno-error=unused-variable", + "-DUSE_PCRE2", + // 1003 corresponds to auditd, from system/core/logd/event.logtags + "-DAUDITD_LOG_TAG=1003", ] cc_defaults { @@ -53,15 +56,49 @@ cc_defaults { cflags: common_CFLAGS, srcs: [ + "src/android/android.c", + "src/avc.c", + "src/avc_internal.c", + "src/avc_sidtab.c", "src/booleans.c", "src/callbacks.c", + "src/canonicalize_context.c", + "src/checkAccess.c", + "src/check_context.c", + "src/compute_av.c", + "src/compute_create.c", + "src/compute_member.c", + "src/context.c", + "src/deny_unknown.c", + "src/disable.c", + "src/enabled.c", + "src/fgetfilecon.c", "src/freecon.c", - "src/label_backends_android.c", + "src/fsetfilecon.c", + "src/get_initial_context.c", + "src/getenforce.c", + "src/getfilecon.c", + "src/getpeercon.c", + "src/init.c", "src/label.c", + "src/label_backends_android.c", + "src/label_file.c", "src/label_support.c", + "src/lgetfilecon.c", + "src/load_policy.c", + "src/lsetfilecon.c", + "src/mapping.c", "src/matchpathcon.c", + "src/policyvers.c", + "src/procattr.c", + "src/regex.c", + "src/reject_unknown.c", + "src/sestatus.c", + "src/setenforce.c", + "src/setfilecon.c", "src/setrans_client.c", "src/sha1.c", + "src/stringrep.c", ], target: { @@ -70,60 +107,46 @@ cc_defaults { "-DBUILD_HOST", ], }, - android: { srcs: [ - "src/android/android.c", - "src/avc.c", - "src/avc_internal.c", - "src/avc_sidtab.c", - "src/canonicalize_context.c", - "src/checkAccess.c", - "src/check_context.c", - "src/compute_av.c", - "src/compute_create.c", - "src/compute_member.c", - "src/context.c", - "src/deny_unknown.c", - "src/disable.c", - "src/enabled.c", - "src/fgetfilecon.c", - "src/fsetfilecon.c", - "src/getenforce.c", - "src/getfilecon.c", - "src/get_initial_context.c", - "src/getpeercon.c", - "src/init.c", - "src/lgetfilecon.c", - "src/load_policy.c", - "src/lsetfilecon.c", - "src/mapping.c", - "src/policyvers.c", - "src/procattr.c", - "src/reject_unknown.c", - "src/sestatus.c", - "src/setenforce.c", - "src/setfilecon.c", - "src/stringrep.c", + "src/android/android_platform.c", ], + static: { + whole_static_libs: [ + "libpackagelistparser", + ], + }, - shared_libs: [ - "liblog", - ], + shared: { + shared_libs: [ + "libpackagelistparser", + ], + }, system_shared_libs: ["libc"], - - header_libs: ["libcutils_headers"], - - local_include_dirs: [ "src" ], - - // 1003 corresponds to auditd, from system/core/logd/event.logtags - cflags: [ - "-DAUDITD_LOG_TAG=1003", - ], - } + }, }, - local_include_dirs: ["include"], + static: { + whole_static_libs: [ + "libpcre2", + "liblog", + ], + }, + shared: { + shared_libs: [ + "libpcre2", + "liblog", + ], + }, + header_libs: [ + "libbase_headers", + "libcutils_headers", + "liblog_headers", + ], + local_include_dirs: [ + "include", + "src", + ], export_include_dirs: ["include"], stl: "none", @@ -140,76 +163,18 @@ cc_library { ramdisk_available: true, vendor_ramdisk_available: true, recovery_available: true, - host_supported: true, - cflags: ["-DUSE_PCRE2"], - - srcs: [ - "src/label_file.c", - "src/regex.c", - ], target: { - host_linux: { - srcs: [ - "src/avc.c", - "src/avc_internal.c", - "src/avc_sidtab.c", - "src/compute_av.c", - "src/compute_create.c", - "src/compute_member.c", - "src/context.c", - "src/deny_unknown.c", - "src/enabled.c", - "src/getenforce.c", - "src/getfilecon.c", - "src/get_initial_context.c", - "src/init.c", - "src/load_policy.c", - "src/mapping.c", - "src/procattr.c", - "src/reject_unknown.c", - "src/sestatus.c", - "src/setexecfilecon.c", - "src/stringrep.c", - ], - }, - linux_glibc: { - srcs: [ - "src/fgetfilecon.c", - "src/lgetfilecon.c", - "src/lsetfilecon.c", - "src/setfilecon.c", - ], - }, linux_bionic: { enabled: true, }, android: { - srcs: [ - "src/android/android_platform.c", - ], - - static: { - whole_static_libs: ["libpackagelistparser"], - }, - - shared: { - shared_libs: ["libpackagelistparser"], - }, - version_script: "exported.map.txt", }, }, - static: { - whole_static_libs: ["libpcre2"], - }, - shared: { - shared_libs: ["libpcre2"], - }, - stubs: { symbol_file: "exported.map.txt", versions: ["30"], @@ -219,14 +184,14 @@ cc_library { cc_binary_host { name: "sefcontext_compile", defaults: ["libselinux_defaults"], - cflags: ["-DUSE_PCRE2"], srcs: ["utils/sefcontext_compile.c"], static_libs: [ "libselinux", "libsepol", ], - whole_static_libs: ["libpcre2"], + + stl: "", } rust_bindgen { diff --git a/libselinux/src/android/android_common.h b/libselinux/src/android/android_common.h index db634945..f7a26c79 100644 --- a/libselinux/src/android/android_common.h +++ b/libselinux/src/android/android_common.h @@ -13,14 +13,10 @@ #include #include #include -#include #include #include #include #include -#ifndef __ANDROID_VNDK__ -#include -#endif #include #include "policy.h" #include "callbacks.h" @@ -32,9 +28,6 @@ #include #include -#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ -#include - #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #define FC_DIGEST_SIZE SHA_DIGEST_LENGTH diff --git a/libselinux/src/android/android_platform.c b/libselinux/src/android/android_platform.c index 25d5f2ba..342b4702 100644 --- a/libselinux/src/android/android_platform.c +++ b/libselinux/src/android/android_platform.c @@ -1,6 +1,10 @@ -#include "android_common.h" #include "android_internal.h" +#include #include +#include + +#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ +#include /* Locations for the file_contexts files. For each partition, only the first * existing entry will be used (for example, if