Remove Profile Build Dependency: Do it at runtime 65/97365/3
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Mon, 14 Nov 2016 04:27:47 +0000 (13:27 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Thu, 12 Jan 2017 08:00:55 +0000 (00:00 -0800)
- This is for Tizen 4.0.

  : Tizen 4.0 Configurability and Build Blocks require
  to remove all profile-depending build options in spec files.
  (No More profile macros)

- It is recommended to distinguish features/profiles at runtime.
 unless it incurs too much overhead, which requires you to
 create multiple binaries and subpackages.

Change-Id: I3e44fc7d258431cc9b3829fa16940d673acf9c96
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
CMakeLists.txt
packaging/wgt-manifest-handlers.spec
src/wgt_manifest_handlers/CMakeLists.txt
src/wgt_manifest_handlers/platform_version.cc
src/wgt_manifest_handlers/platform_version.h
src/wgt_manifest_handlers/setting_handler.cc

index dd773d7388b59d8af3bcf40c4481d1cb26155a23..16c632f155b29cc23c5cc1d147b4ea8c757dd3b8 100644 (file)
@@ -34,13 +34,6 @@ ADD_DEFINITIONS("-DPROJECT_TAG=\"wgt-manifest-handlers\"")
 
 ADD_DEFINITIONS("-DSHAREDIR=\"${SHAREDIR}\"")
 ADD_DEFINITIONS("-DTIZEN_VERSION=\"${TIZEN_VERSION}\"")
-IF(TIZEN_PROFILE STREQUAL "tv")
-  ADD_DEFINITIONS("-DTIZEN_TV")
-ELSEIF(TIZEN_PROFILE STREQUAL "mobile")
-  ADD_DEFINITIONS("-DTIZEN_MOBILE")
-ELSEIF(TIZEN_PROFILE STREQUAL "wearable")
-  ADD_DEFINITIONS("-DTIZEN_WEARABLE")
-ENDIF()
 
 SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
 INCLUDE(FindPkgConfig)
@@ -54,6 +47,7 @@ PKG_CHECK_MODULES(LIBIRI_DEPS REQUIRED libiri)
 PKG_CHECK_MODULES(XGDMIME_DEPS REQUIRED xdgmime)
 PKG_CHECK_MODULES(MANIFEST_PARSER_DEPS REQUIRED manifest-parser)
 PKG_CHECK_MODULES(MANIFEST_PARSER_UTILS_DEPS REQUIRED manifest-parser-utils)
+PKG_CHECK_MODULES(CAPI_SYSTEM_INFO REQUIRED capi-system-info)
 
 FIND_PACKAGE(GTest REQUIRED)
 FIND_PACKAGE(Boost REQUIRED COMPONENTS system filesystem)
index 37f433b35523f99f2f68c5d343ef6da33d1ad737..88909c56c858ac01c10b617504b4cff5625e23f6 100644 (file)
@@ -18,6 +18,7 @@ BuildRequires:  pkgconfig(libxml-2.0)
 BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(xdgmime)
 BuildRequires:  pkgconfig(manifest-parser)
+BuildRequires:  pkgconfig(capi-system-info)
 
 Requires: ca-certificates-tizen
 Requires: libtzplatform-config
@@ -54,8 +55,7 @@ export FFLAGS="$(echo $FFLAGS | sed 's/-Wl,--as-needed//g')"
 # is used in CMakeLists.txt files to distinguish, which project
 # is currently being build.
 %cmake . -DCMAKE_BUILD_TYPE=%{?build_type:%build_type} \
-         -DTIZEN_VERSION=%{tizen_version} \
-         -DTIZEN_PROFILE=%{profile}
+         -DTIZEN_VERSION=%{tizen_version}
 
 make %{?_smp_mflags}
 
index 4a9039e3d112ff0e42f94a02a4b7545efc309c85..d5fd3652edc06c9ddd686cd854c030d852f4164d 100644 (file)
@@ -34,6 +34,7 @@ APPLY_PKG_CONFIG(${TARGET_LIBNAME_WGT_MANIFEST_HANDLERS} PUBLIC
   XGDMIME_DEPS
   MANIFEST_PARSER_UTILS_DEPS
   Boost
+  CAPI_SYSTEM_INFO
 )
 
 # Extra
index cbdfc6646e2f586e5b47716d87a29590278be23d..a1266221f890aba084ed8663bdd7639ae71f1be3 100644 (file)
@@ -3,6 +3,8 @@
 // found in the LICENSE-xwalk file.
 
 #include "wgt_manifest_handlers/platform_version.h"
+#include <stdlib.h>
+#include <system_info.h>
 
 namespace parser {
 
@@ -11,13 +13,47 @@ utils::VersionNumber GetCurrentPlatformVersion() {
 }
 
 utils::VersionNumber GetMinimumPlatformVersion() {
-#ifdef TIZEN_TV
-  return utils::VersionNumber("2.3");
-#elif TIZEN_WEARABLE
-  return utils::VersionNumber("2.3");
-#else
-  return utils::VersionNumber("2.2.1");
-#endif
+
+  switch (GetProfile()) {
+    case TIZEN_PROFILE_TV:
+      return utils::VersionNumber("2.3");
+    case TIZEN_PROFILE_WEARABLE:
+      return utils::VersionNumber("2.3");
+    default:
+      return utils::VersionNumber("2.2.1");
+  }
+}
+
+tizen_profile_t GetProfile() {
+  static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
+  char *profileName;
+
+  if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
+    return profile;
+
+  system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
+  switch (*profileName) {
+    case 'm':
+    case 'M':
+      profile = TIZEN_PROFILE_MOBILE;
+      break;
+    case 'w':
+    case 'W':
+      profile = TIZEN_PROFILE_WEARABLE;
+      break;
+    case 't':
+    case 'T':
+      profile = TIZEN_PROFILE_TV;
+      break;
+    case 'i':
+    case 'I':
+      profile = TIZEN_PROFILE_IVI;
+      break;
+    default: // common or unknown ==> ALL ARE COMMON.
+      profile = TIZEN_PROFILE_COMMON;
+  }
+  free(profileName);
+  return profile;
 }
 
 }  // namespace parser
index c95c15c4e9fd425fe436b87ae338cca6e273c202..ec2b2085e89788a4ef77cd4c92b565a4af9ee803 100644 (file)
@@ -22,6 +22,21 @@ utils::VersionNumber GetCurrentPlatformVersion();
  */
 utils::VersionNumber GetMinimumPlatformVersion();
 
+typedef enum {
+       TIZEN_PROFILE_UNKNOWN = 0,
+       TIZEN_PROFILE_MOBILE = 0x1,
+       TIZEN_PROFILE_WEARABLE = 0x2,
+       TIZEN_PROFILE_TV = 0x4,
+       TIZEN_PROFILE_IVI = 0x8,
+       TIZEN_PROFILE_COMMON = 0x10,
+} tizen_profile_t;
+
+/**
+ * @brief GetProfile
+ * @return identify Tizen profile at runtime.
+ */
+tizen_profile_t GetProfile();
+
 }  // namespace parser
 
 #endif  // WGT_MANIFEST_HANDLERS_PLATFORM_VERSION_H_
