-
Notifications
You must be signed in to change notification settings - Fork 1
RDKEMW-3106 : Ensure modules path works in all environments #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,30 +25,35 @@ | |
| #ifdef ENABLE_ESSOS | ||
| #include <EssosInstance.h> | ||
| #endif | ||
| #include <sys/stat.h> | ||
| #include <cstdlib> | ||
|
|
||
| std::string JavaScriptContextBase::sThunderJSCode = ""; | ||
| std::string JavaScriptContextBase::sWebBridgeCode = ""; | ||
| std::string JavaScriptContextBase::sModulesPath = "" ; | ||
|
|
||
| JavaScriptContextFeatures::JavaScriptContextFeatures(bool embedThunderJS, bool embedWebBridge, bool enableWebSockerServer, ModuleSettings& moduleSettings):mEmbedThunderJS(embedThunderJS), mEmbedWebBridge(embedWebBridge), mEnableWebSockerServer(enableWebSockerServer), mModuleSettings(moduleSettings) | ||
| { | ||
| } | ||
|
|
||
| JavaScriptContextBase::JavaScriptContextBase(JavaScriptContextFeatures& features, std::string url, IJavaScriptEngine* jsEngine): mApplicationUrl(url), mEngine(jsEngine), mEmbedThunderJS(features.mEmbedThunderJS), mEmbedWebBridge(features.mEmbedWebBridge), mEnableWebSockerServer(features.mEnableWebSockerServer), mModuleSettings(features.mModuleSettings) | ||
| { | ||
| populateModulesPath(); | ||
| if (mEmbedThunderJS) | ||
| { | ||
| if (sThunderJSCode.empty()) | ||
| { | ||
| sThunderJSCode = readFile("modules/thunderJS.js"); | ||
| { | ||
| sThunderJSCode = readFile("thunderJS.js"); | ||
| } | ||
| } | ||
| if (mEmbedWebBridge) | ||
| { | ||
| if (sWebBridgeCode.empty()) | ||
| { | ||
| sWebBridgeCode = readFile("modules/webbridgesdk.js"); | ||
| { | ||
| sWebBridgeCode = readFile("webbridgesdk.js"); | ||
| } | ||
| } | ||
|
|
||
| #ifdef ENABLE_ESSOS | ||
| EssosInstance::instance()->registerKeyListener(this); | ||
| #endif | ||
|
|
@@ -75,9 +80,23 @@ void JavaScriptContextBase::registerCommonUtils() | |
|
|
||
| std::string JavaScriptContextBase::readFile(const char *file) | ||
| { | ||
| std::ifstream src_file(file); | ||
| bool isModules = true; | ||
| std::ifstream src_file; | ||
| std::stringstream src_script; | ||
| src_script << src_file.rdbuf(); | ||
| struct stat path; | ||
| if(stat(file, &path) == 0){ | ||
| isModules=false; | ||
| } | ||
| if(!isModules){ | ||
| src_file.open(file); | ||
| src_script << src_file.rdbuf(); | ||
| } | ||
| else{ | ||
| std::string fileName=sModulesPath; | ||
| fileName.append(file); | ||
| src_file.open(fileName); | ||
| src_script << src_file.rdbuf(); | ||
| } | ||
| return src_script.str(); | ||
| } | ||
|
|
||
|
|
@@ -86,24 +105,17 @@ bool JavaScriptContextBase::runFile(const char *file, const char* args, bool isA | |
| if (!file) | ||
| { | ||
| NativeJSLogger::log(WARN, "%s ... no script given.\n", __PRETTY_FUNCTION__); | ||
| fflush(stdout); | ||
| fflush(stdout); | ||
| return false; | ||
| } | ||
|
|
||
| std::string scriptToRun; | ||
| scriptToRun = readFile(file); | ||
| NativeJSLogger::log(INFO, "Checking in [%s]\n", file); | ||
| if(scriptToRun.empty()) | ||
| { | ||
| std::string fileName("/home/root/"); | ||
| fileName.append(file); | ||
| scriptToRun = readFile(fileName.c_str()); | ||
| NativeJSLogger::log(INFO, "Checking in [%s]\n", fileName.c_str()); | ||
| if(scriptToRun.empty()) | ||
| { | ||
| NativeJSLogger::log(ERROR, "%s ... load error / not found. %s\n", __PRETTY_FUNCTION__, file); | ||
| fflush(stdout); | ||
| fflush(stdout); | ||
| return false; | ||
| } | ||
| } | ||
| return evaluateScript(scriptToRun.c_str(), isApplication?file:nullptr, args, isApplication); | ||
| } | ||
|
|
@@ -127,3 +139,24 @@ void JavaScriptContextBase::onKeyRelease(struct JavaScriptKeyDetails& details) | |
| { | ||
| processKeyEvent(details, false); | ||
| } | ||
|
|
||
| void JavaScriptContextBase::populateModulesPath(){ | ||
| if(getenv("JSRUNTIME_MODULES_PATH")){ | ||
| std::cout<<"JSRUNTIME_MODULES_PATH variable is set"<<std::endl; | ||
| sModulesPath = std::string(getenv("JSRUNTIME_MODULES_PATH")); | ||
| return; | ||
| } | ||
| else{ | ||
| char* cwd = getcwd(nullptr,0); | ||
| std::string PWD=cwd; | ||
| if(PWD=="/package") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may need to remove this check and need to be done via JSruntimeLauncher by setting environment variable JSRUNTIME_MODULES_PATH=/runtime/modules |
||
| { | ||
| PWD = "/runtime"; | ||
| } | ||
| sModulesPath=PWD+"/modules/"; | ||
| setenv("JSRUNTIME_MODULES_PATH",sModulesPath.c_str(),1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have to remove setenv also |
||
| } | ||
| std::cout<<"Modules Path:"<<sModulesPath<<std::endl; | ||
| return; | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to isModule