Merge lp:~marcustomlinson/unity-js-scopes/lp-1476521 into lp:unity-js-scopes

Proposed by Marcus Tomlinson
Status: Merged
Merged at revision: 15
Proposed branch: lp:~marcustomlinson/unity-js-scopes/lp-1476521
Merge into: lp:unity-js-scopes
Diff against target: 168 lines (+59/-24)
5 files modified
examples/simple/simple.ini (+1/-1)
src/bindings/src/scope.cc (+21/-2)
src/common/config.h (+1/-0)
src/launcher/config.h.in (+2/-0)
src/launcher/main.cc (+34/-21)
To merge this branch: bzr merge lp:~marcustomlinson/unity-js-scopes/lp-1476521
Reviewer Review Type Date Requested Status
Alexandre Abreu (community) Approve
Review via email: mp+265498@code.launchpad.net

Commit message

Store runtime config (via optional launcher paramter) in an env var use in constructing the runtime from scope.cc

To post a comment you must log in.
Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'examples/simple/simple.ini'
--- examples/simple/simple.ini 2015-07-09 06:40:58 +0000
+++ examples/simple/simple.ini 2015-07-22 09:51:01 +0000
@@ -1,5 +1,5 @@
1[ScopeConfig]1[ScopeConfig]
2ScopeRunner=/usr/bin/unity-js-scopes-launcher --scope %S2ScopeRunner=/usr/bin/unity-js-scopes-launcher %S %R
3DisplayName = mock.DisplayName3DisplayName = mock.DisplayName
4Description = mock.Description4Description = mock.Description
5Author = test5Author = test
66
=== modified file 'src/bindings/src/scope.cc'
--- src/bindings/src/scope.cc 2015-07-20 19:24:44 +0000
+++ src/bindings/src/scope.cc 2015-07-22 09:51:01 +0000
@@ -28,8 +28,27 @@
2828
29JavascriptScopeRuntime::JavascriptScopeRuntime(29JavascriptScopeRuntime::JavascriptScopeRuntime(
30 const std::string& config_file)30 const std::string& config_file)
31 : runtime_(unity::scopes::Runtime::create(config_file)),31 : scope_base_(new ScopeBase()) {
32 scope_base_(new ScopeBase()) {32 std::string current_runtime_config = config_file;
33
34 if (current_runtime_config.empty()) {
35 char * env_runtime_config =
36 std::getenv(kJavascriptUnityRuntimeEnvVarName);
37
38 if (env_runtime_config) {
39 current_runtime_config = env_runtime_config;
40
41 if ( ! boost::ends_with(current_runtime_config, ".ini")) {
42 throw std::runtime_error("Invalid runtime config (ini file)");
43 }
44
45 if (!boost::filesystem::path(current_runtime_config).is_absolute()) {
46 current_runtime_config = boost::filesystem::canonical(current_runtime_config).native();
47 }
48 }
49 }
50
51 runtime_ = unity::scopes::Runtime::create(current_runtime_config);
33}52}
3453
35JavascriptScopeRuntime::~JavascriptScopeRuntime() {54JavascriptScopeRuntime::~JavascriptScopeRuntime() {
3655
=== modified file 'src/common/config.h'
--- src/common/config.h 2015-07-20 19:07:45 +0000
+++ src/common/config.h 2015-07-22 09:51:01 +0000
@@ -21,6 +21,7 @@
2121
2222
23const char kJavascriptUnityScopeIdEnvVarName[] = "JS_UNITY_SCOPE_ID_ENV_VAR_NAME";23const char kJavascriptUnityScopeIdEnvVarName[] = "JS_UNITY_SCOPE_ID_ENV_VAR_NAME";
24const char kJavascriptUnityRuntimeEnvVarName[] = "JS_UNITY_RUNTIME_ENV_VAR_NAME";
2425
2526
26#endif // _UNITY_JS_SCOPES_CONFIG_H_27#endif // _UNITY_JS_SCOPES_CONFIG_H_
2728
=== modified file 'src/launcher/config.h.in'
--- src/launcher/config.h.in 2015-07-20 19:07:45 +0000
+++ src/launcher/config.h.in 2015-07-22 09:51:01 +0000
@@ -19,6 +19,8 @@
19#ifndef __CONFIG_H__19#ifndef __CONFIG_H__
20#define __CONFIG_H__20#define __CONFIG_H__
2121
22#include <string>
23
22inline std::string executable_name() {24inline std::string executable_name() {
23 return "@LAUNCHER_EXECUTABLE_NAME@";25 return "@LAUNCHER_EXECUTABLE_NAME@";
24}26}
2527
=== modified file 'src/launcher/main.cc'
--- src/launcher/main.cc 2015-07-20 19:07:45 +0000
+++ src/launcher/main.cc 2015-07-22 09:51:01 +0000
@@ -28,38 +28,26 @@
2828
29#include <boost/filesystem.hpp>29#include <boost/filesystem.hpp>
3030
31namespace {
32
33const char kScopeInitPathArgumentHeader[] = "--scope=";
34
35}
36
37void usage() {31void usage() {
38 std::cout << executable_name()32 std::cout << executable_name()
39 << " "33 << " "
40 << kScopeInitPathArgumentHeader34 << "<path-to-scope-ini>"
41 << "<path-to-ini-file>"35 << "[<path-to-runtime-ini>]"
42 << std::endl;36 << std::endl;
43}37}
4438
45int main(int argc, char *argv[]) {39int main(int argc, char *argv[]) {
46 if (argc < 2) {40 if (argc < 2 || argc > 3) {
47 usage();41 usage();
48 return EXIT_FAILURE;42 return EXIT_FAILURE;
49 }43 }
5044
51 std::string ini_filename;45 std::string ini_filename = argv[1];
52 for (int i = 0; i < argc; ++i) {
53 std::string argument(argv[i]);
54 if (argument.substr(0, sizeof(kScopeInitPathArgumentHeader)-1)
55 == kScopeInitPathArgumentHeader) {
56 ini_filename = argument.substr(sizeof(kScopeInitPathArgumentHeader)-1);
57 }
58 }
5946
60 if (ini_filename.empty()47 if (ini_filename.empty()
61 || !boost::filesystem::exists(ini_filename)) {48 || !boost::filesystem::exists(ini_filename)) {
62 std::cout << "Invalid or non existant scope ini file name";49 std::cout << "Invalid or non existant scope ini file name: "
50 << ini_filename << std::endl;
63 usage();51 usage();
64 return EXIT_FAILURE;52 return EXIT_FAILURE;
65 }53 }
@@ -67,8 +55,8 @@
67 boost::filesystem::path p(ini_filename);55 boost::filesystem::path p(ini_filename);
6856
69 if (p.extension().string() != ".ini") {57 if (p.extension().string() != ".ini") {
70 std::cout << "Invalid scope ini file name extension "58 std::cout << "Invalid scope ini file name extension: "
71 << ini_filename;59 << ini_filename << std::endl;
72 return EXIT_FAILURE;60 return EXIT_FAILURE;
73 }61 }
7462
@@ -76,13 +64,38 @@
76 p.string().c_str(),64 p.string().c_str(),
77 true);65 true);
7866
67 if (argc == 3) {
68 std::string runtime_filename = argv[2];
69
70 if (runtime_filename.empty()
71 || !boost::filesystem::exists(runtime_filename)) {
72 std::cout << "Invalid or non existant runtime ini file name: "
73 << runtime_filename << std::endl;
74 usage();
75 return EXIT_FAILURE;
76 }
77
78 boost::filesystem::path p(runtime_filename);
79
80 if (p.extension().string() != ".ini") {
81 std::cout << "Invalid runtime ini file name extension: "
82 << runtime_filename << std::endl;
83 return EXIT_FAILURE;
84 }
85
86 setenv(kJavascriptUnityRuntimeEnvVarName,
87 p.string().c_str(),
88 true);
89 }
90
79 std::string base_name = p.filename().string();91 std::string base_name = p.filename().string();
8092
81 boost::filesystem::path script_path = p.parent_path();93 boost::filesystem::path script_path = p.parent_path();
82 script_path += std::string("/") + p.stem().string() + ".js";94 script_path += std::string("/") + p.stem().string() + ".js";
8395
84 if (!boost::filesystem::exists(script_path)) {96 if (!boost::filesystem::exists(script_path)) {
85 std::cout << "Could not find scope javascript file";97 std::cout << "Could not find scope javascript file: "
98 << script_path.string() << std::endl;
86 return EXIT_FAILURE;99 return EXIT_FAILURE;
87 }100 }
88101

Subscribers

People subscribed via source and target branches

to all changes: