Merge "Move all of init to libinit"
am: ad939afaf4

Change-Id: Ib2df5914dd2f24958d95f5b9dfe01577c8b796b0
diff --git a/init/Android.bp b/init/Android.bp
index 0db7824..6c80ee6 100644
--- a/init/Android.bp
+++ b/init/Android.bp
@@ -58,6 +58,34 @@
             cppflags: ["-DUSER_MODE_LINUX"],
         }
     },
+    static_libs: [
+        "libbootloader_message",
+        "libfs_mgr",
+        "libfec",
+        "libfec_rs",
+        "libhidl-gen-utils",
+        "libsquashfs_utils",
+        "liblogwrap",
+        "libext4_utils",
+        "libcutils",
+        "libbase",
+        "libc",
+        "libseccomp_policy",
+        "libselinux",
+        "liblog",
+        "libcrypto_utils",
+        "libcrypto",
+        "libc++_static",
+        "libdl",
+        "libsparse",
+        "libz",
+        "libprocessgroup",
+        "libavb",
+        "libkeyutils",
+        "libprotobuf-cpp-lite",
+        "libpropertyinfoserializer",
+        "libpropertyinfoparser",
+    ],
 }
 
 cc_library_static {
@@ -65,40 +93,38 @@
     defaults: ["init_defaults"],
     srcs: [
         "action.cpp",
+        "bootchart.cpp",
+        "builtins.cpp",
         "capabilities.cpp",
         "descriptors.cpp",
         "devices.cpp",
         "firmware_handler.cpp",
         "import_parser.cpp",
+        "init.cpp",
+        "init_first_stage.cpp",
+        "keychords.cpp",
         "log.cpp",
         "parser.cpp",
         "persistent_properties.cpp",
         "persistent_properties.proto",
         "property_service.cpp",
         "property_type.cpp",
+        "reboot.cpp",
         "security.cpp",
         "selinux.cpp",
         "service.cpp",
+        "sigchld_handler.cpp",
         "subcontext.cpp",
         "subcontext.proto",
         "rlimit_parser.cpp",
         "tokenizer.cpp",
         "uevent_listener.cpp",
+        "ueventd.cpp",
         "ueventd_parser.cpp",
         "util.cpp",
+        "watchdogd.cpp",
     ],
     whole_static_libs: ["libcap"],
-    static_libs: [
-        "libbase",
-        "libhidl-gen-utils",
-        "libselinux",
-        "liblog",
-        "libprocessgroup",
-        "libfs_mgr",
-        "libprotobuf-cpp-lite",
-        "libpropertyinfoserializer",
-        "libpropertyinfoparser",
-    ],
     include_dirs: [
         "system/core/mkbootimg",
     ],
@@ -125,42 +151,7 @@
         "make_f2fs",
     ],
     static_executable: true,
-    srcs: [
-        "bootchart.cpp",
-        "builtins.cpp",
-        "init.cpp",
-        "init_first_stage.cpp",
-        "keychords.cpp",
-        "reboot.cpp",
-        "sigchld_handler.cpp",
-        "ueventd.cpp",
-        "watchdogd.cpp",
-    ],
-    static_libs: [
-        "libinit",
-        "libbootloader_message",
-        "libfs_mgr",
-        "libfec",
-        "libfec_rs",
-        "libhidl-gen-utils",
-        "libsquashfs_utils",
-        "liblogwrap",
-        "libext4_utils",
-        "libcutils",
-        "libbase",
-        "libc",
-        "libselinux",
-        "liblog",
-        "libcrypto_utils",
-        "libcrypto",
-        "libc++_static",
-        "libdl",
-        "libsparse",
-        "libz",
-        "libprocessgroup",
-        "libavb",
-        "libkeyutils",
-    ],
+    srcs: ["main.cpp"],
     symlinks: [
         "sbin/ueventd",
         "sbin/watchdogd",
@@ -174,6 +165,7 @@
 cc_test {
     name: "init_tests",
     defaults: ["init_defaults"],
+    static_executable: true,
     srcs: [
         "devices_test.cpp",
         "init_test.cpp",
@@ -187,36 +179,17 @@
         "ueventd_test.cpp",
         "util_test.cpp",
     ],
-    shared_libs: [
-        "libbase",
-        "libcutils",
-    ],
-    static_libs: [
-        "libinit",
-        "libhidl-gen-utils",
-        "libselinux",
-        "libcrypto",
-        "libprotobuf-cpp-lite",
-        "libpropertyinfoparser",
-    ],
+    static_libs: ["libinit"],
 }
 
 cc_benchmark {
     name: "init_benchmarks",
+    static_executable: true,
     defaults: ["init_defaults"],
     srcs: [
         "subcontext_benchmark.cpp",
     ],
-    shared_libs: [
-        "libbase",
-        "libcutils",
-    ],
-    static_libs: [
-        "libinit",
-        "libselinux",
-        "libcrypto",
-        "libprotobuf-cpp-lite",
-    ],
+    static_libs: ["libinit"],
 }
 
 subdirs = ["*"]
diff --git a/init/Android.mk b/init/Android.mk
index 5239366..c4a6a50 100644
--- a/init/Android.mk
+++ b/init/Android.mk
@@ -41,16 +41,7 @@
 
 include $(CLEAR_VARS)
 LOCAL_CPPFLAGS := $(init_cflags)
-LOCAL_SRC_FILES:= \
-    bootchart.cpp \
-    builtins.cpp \
-    init.cpp \
-    init_first_stage.cpp \
-    keychords.cpp \
-    reboot.cpp \
-    sigchld_handler.cpp \
-    ueventd.cpp \
-    watchdogd.cpp \
+LOCAL_SRC_FILES := main.cpp
 
 LOCAL_MODULE:= init
 
diff --git a/init/init.cpp b/init/init.cpp
index 571da7c..95f272b 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -746,7 +746,3 @@
 
 }  // namespace init
 }  // namespace android
-
-int main(int argc, char** argv) {
-    android::init::main(argc, argv);
-}
diff --git a/init/init.h b/init/init.h
index b757c1d..ff7bdeb 100644
--- a/init/init.h
+++ b/init/init.h
@@ -47,6 +47,8 @@
 
 void ResetWaitForProp();
 
+int main(int argc, char** argv);
+
 }  // namespace init
 }  // namespace android
 
diff --git a/init/main.cpp b/init/main.cpp
new file mode 100644
index 0000000..9ed451b
--- /dev/null
+++ b/init/main.cpp
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+#include "init.h"
+
+int main(int argc, char** argv) {
+    android::init::main(argc, argv);
+}
diff --git a/init/subcontext.h b/init/subcontext.h
index 262440d..5601b80 100644
--- a/init/subcontext.h
+++ b/init/subcontext.h
@@ -25,6 +25,7 @@
 #include <android-base/unique_fd.h>
 
 #include "builtins.h"
+#include "result.h"
 #include "system/core/init/subcontext.pb.h"
 
 namespace android {