Add new specific step to create symbolic link for WebApp 25/34525/6
authorBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Wed, 28 Jan 2015 15:38:13 +0000 (16:38 +0100)
committerBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Thu, 29 Jan 2015 10:00:45 +0000 (11:00 +0100)
Remove this operation from generate xml step, create a new one

Add a spec file option for set the WRT binary path used for symbolic link

Change-Id: Ife93a10b830fd093dc9c02184dd2490ce99d67a0
Signed-off-by: Baptiste DURAND <baptiste.durand@open.eurogiciel.org>
packaging/app-installers.spec
src/common/step/step_generate_xml.cc
src/wgt/CMakeLists.txt
src/wgt/step/step_symbolic_link.cc [new file with mode: 0644]
src/wgt/step/step_symbolic_link.h [new file with mode: 0644]
src/wgt/wgt_backend.cc

index 5320876..9eb8567 100644 (file)
@@ -49,7 +49,7 @@ Backend for standard widget files XPK
 cp %{SOURCE1001} .
 
 %build
-%cmake . -DCMAKE_BUILD_TYPE=%{?build_type:%build_type}
+%cmake . -DCMAKE_BUILD_TYPE=%{?build_type:%build_type} -DWRT_LAUNCHER=%{_bindir}/xwalk-launcher
 make %{?_smp_mflags}
 
 %install
index fbe4a42..8f00c2d 100644 (file)
 #define DBG(msg) std::cout << "[GenerateXML] " << msg << std::endl;
 #define ERR(msg) std::cout << "[ERROR: GenerateXML] " << msg << std::endl;
 
