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

Proposed by Marcus Tomlinson on 2015-07-22
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) 2015-07-22 Approve on 2015-07-22
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.
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
1=== modified file 'examples/simple/simple.ini'
2--- examples/simple/simple.ini 2015-07-09 06:40:58 +0000
3+++ examples/simple/simple.ini 2015-07-22 09:51:01 +0000
4@@ -1,5 +1,5 @@
5 [ScopeConfig]
6-ScopeRunner=/usr/bin/unity-js-scopes-launcher --scope %S
7+ScopeRunner=/usr/bin/unity-js-scopes-launcher %S %R
8 DisplayName = mock.DisplayName
9 Description = mock.Description
10 Author = test
11
12=== modified file 'src/bindings/src/scope.cc'
13--- src/bindings/src/scope.cc 2015-07-20 19:24:44 +0000
14+++ src/bindings/src/scope.cc 2015-07-22 09:51:01 +0000
15@@ -28,8 +28,27 @@
16
17 JavascriptScopeRuntime::JavascriptScopeRuntime(
18 const std::string& config_file)
19- : runtime_(unity::scopes::Runtime::create(config_file)),
20- scope_base_(new ScopeBase()) {
21+ : scope_base_(new ScopeBase()) {
22+ std::string current_runtime_config = config_file;
23+
24+ if (current_runtime_config.empty()) {
25+ char * env_runtime_config =
26+ std::getenv(kJavascriptUnityRuntimeEnvVarName);
27+
28+ if (env_runtime_config) {
29+ current_runtime_config = env_runtime_config;
30+
31+ if ( ! boost::ends_with(current_runtime_config, ".ini")) {
32+ throw std::runtime_error("Invalid runtime config (ini file)");
33+ }
34+
35+ if (!boost::filesystem::path(current_runtime_config).is_absolute()) {
36+ current_runtime_config = boost::filesystem::canonical(current_runtime_config).native();
37+ }
38+ }
39+ }
40+
41+ runtime_ = unity::scopes::Runtime::create(current_runtime_config);
42 }
43
44 JavascriptScopeRuntime::~JavascriptScopeRuntime() {
45
46=== modified file 'src/common/config.h'
47--- src/common/config.h 2015-07-20 19:07:45 +0000
48+++ src/common/config.h 2015-07-22 09:51:01 +0000
49@@ -21,6 +21,7 @@
50
51
52 const char kJavascriptUnityScopeIdEnvVarName[] = "JS_UNITY_SCOPE_ID_ENV_VAR_NAME";
53+const char kJavascriptUnityRuntimeEnvVarName[] = "JS_UNITY_RUNTIME_ENV_VAR_NAME";
54
55
56 #endif // _UNITY_JS_SCOPES_CONFIG_H_
57
58=== modified file 'src/launcher/config.h.in'
59--- src/launcher/config.h.in 2015-07-20 19:07:45 +0000
60+++ src/launcher/config.h.in 2015-07-22 09:51:01 +0000
61@@ -19,6 +19,8 @@
62 #ifndef __CONFIG_H__
63 #define __CONFIG_H__
64
65+#include <string>
66+
67 inline std::string executable_name() {
68 return "@LAUNCHER_EXECUTABLE_NAME@";
69 }
70
71=== modified file 'src/launcher/main.cc'
72--- src/launcher/main.cc 2015-07-20 19:07:45 +0000
73+++ src/launcher/main.cc 2015-07-22 09:51:01 +0000
74@@ -28,38 +28,26 @@
75
76 #include <boost/filesystem.hpp>
77
78-namespace {
79-
80-const char kScopeInitPathArgumentHeader[] = "--scope=";
81-
82-}
83-
84 void usage() {
85 std::cout << executable_name()
86 << " "
87- << kScopeInitPathArgumentHeader
88- << "<path-to-ini-file>"
89+ << "<path-to-scope-ini>"
90+ << "[<path-to-runtime-ini>]"
91 << std::endl;
92 }
93
94 int main(int argc, char *argv[]) {
95- if (argc < 2) {
96+ if (argc < 2 || argc > 3) {
97 usage();
98 return EXIT_FAILURE;
99 }
100
101- std::string ini_filename;
102- for (int i = 0; i < argc; ++i) {
103- std::string argument(argv[i]);
104- if (argument.substr(0, sizeof(kScopeInitPathArgumentHeader)-1)
105- == kScopeInitPathArgumentHeader) {
106- ini_filename = argument.substr(sizeof(kScopeInitPathArgumentHeader)-1);
107- }
108- }
109+ std::string ini_filename = argv[1];
110
111 if (ini_filename.empty()
112 || !boost::filesystem::exists(ini_filename)) {
113- std::cout << "Invalid or non existant scope ini file name";
114+ std::cout << "Invalid or non existant scope ini file name: "
115+ << ini_filename << std::endl;
116 usage();
117 return EXIT_FAILURE;
118 }
119@@ -67,8 +55,8 @@
120 boost::filesystem::path p(ini_filename);
121
122 if (p.extension().string() != ".ini") {
123- std::cout << "Invalid scope ini file name extension "
124- << ini_filename;
125+ std::cout << "Invalid scope ini file name extension: "
126+ << ini_filename << std::endl;
127 return EXIT_FAILURE;
128 }
129
130@@ -76,13 +64,38 @@
131 p.string().c_str(),
132 true);
133
134+ if (argc == 3) {
135+ std::string runtime_filename = argv[2];
136+
137+ if (runtime_filename.empty()
138+ || !boost::filesystem::exists(runtime_filename)) {
139+ std::cout << "Invalid or non existant runtime ini file name: "
140+ << runtime_filename << std::endl;
141+ usage();
142+ return EXIT_FAILURE;
143+ }
144+
145+ boost::filesystem::path p(runtime_filename);
146+
147+ if (p.extension().string() != ".ini") {
148+ std::cout << "Invalid runtime ini file name extension: "
149+ << runtime_filename << std::endl;
150+ return EXIT_FAILURE;
151+ }
152+
153+ setenv(kJavascriptUnityRuntimeEnvVarName,
154+ p.string().c_str(),
155+ true);
156+ }
157+
158 std::string base_name = p.filename().string();
159
160 boost::filesystem::path script_path = p.parent_path();
161 script_path += std::string("/") + p.stem().string() + ".js";
162
163 if (!boost::filesystem::exists(script_path)) {
164- std::cout << "Could not find scope javascript file";
165+ std::cout << "Could not find scope javascript file: "
166+ << script_path.string() << std::endl;
167 return EXIT_FAILURE;
168 }
169

Subscribers

People subscribed via source and target branches

to all changes: