Snap for 5735642 from 15e3835dd92bc86e673aefdaec34253636d7da19 to sdk-release

Change-Id: Ie6e8e3be1ddf51bd97efe3f3494b8a54bf39f50f
diff --git a/Android.bp b/Android.bp
index 6849ecd..a145da5 100644
--- a/Android.bp
+++ b/Android.bp
@@ -51,6 +51,20 @@
     ],
 }
 
+cc_binary {
+    name: "linkerconfig",
+    defaults: [ "linkerconfig_defaults" ],
+    local_include_dirs: [ "generator/include" ],
+    static_libs: [
+        "linkerconfig_modules",
+        "linkerconfig_contents",
+    ],
+    srcs: [
+        "generator/*.cc",
+    ],
+    static_executable: true,
+}
+
 cc_test {
     name: "linkerconfig_modules_unittest",
     defaults: [ "linkerconfig_defaults" ],
@@ -82,4 +96,4 @@
         "-Wunused",
     ],
     test_suites: ["general-tests"],
-}
\ No newline at end of file
+}
diff --git a/contents/namespace/rs.cc b/contents/namespace/rs.cc
index dcfd5b6..4280783 100644
--- a/contents/namespace/rs.cc
+++ b/contents/namespace/rs.cc
@@ -45,7 +45,7 @@
 
   ns.CreateLink("default").AddSharedLib({"@{LLNDK_LIBRARIES}",
                                          "@{SANITIZER_RUNTIME_LIBRARIES}",
-                                         "@{PRIVATE_LLNDK_LIBRARIES}"});
+                                         "@{PRIVATE_LLNDK_LIBRARIES:}"});
   ns.CreateLink("vndk").AddSharedLib("@{VNDK_SAMEPROCESS_LIBRARIES}");
 
   return ns;
diff --git a/contents/namespace/system.cc b/contents/namespace/system.cc
index c571054..786bbe2 100644
--- a/contents/namespace/system.cc
+++ b/contents/namespace/system.cc
@@ -25,9 +25,9 @@
   Namespace ns("system", /*is_isolated=*/false, /*is_visible=*/false);
   ns.AddSearchPath("/system/${LIB}", /*also_in_asan=*/true,
                    /*with_data_asan=*/true);