-namespace {
-
-const char kLauncher[] = "/usr/lib/xwalk/xwalk";
-
-}  // anonymous namespace
 
 namespace common_installer {
 namespace generate_xml {
@@ -96,18 +91,8 @@ Step::Status StepGenerateXml::process() {
 
     // binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
     fs::path exec_path = fs::path(context_->pkg_path()) / fs::path(ui->appid)
-        / fs::path("bin");
-    utils::CreateDir(exec_path);
+        / fs::path("bin") / fs::path(ui->appid);
 
-    exec_path /= fs::path(ui->appid);
-
-    fs::create_symlink(fs::path(kLauncher), exec_path, error);
-    if (error) {
-      ERR("Failed to set symbolic link "
-        << boost::system::system_error(error).what());
-        xmlFreeTextWriter(writer);
-      return Step::Status::ERROR;
-    }
     xmlTextWriterWriteAttribute(writer, BAD_CAST "exec",
         BAD_CAST exec_path.string().c_str());
     xmlTextWriterWriteAttribute(writer, BAD_CAST "type",
@@ -177,18 +162,7 @@ Step::Status StepGenerateXml::process() {
 
     // binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
     fs::path exec_path = fs::path(context_->pkg_path()) / fs::path(svc->appid)
-        / fs::path("bin");
-    utils::CreateDir(exec_path);
-
-    exec_path /= fs::path(svc->appid);
-
-    fs::create_symlink(fs::path(kLauncher), exec_path, error);
-    if (error) {
-      ERR("Failed to set symbolic link "
-        << boost::system::system_error(error).what());
-        xmlFreeTextWriter(writer);
-      return Step::Status::ERROR;
-    }
+        / fs::path("bin") / fs::path(svc->appid);
 
     xmlTextWriterWriteAttribute(writer, BAD_CAST "exec",
         BAD_CAST exec_path.string().c_str());
index 988c122..31a8ab0 100644 (file)
@@ -1,8 +1,17 @@
 # Target - sources
 SET(SRCS
   step/step_parse.cc
+  step/step_symbolic_link.cc
   wgt_backend.cc
 )
+
+IF(WRT_LAUNCHER)
+    ADD_DEFINITIONS("-DWRT_LAUNCHER=\"${WRT_LAUNCHER}\"")
+    MESSAGE( "WRT LAUNCHER binary path is  set to ${WRT_LAUNCHER}")
+ELSE(WRT_LAUNCHER)
+    MESSAGE(FATAL_ERROR, "WRT LAUNCHER binary path is not set")
+ENDIF(WRT_LAUNCHER)
+
 # Target - definition
 ADD_EXECUTABLE(${TARGET_WGT_BACKEND} ${SRCS})
 # Target - includes
diff --git a/src/wgt/step/step_symbolic_link.cc b/src/wgt/step/step_symbolic_link.cc
new file mode 100644 (file)
index 0000000..5ce2c31
--- /dev/null
@@ -0,0 +1,95 @@
+/* 2014, Copyright © Eurogiciel Coporation, APACHE-2.0, see LICENSE file */
+
+#include "wgt/step/step_symbolic_link.h"
+
+#include <pkgmgr-info.h>
+#include <unistd.h>
+
+#include <boost/filesystem.hpp>
+#include <cassert>
+#include <cstring>
+#include <iostream>
+#include <cstdio>
+#include <string>
+
+#include "common/utils.h"
+
+#define DBG(msg) std::cout << "[Symoblic Link] " << msg << std::endl;
+#define ERR(msg) std::cout << "[ERROR: Symoblic Link] " << msg << std::endl;
+
+namespace wgt {
+namespace symbolic_link {
+
+namespace fs = boost::filesystem;
+
+common_installer::Step::Status StepSymbolicLink::process() {
+  assert(context_->manifest_data());
+  boost::system::error_code error;
+  uiapplication_x* ui = context_->manifest_data()->uiapplication;
+  serviceapplication_x* svc = context_->manifest_data()->serviceapplication;
+  if ((!ui) && (!svc)) {
+    ERR("There is neither UI applications nor"
+        << "Services applications described!\n");
+    return Step::Status::ERROR;
+  }
+  // add ui-application element per ui application
+  for (; ui != nullptr; ui = ui->next) {
+    // binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
+    fs::path exec_path = fs::path(context_->pkg_path()) / fs::path(ui->appid)
+        / fs::path("bin");
+    utils::CreateDir(exec_path);
+
+    exec_path /= fs::path(ui->appid);
+
+    fs::create_symlink(fs::path(WRT_LAUNCHER), exec_path, error);
+    if (error) {
+      ERR("Failed to set symbolic link "
+        << boost::system::system_error(error).what());
+      return Step::Status::ERROR;
+    }
+  }
+  for (; svc != nullptr; svc = svc->next) {
+    // binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
+    fs::path exec_path = fs::path(context_->pkg_path()) / fs::path(svc->appid)
+        / fs::path("bin");
+    utils::CreateDir(exec_path);
+
+    exec_path /= fs::path(svc->appid);
+
+    fs::create_symlink(fs::path(WRT_LAUNCHER), exec_path, error);
+    if (error) {
+      ERR("Failed to set symbolic link "
+        << boost::system::system_error(error).what());
+      return Step::Status::ERROR;
+    }
+  }
+  DBG("Successfully parse tizen manifest xml");
+
+  return Status::OK;
+}
+
+common_installer::Step::Status StepSymbolicLink::clean() {
+  return Status::OK;
+}
+
+common_installer::Step::Status StepSymbolicLink::undo() {
+  uiapplication_x* ui = context_->manifest_data()->uiapplication;
+  serviceapplication_x* svc = context_->manifest_data()->serviceapplication;
+
+  for (; ui != nullptr; ui = ui->next) {
+    fs::path exec_path = fs::path(context_->pkg_path()) / fs::path(ui->appid)
+    / fs::path("bin");
+    if (fs::exists(exec_path))
+      fs::remove_all(exec_path);
+  }
+  for (; svc != nullptr; svc = svc->next) {
+    fs::path exec_path = fs::path(context_->pkg_path()) / fs::path(svc->appid)
+    / fs::path("bin");
+    if (fs::exists(exec_path))
+      fs::remove_all(exec_path);
+  }
+  return Status::OK;
+}
+
+}  // namespace symbolic_link
+}  // namespace wgt
diff --git a/src/wgt/step/step_symbolic_link.h b/src/wgt/step/step_symbolic_link.h
new file mode 100644 (file)
index 0000000..207dce5
--- /dev/null
@@ -0,0 +1,27 @@
+/* 2014, Copyright © Samsung, license APACHE-2.0, see LICENSE file */
+
+#ifndef WGT_STEP_STEP_SYMBOLIC_LINK_H_
+#define WGT_STEP_STEP_SYMBOLIC_LINK_H_
+
+#include <boost/filesystem.hpp>
+
+#include "common/app_installer.h"
+#include "common/context_installer.h"
+#include "common/step/step.h"
+
+namespace wgt {
+namespace symbolic_link {
+
+class StepSymbolicLink : public common_installer::Step {
+ public:
+  using Step::Step;
+
+  Status process() override;
+  Status clean() override;
+  Status undo() override;
+};
+
+}  // namespace symbolic_link
+}  // namespace wgt
+
+#endif  // WGT_STEP_STEP_SYMBOLIC_LINK_H_
index f840e7a..da7bc70 100644 (file)
@@ -25,6 +25,8 @@
 #include "common/step/step_unregister.h"
 #include "common/step/step_unzip.h"
 #include "wgt/step/step_parse.h"
+#include "wgt/step/step_symbolic_link.h"
+
 
 namespace ci = common_installer;
 
@@ -51,6 +53,7 @@ int main(int argc, char** argv) {
       installer.AddStep<wgt::parse::StepParse>();
       installer.AddStep<ci::signal::StepSignal>();
       installer.AddStep<ci::copy::StepCopy>();
+      installer.AddStep<wgt::symbolic_link::StepSymbolicLink>();
       installer.AddStep<ci::security::StepSecurity>();
       installer.AddStep<ci::generate_xml::StepGenerateXml>();
       installer.AddStep<ci::record::StepRecord>();