index 74652435a2a0d0bb32d6fdfaeb95946e3844c16d..5abbdc5f914e45ff23c9531da1be9c4b6a31fbde 100644 (file)
@@ -15,6 +15,7 @@
 #include "manifest_parser/utils/version_number.h"
 #include "wgt_manifest_handlers/application_manifest_constants.h"
 #include "wgt_manifest_handlers/tizen_application_handler.h"
+#include "platform_version.h"
 
 namespace {
 
@@ -182,28 +183,28 @@ bool SettingHandler::Validate(
     std::string* error) const {
   const SettingInfo& setting_info = static_cast<const SettingInfo&>(data);
 
-#if defined(TIZEN_MOBILE) || defined(TIZEN_WEARABLE)
-  // backward compatibility
-  if (setting_info.orientation_defaulted()) {
-    const TizenApplicationInfo& app_info =
-      static_cast<const TizenApplicationInfo&>(
-        *handlers_output.find(TizenApplicationInfo::Key())->second);
-    utils::VersionNumber required_version(app_info.required_version());
-    if (!required_version.IsValid()) {
-      *error = "Cannot retrieve required API version from widget";
-      return false;
-    }
-    if (required_version < kDefaultAutoOrientationVersion) {
-      auto& constless_setting_info = const_cast<SettingInfo&>(setting_info);
-      constless_setting_info.set_screen_orientation(
-          SettingInfo::ScreenOrientation::PORTRAIT);
-      // keep claiming it is default
-      constless_setting_info.set_orientation_defaulted(true);
+  if (parser::GetProfile() & (parser::TIZEN_PROFILE_MOBILE | parser::TIZEN_PROFILE_WEARABLE)) {
+    // backward compatibility
+    if (setting_info.orientation_defaulted()) {
+      const TizenApplicationInfo& app_info =
+        static_cast<const TizenApplicationInfo&>(
+          *handlers_output.find(TizenApplicationInfo::Key())->second);
+      utils::VersionNumber required_version(app_info.required_version());
+      if (!required_version.IsValid()) {
+        *error = "Cannot retrieve required API version from widget";
+        return false;
+      }
+      if (required_version < kDefaultAutoOrientationVersion) {
+        auto& constless_setting_info = const_cast<SettingInfo&>(setting_info);
+        constless_setting_info.set_screen_orientation(
+            SettingInfo::ScreenOrientation::PORTRAIT);
+        // keep claiming it is default
+        constless_setting_info.set_orientation_defaulted(true);
+      }
     }
+  } else {
+    (void)handlers_output;
   }
-#else
-  (void)handlers_output;
-#endif
 
   if (setting_info.screen_orientation() !=
           SettingInfo::ScreenOrientation::AUTO &&