-  ns.AddSearchPath("/@{PRODUCT:product}/${LIB}", /*also_in_asan=*/true,
+  ns.AddSearchPath("/@{SYSTEM_EXT:system_ext}/${LIB}", /*also_in_asan=*/true,
                    /*with_data_asan=*/true);
-  ns.AddSearchPath("/@{PRODUCT_SERVICES}/${LIB}", /*also_in_asan=*/true,
+  ns.AddSearchPath("/@{PRODUCT:product}/${LIB}", /*also_in_asan=*/true,
                    /*with_data_asan=*/true);
 
   ns.CreateLink("runtime").AddSharedLib(
diff --git a/contents/namespace/systemdefault.cc b/contents/namespace/systemdefault.cc
index b3e5f39..8dfc18c 100644
--- a/contents/namespace/systemdefault.cc
+++ b/contents/namespace/systemdefault.cc
@@ -34,17 +34,16 @@
 
 const std::vector<std::string> kPermittedPaths = {
     "/system/${LIB}/drm", "/system/${LIB}/extractors", "/system/${LIB}/hw",
-    "/@{PRODUCT:product}/${LIB}", "/@{PRODUCT_SERVICES:product_services}/${LIB}",
+    "/@{SYSTEM_EXT:system_ext}/${LIB}", "/@{PRODUCT:product}/${LIB}",
     // These are where odex files are located. libart has to be able to
     // dlopen the files
-    "/system/framework", "/system/app", "/system/priv-app", "/vendor/framework",
-    "/vendor/app", "/vendor/priv-app", "/system/vendor/framework",
-    "/system/vendor/app", "/system/vendor/priv-app", "/odm/framework",
-    "/odm/app", "/odm/priv-app", "/oem/app", "/@{PRODUCT:product}/framework",
-    "/@{PRODUCT:product}/app", "/@{PRODUCT:product}/priv-app",
-    "/@{PRODUCT_SERVICES:product_services}/framework",
-    "/@{PRODUCT_SERVICES:product_services}/app",
-    "/@{PRODUCT_SERVICES:product_services}/priv-app", "/data", "/mnt/expand",
+    "/system/framework", "/system/app", "/system/priv-app",
+    "/@{SYSTEM_EXT:system_ext}/framework", "/@{SYSTEM_EXT:system_ext}/app",
+    "/@{SYSTEM_EXT:system_ext}/priv-app", "/vendor/framework", "/vendor/app",
+    "/vendor/priv-app", "/system/vendor/framework", "/system/vendor/app",
+    "/system/vendor/priv-app", "/odm/framework", "/odm/app", "/odm/priv-app",
+    "/oem/app", "/@{PRODUCT:product}/framework", "/@{PRODUCT:product}/app",
+    "/@{PRODUCT:product}/priv-app", "/data", "/mnt/expand",
     "/apex/com.android.runtime/${LIB}/bionic", "/system/${LIB}/bootstrap"};
 
 void BuildPermittedPath(Namespace& ns) {
@@ -64,6 +63,8 @@
 
   ns.AddSearchPath("/system/${LIB}", /*also_in_asan=*/true,
                    /*with_data_asan=*/true);
+  ns.AddSearchPath("/@{SYSTEM_EXT:system_ext}/${LIB}",
+                   /*also_in_asan=*/true, /*with_data_asan=*/true);
   ns.AddSearchPath("/@{PRODUCT:product}/${LIB}", /*also_in_asan=*/true,
                    /*with_data_asan=*/true);
   if (is_legacy) {
@@ -71,9 +72,6 @@
                      /*with_data_asan=*/true);
     ns.AddSearchPath("/odm/${LIB}", /*also_in_asan=*/true,
                      /*with_data_asan=*/true);
-  } else {
-    ns.AddSearchPath("/@{PRODUCT_SERVICES:product_services}/${LIB}",
-                     /*also_in_asan=*/true, /*with_data_asan=*/true);
   }
 
   if (!is_legacy) {
diff --git a/contents/namespace/vndkinsystem.cc b/contents/namespace/vndkinsystem.cc
index 05ab95b..bddf76b 100644
--- a/contents/namespace/vndkinsystem.cc
+++ b/contents/namespace/vndkinsystem.cc
@@ -16,6 +16,8 @@
 
 #include "linkerconfig/namespacebuilder.h"
 
+#include "linkerconfig/environment.h"
+
 using android::linkerconfig::modules::Namespace;
 
 namespace android {
@@ -27,12 +29,14 @@
 
   ns.AddSearchPath("/system/${LIB}", /*also_in_asan=*/true,
                    /*with_data_asan=*/true);
+  ns.AddSearchPath("/@{SYSTEM_EXT:system_ext}/${LIB}",
+                   /*also_in_asan=*/true, /*with_data_asan=*/true);
   ns.AddSearchPath("/@{PRODUCT:product}/${LIB}", /*also_in_asan=*/true,
                    /*with_data_asan=*/true);
-  ns.AddSearchPath("/@{PRODUCT_SERVICES:product_services}/${LIB}",
-                   /*also_in_asan=*/true, /*with_data_asan=*/true);
 
-  ns.AddWhitelisted("@{VNDK_USING_CORE_VARIANT_LIBRARIES}");
+  if (android::linkerconfig::modules::IsVndkInSystemNamespace()) {
+    ns.AddWhitelisted("@{VNDK_USING_CORE_VARIANT_LIBRARIES}");
+  }
 
   ns.CreateLink("system").AddSharedLib(
       {"@{LLNDK_LIBRARIES}", "@{SANITIZER_RUNTIME_LIBRARIES}"});
diff --git a/contents/section/vendor.cc b/contents/section/vendor.cc
index 64f2ca2..07ebf5b 100644
--- a/contents/section/vendor.cc
+++ b/contents/section/vendor.cc
@@ -50,9 +50,7 @@
   namespaces.emplace_back(BuildRuntimeNamespace(ctx));
   namespaces.emplace_back(BuildVndkNamespace(ctx));
   namespaces.emplace_back(BuildSystemNamespace(ctx));
-  if (android::linkerconfig::modules::IsVndkInSystemNamespace()) {
-    namespaces.emplace_back(BuildVndkInSystemNamespace(ctx));
-  }
+  namespaces.emplace_back(BuildVndkInSystemNamespace(ctx));
 
   return Section("vendor", kBinaryPath, std::move(namespaces));
 }
diff --git a/contents/tests/backward_compatibility/testbase.h b/contents/tests/backward_compatibility/testbase.h
index c21c01b..affbc30 100644
--- a/contents/tests/backward_compatibility/testbase.h
+++ b/contents/tests/backward_compatibility/testbase.h
@@ -20,8 +20,8 @@
 inline void MockVariables(std::string vndk_ver = "Q") {
   android::linkerconfig::modules::Variables::AddValue("VNDK_VER", vndk_ver);
   android::linkerconfig::modules::Variables::AddValue("PRODUCT", "product");
-  android::linkerconfig::modules::Variables::AddValue("PRODUCT_SERVICES",
-                                                      "product_services");
+  android::linkerconfig::modules::Variables::AddValue("SYSTEM_EXT",
+                                                      "system_ext");
   android::linkerconfig::modules::Variables::AddValue("LLNDK_LIBRARIES",
                                                       "llndk_libraries");
   android::linkerconfig::modules::Variables::AddValue(
diff --git a/generator/include/linkerconfig/configs.h b/generator/include/linkerconfig/configs.h
new file mode 100644
index 0000000..4fb0b75
--- /dev/null
+++ b/generator/include/linkerconfig/configs.h
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#pragma once
+
+// TODO : Create this file in build time
+#include <map>
+#include <string>
+
+inline const std::map<std::string, std::string> kPredefinedConfigs = {
+    {"PRODUCT", "product"},
+    {"SYSTEM_EXT", "system_ext"},
+    {"LLNDK_LIBRARIES",
+     "libEGL.so:libGLESv1_CM.so:libGLESv2.so:libGLESv3.so:libRS.so:libandroid_"
+     "net.so:libc.so:libcgrouprc.so:libclang_rt.asan-aarch64-android.so:"
+     "libclang_rt.asan-arm-android.so:libclang_rt.hwasan-aarch64-android.so:"
+     "libdl.so:libft2.so:liblog.so:libm.so:libmediandk.so:libnativewindow.so:"
+     "libneuralnetworks.so:libsync.so:libvndksupport.so:libvulkan.so"},
+    {"SANITIZER_RUNTIME_LIBRARIES",
+     "libclang_rt.asan-aarch64-android.so:libclang_rt.hwasan-aarch64-android."
+     "so:libclang_rt.ubsan_standalone-aarch64-android.so:libclang_rt.tsan-"
+     "aarch64-android.so:libclang_rt.asan-arm-android.so:libclang_rt.hwasan-"
+     "arm-android.so:libclang_rt.ubsan_standalone-arm-android.so:libclang_rt."
+     "tsan-arm-android.so"},
+    {"PRIVATE_LLNDK_LIBRARIES", ""},
+    {"VNDK_SAMEPROCESS_LIBRARIES",
+     "android.hardware.graphics.common@1.0.so:android.hardware.graphics.common@"
+     "1.1.so:android.hardware.graphics.common@1.2.so:android.hardware.graphics."
+     "mapper@2.0.so:android.hardware.graphics.mapper@2.1.so:android.hardware."
+     "graphics.mapper@3.0.so:android.hardware.renderscript@1.0.so:android.hidl."
+     "memory.token@1.0.so:android.hidl.memory@1.0.so:android.hidl.memory@1.0-"
+     "impl.so:android.hidl.safe_union@1.0.so:libRSCpuRef.so:libRSDriver.so:"
+     "libRS_internal.so:libbacktrace.so:libbase.so:libbcinfo.so:"
+     "libbinderthreadstate.so:libblas.so:libc++.so:libcompiler_rt.so:libcutils."
+     "so:libhardware.so:libhidlbase.so:libhidlmemory.so:libhidltransport.so:"
+     "libhwbinder.so:libhwbinder_noltopgo.so:libion.so:libjsoncpp.so:liblzma."
+     "so:libprocessgroup.so:libunwindstack.so:libutils.so:libutilscallstack.so:"
+     "libz.so"},
+    {"VNDK_USING_CORE_VARIANT_LIBRARIES", ""},
+    {"VNDK_CORE_LIBRARIES",
+     "android.frameworks.cameraservice.common@2.0.so:android.frameworks."
+     "cameraservice.device@2.0.so:android.frameworks.cameraservice.service@2.0."
+     "so:android.frameworks.displayservice@1.0.so:android.frameworks."
+     "schedulerservice@1.0.so:android.frameworks.sensorservice@1.0.so:android."
+     "frameworks.stats@1.0.so:android.frameworks.vr.composer@1.0.so:android."
+     "hardware.atrace@1.0.so:android.hardware.audio.common@2.0.so:android."
+     "hardware.audio.common@4.0.so:android.hardware.audio.common@5.0.so:"
+     "android.hardware.audio.effect@2.0.so:android.hardware.audio.effect@4.0."
+     "so:android.hardware.audio.effect@5.0.so:android.hardware.audio@2.0.so:"
+     "android.hardware.audio@4.0.so:android.hardware.audio@5.0.so:android."
+     "hardware.authsecret@1.0.so:android.hardware.automotive.audiocontrol@1.0."
+     "so:android.hardware.automotive.evs@1.0.so:android.hardware.automotive."
+     "vehicle@2.0.so:android.hardware.biometrics.face@1.0.so:android.hardware."
+     "biometrics.fingerprint@2.1.so:android.hardware.bluetooth.a2dp@1.0.so:"
+     "android.hardware.bluetooth.audio@2.0.so:android.hardware.bluetooth@1.0."
+     "so:android.hardware.boot@1.0.so:android.hardware.broadcastradio@1.0.so:"
+     "android.hardware.broadcastradio@1.1.so:android.hardware.broadcastradio@2."
+     "0.so:android.hardware.camera.common@1.0.so:android.hardware.camera."
+     "device@1.0.so:android.hardware.camera.device@3.2.so:android.hardware."
+     "camera.device@3.3.so:android.hardware.camera.device@3.4.so:android."
+     "hardware.camera.device@3.5.so:android.hardware.camera.metadata@3.2.so:"
+     "android.hardware.camera.metadata@3.3.so:android.hardware.camera.metadata@"
+     "3.4.so:android.hardware.camera.provider@2.4.so:android.hardware.camera."
+     "provider@2.5.so:android.hardware.cas.native@1.0.so:android.hardware.cas@"
+     "1.0.so:android.hardware.cas@1.1.so:android.hardware.configstore-utils.so:"
+     "android.hardware.configstore@1.0.so:android.hardware.configstore@1.1.so:"
+     "android.hardware.confirmationui-support-lib.so:android.hardware."
+     "confirmationui@1.0.so:android.hardware.contexthub@1.0.so:android."
+     "hardware.drm@1.0.so:android.hardware.drm@1.1.so:android.hardware.drm@1.2."
+     "so:android.hardware.dumpstate@1.0.so:android.hardware.fastboot@1.0.so:"
+     "android.hardware.gatekeeper@1.0.so:android.hardware.gnss.measurement_"
+     "corrections@1.0.so:android.hardware.gnss.visibility_control@1.0.so:"
+     "android.hardware.gnss@1.0.so:android.hardware.gnss@1.1.so:android."
+     "hardware.gnss@2.0.so:android.hardware.graphics.allocator@2.0.so:android."
+     "hardware.graphics.allocator@3.0.so:android.hardware.graphics.bufferqueue@"
+     "1.0.so:android.hardware.graphics.bufferqueue@2.0.so:android.hardware."
+     "graphics.composer@2.1.so:android.hardware.graphics.composer@2.2.so:"
+     "android.hardware.graphics.composer@2.3.so:android.hardware.health."
+     "storage@1.0.so:android.hardware.health@1.0.so:android.hardware.health@2."
+     "0.so:android.hardware.input.classifier@1.0.so:android.hardware.input."
+     "common@1.0.so:android.hardware.ir@1.0.so:android.hardware.keymaster@3.0."
+     "so:android.hardware.keymaster@4.0.so:android.hardware.light@2.0.so:"
+     "android.hardware.media.bufferpool@1.0.so:android.hardware.media."
+     "bufferpool@2.0.so:android.hardware.media.c2@1.0.so:android.hardware."
+     "media.omx@1.0.so:android.hardware.media@1.0.so:android.hardware.memtrack@"
+     "1.0.so:android.hardware.neuralnetworks@1.0.so:android.hardware."
+     "neuralnetworks@1.1.so:android.hardware.neuralnetworks@1.2.so:android."
+     "hardware.nfc@1.0.so:android.hardware.nfc@1.1.so:android.hardware.nfc@1.2."
+     "so:android.hardware.oemlock@1.0.so:android.hardware.power.stats@1.0.so:"
+     "android.hardware.power@1.0.so:android.hardware.power@1.1.so:android."
+     "hardware.power@1.2.so:android.hardware.power@1.3.so:android.hardware."
+     "radio.config@1.0.so:android.hardware.radio.config@1.1.so:android."
+     "hardware.radio.config@1.2.so:android.hardware.radio.deprecated@1.0.so:"
+     "android.hardware.radio@1.0.so:android.hardware.radio@1.1.so:android."
+     "hardware.radio@1.2.so:android.hardware.radio@1.3.so:android.hardware."
+     "radio@1.4.so:android.hardware.secure_element@1.0.so:android.hardware."
+     "secure_element@1.1.so:android.hardware.sensors@1.0.so:android.hardware."
+     "sensors@2.0.so:android.hardware.soundtrigger@2.0.so:android.hardware."
+     "soundtrigger@2.0-core.so:android.hardware.soundtrigger@2.1.so:android."
+     "hardware.soundtrigger@2.2.so:android.hardware.tetheroffload.config@1.0."
+     "so:android.hardware.tetheroffload.control@1.0.so:android.hardware."
+     "thermal@1.0.so:android.hardware.thermal@1.1.so:android.hardware.thermal@"
+     "2.0.so:android.hardware.tv.cec@1.0.so:android.hardware.tv.cec@2.0.so:"
+     "android.hardware.tv.input@1.0.so:android.hardware.usb.gadget@1.0.so:"
+     "android.hardware.usb@1.0.so:android.hardware.usb@1.1.so:android.hardware."
+     "usb@1.2.so:android.hardware.vibrator@1.0.so:android.hardware.vibrator@1."
+     "1.so:android.hardware.vibrator@1.2.so:android.hardware.vibrator@1.3.so:"
+     "android.hardware.vr@1.0.so:android.hardware.weaver@1.0.so:android."
+     "hardware.wifi.hostapd@1.0.so:android.hardware.wifi.hostapd@1.1.so:"
+     "android.hardware.wifi.offload@1.0.so:android.hardware.wifi.supplicant@1."
+     "0.so:android.hardware.wifi.supplicant@1.1.so:android.hardware.wifi."
+     "supplicant@1.2.so:android.hardware.wifi@1.0.so:android.hardware.wifi@1.1."
+     "so:android.hardware.wifi@1.2.so:android.hardware.wifi@1.3.so:android."
+     "hidl.allocator@1.0.so:android.hidl.memory.block@1.0.so:android.hidl."
+     "token@1.0.so:android.hidl.token@1.0-utils.so:android.system.net.netd@1.0."
+     "so:android.system.net.netd@1.1.so:android.system.suspend@1.0.so:android."
+     "system.wifi.keystore@1.0.so:libadf.so:libaudioroute.so:libaudioutils.so:"
+     "libbinder.so:libcamera_metadata.so:libcap.so:libclang_rt.scudo-aarch64-"
+     "android.so:libclang_rt.scudo-arm-android.so:libclang_rt.scudo_minimal-"
+     "aarch64-android.so:libclang_rt.scudo_minimal-arm-android.so:libclang_rt."
+     "ubsan_standalone-aarch64-android.so:libclang_rt.ubsan_standalone-arm-"
+     "android.so:libcn-cbor.so:libcodec2.so:libcrypto.so:libcrypto_utils.so:"
+     "libcurl.so:libdiskconfig.so:libdumpstateutil.so:libevent.so:libexif.so:"
+     "libexpat.so:libfmq.so:libgatekeeper.so:libgui.so:libhardware_legacy.so:"
+     "libhidlallocatorutils.so:libhidlcache.so:libjpeg.so:libkeymaster_"
+     "messages.so:libkeymaster_portable.so:libldacBT_abr.so:libldacBT_enc.so:"
+     "liblz4.so:libmedia_helper.so:libmedia_omx.so:libmemtrack.so:libminijail."
+     "so:libmkbootimg_abi_check.so:libnetutils.so:libnl.so:libopus.so:libpcre2."
+     "so:libpiex.so:libpng.so:libpower.so:libprocinfo.so:libprotobuf-cpp-full."
+     "so:libprotobuf-cpp-lite.so:libpuresoftkeymasterdevice.so:libradio_"
+     "metadata.so:libselinux.so:libsoftkeymasterdevice.so:libspeexresampler.so:"
+     "libsqlite.so:libssl.so:libstagefright_amrnb_common.so:libstagefright_"
+     "bufferpool@2.0.so:libstagefright_bufferqueue_helper.so:libstagefright_"
+     "enc_common.so:libstagefright_flacdec.so:libstagefright_foundation.so:"
+     "libstagefright_omx.so:libstagefright_omx_utils.so:libstagefright_"
+     "xmlparser.so:libsysutils.so:libtinyalsa.so:libtinyxml2.so:libui.so:"
+     "libusbhost.so:libvorbisidec.so:libwifi-system-iface.so:libxml2.so:libyuv."
+     "so:libziparchive.so"}};
\ No newline at end of file
diff --git a/generator/include/linkerconfig/variableloader.h b/generator/include/linkerconfig/variableloader.h
new file mode 100644
index 0000000..7ff248a
--- /dev/null
+++ b/generator/include/linkerconfig/variableloader.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#pragma once
+
+namespace android {
+namespace linkerconfig {
+namespace generator {
+
+void LoadVariable();
+
+}  // namespace generator
+}  // namespace linkerconfig
+}  // namespace android
diff --git a/generator/main.cc b/generator/main.cc
new file mode 100644
index 0000000..02ebc48
--- /dev/null
+++ b/generator/main.cc
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2019 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 <getopt.h>
+#include <cstring>
+#include <fstream>
+#include <iostream>
+#include <string>
+
+#include "linkerconfig/baseconfig.h"
+#include "linkerconfig/variableloader.h"
+
+namespace {
+const static struct option program_options[] = {
+    {"target", required_argument, 0, 't'},
+    {"help", no_argument, 0, 'h'},
+    {0, 0, 0, 0}};
+
+struct ProgramArgs {
+  std::string target_file;
+};
+
+[[noreturn]] void PrintUsage(int status = EXIT_SUCCESS) {
+  std::cerr << "Usage : linkerconfig [--target <target_file>] [--help]"
+            << std::endl;
+  exit(status);
+}
+
+bool ParseArgs(int argc, char* argv[], ProgramArgs* args) {
+  int parse_result;
+  while ((parse_result =
+              getopt_long(argc, argv, "th:", program_options, NULL)) != -1) {
+    switch (parse_result) {
+      case 't':
+        args->target_file = optarg;
+        break;
+      case 'h':
+        PrintUsage();
+      default:
+        return false;
+    }
+  }
+
+  if (optind < argc) {
+    return false;
+  }
+
+  return true;
+}
+
+android::linkerconfig::modules::Configuration GetConfiguration() {
+  // TODO : Use legacy if needed
+
+  // TODO : Use vndk lite if needed
+
+  // TODO : Use recovery if needed
+
+  // Use base configuration in default
+  return android::linkerconfig::contents::CreateBaseConfiguration();
+}
+}  // namespace
+
+int main(int argc, char* argv[]) {
+  ProgramArgs args;
+
+  if (!ParseArgs(argc, argv, &args)) {
+    PrintUsage(EXIT_FAILURE);
+  }
+
+  std::ostream* out = &std::cout;
+  std::ofstream file_out;
+
+  if (args.target_file != "") {
+    file_out.open(args.target_file);
+    if (file_out.fail()) {
+      std::cerr << "Failed to open file " << args.target_file << " : "
+                << std::strerror(errno) << std::endl;
+      return EXIT_FAILURE;
+    }
+    out = &file_out;
+  }
+
+  android::linkerconfig::generator::LoadVariable();
+  auto config = GetConfiguration();
+  android::linkerconfig::modules::ConfigWriter config_writer;
+
+  config.WriteConfig(config_writer);
+  *out << config_writer.ToString();
+  if (!out->good()) {
+    std::cerr << "Failed to write content to " << args.target_file << " : "
+              << std::strerror(errno) << std::endl;
+    return EXIT_FAILURE;
+  }
+
+  return EXIT_SUCCESS;
+}
\ No newline at end of file
diff --git a/generator/variableloader.cc b/generator/variableloader.cc
new file mode 100644
index 0000000..5573e82
--- /dev/null
+++ b/generator/variableloader.cc
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2019 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 "linkerconfig/variableloader.h"
+
+#include "linkerconfig/configs.h"
+#include "linkerconfig/environment.h"
+#include "linkerconfig/variables.h"
+
+using android::linkerconfig::modules::GetVendorVndkVersion;
+using android::linkerconfig::modules::Variables;
+
+namespace {
+void LoadPredefined() {
+  Variables::Load(kPredefinedConfigs);
+}
+
+void LoadVndkVersion() {
+  Variables::AddValue("VNDK_VER", GetVendorVndkVersion());
+}
+}  // namespace
+
+namespace android {
+namespace linkerconfig {
+namespace generator {
+void LoadVariable() {
+  LoadPredefined();
+  LoadVndkVersion();
+}
+}  // namespace generator
+}  // namespace linkerconfig
+}  // namespace android
\ No newline at end of file
diff --git a/modules/environment.cc b/modules/environment.cc
index 71ade6b..4f6a7ba 100644
--- a/modules/environment.cc
+++ b/modules/environment.cc
@@ -30,7 +30,7 @@
 
 bool IsVndkInSystemNamespace() {
   // TODO : Implement
-  return true;
+  return Variables::GetValue("VNDK_USING_CORE_VARIANT_LIBRARIES").has_value();
 }
 
 std::string GetVendorVndkVersion() {
diff --git a/modules/include/linkerconfig/variables.h b/modules/include/linkerconfig/variables.h
index 7c2c87f..d8ad3ee 100644
--- a/modules/include/linkerconfig/variables.h
+++ b/modules/include/linkerconfig/variables.h
@@ -27,6 +27,11 @@
   static std::optional<std::string> GetValue(const std::string& key);
   static void AddValue(const std::string& key, const std::string& value);
 
+  // Load multiple variables at a time
+  // This function will add multiple variables at a time. Any item with existing
+  // key will be ignored.
+  static void Load(std::map<std::string, std::string> predefined_variables);
+
  private:
   static std::map<std::string, std::string> variables_;
 };
diff --git a/modules/variables.cc b/modules/variables.cc
index fcc41ee..b195e82 100644
--- a/modules/variables.cc
+++ b/modules/variables.cc
@@ -46,6 +46,10 @@
 void Variables::AddValue(const std::string& key, const std::string& value) {
   variables_[key] = value;
 }
+
+void Variables::Load(std::map<std::string, std::string> predefined_variables) {
+  variables_.merge(predefined_variables);
+}
 }  // namespace modules
 }  // namespace linkerconfig
 }  // namespace android
\ No newline at end of file