Merge pull request #1256 from deepak1556/process_arg_patch
implemetation of AtomCommandline to preserve args
This commit is contained in:
commit
27d2dbf375
12 changed files with 104 additions and 59 deletions
2
atom.gyp
2
atom.gyp
|
@ -62,6 +62,8 @@
|
||||||
'lib_sources': [
|
'lib_sources': [
|
||||||
'atom/app/atom_content_client.cc',
|
'atom/app/atom_content_client.cc',
|
||||||
'atom/app/atom_content_client.h',
|
'atom/app/atom_content_client.h',
|
||||||
|
'atom/app/atom_main_args.cc',
|
||||||
|
'atom/app/atom_main_args.h',
|
||||||
'atom/app/atom_main_delegate.cc',
|
'atom/app/atom_main_delegate.cc',
|
||||||
'atom/app/atom_main_delegate.h',
|
'atom/app/atom_main_delegate.h',
|
||||||
'atom/app/atom_main_delegate_mac.mm',
|
'atom/app/atom_main_delegate_mac.mm',
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "atom/app/atom_library_main.h"
|
#include "atom/app/atom_library_main.h"
|
||||||
|
|
||||||
|
#include "atom/app/atom_main_args.h"
|
||||||
#include "atom/app/atom_main_delegate.h"
|
#include "atom/app/atom_main_delegate.h"
|
||||||
#include "atom/app/node_main.h"
|
#include "atom/app/node_main.h"
|
||||||
#include "base/at_exit.h"
|
#include "base/at_exit.h"
|
||||||
|
@ -18,6 +19,7 @@ int AtomMain(int argc, const char* argv[]) {
|
||||||
content::ContentMainParams params(&delegate);
|
content::ContentMainParams params(&delegate);
|
||||||
params.argc = argc;
|
params.argc = argc;
|
||||||
params.argv = argv;
|
params.argv = argv;
|
||||||
|
atom::AtomCommandLine::Init(argc, argv);
|
||||||
return content::ContentMain(params);
|
return content::ContentMain(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#include "atom/app/atom_main.h"
|
#include "atom/app/atom_main.h"
|
||||||
|
#include "atom/app/atom_main_args.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -95,43 +96,44 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
|
||||||
freopen_s(&dontcare, "CON", "r", stdin);
|
freopen_s(&dontcare, "CON", "r", stdin);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string node_indicator, crash_service_indicator;
|
// Convert argv to to UTF8
|
||||||
if (env->GetVar("ATOM_SHELL_INTERNAL_RUN_AS_NODE", &node_indicator) &&
|
char** argv = new char*[argc];
|
||||||
node_indicator == "1") {
|
for (int i = 0; i < argc; i++) {
|
||||||
// Convert argv to to UTF8
|
// Compute the size of the required buffer
|
||||||
char** argv = new char*[argc];
|
DWORD size = WideCharToMultiByte(CP_UTF8,
|
||||||
for (int i = 0; i < argc; i++) {
|
0,
|
||||||
// Compute the size of the required buffer
|
wargv[i],
|
||||||
DWORD size = WideCharToMultiByte(CP_UTF8,
|
-1,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
if (size == 0) {
|
||||||
|
// This should never happen.
|
||||||
|
fprintf(stderr, "Could not convert arguments to utf8.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
// Do the actual conversion
|
||||||
|
argv[i] = new char[size];
|
||||||
|
DWORD result = WideCharToMultiByte(CP_UTF8,
|
||||||
0,
|
0,
|
||||||
wargv[i],
|
wargv[i],
|
||||||
-1,
|
-1,
|
||||||
NULL,
|
argv[i],
|
||||||
0,
|
size,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
if (size == 0) {
|
if (result == 0) {
|
||||||
// This should never happen.
|
// This should never happen.
|
||||||
fprintf(stderr, "Could not convert arguments to utf8.");
|
fprintf(stderr, "Could not convert arguments to utf8.");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
|
||||||
// Do the actual conversion
|
|
||||||
argv[i] = new char[size];
|
|
||||||
DWORD result = WideCharToMultiByte(CP_UTF8,
|
|
||||||
0,
|
|
||||||
wargv[i],
|
|
||||||
-1,
|
|
||||||
argv[i],
|
|
||||||
size,
|
|
||||||
NULL,
|
|
||||||
NULL);
|
|
||||||
if (result == 0) {
|
|
||||||
// This should never happen.
|
|
||||||
fprintf(stderr, "Could not convert arguments to utf8.");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Now that conversion is done, we can finally start.
|
}
|
||||||
|
|
||||||
|
std::string node_indicator, crash_service_indicator;
|
||||||
|
if (env->GetVar("ATOM_SHELL_INTERNAL_RUN_AS_NODE", &node_indicator) &&
|
||||||
|
node_indicator == "1") {
|
||||||
|
// Now that argv conversion is done, we can finally start.
|
||||||
base::i18n::InitializeICU();
|
base::i18n::InitializeICU();
|
||||||
return atom::NodeMain(argc, argv);
|
return atom::NodeMain(argc, argv);
|
||||||
} else if (env->GetVar("ATOM_SHELL_INTERNAL_CRASH_SERVICE",
|
} else if (env->GetVar("ATOM_SHELL_INTERNAL_CRASH_SERVICE",
|
||||||
|
@ -153,6 +155,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
|
||||||
content::ContentMainParams params(&delegate);
|
content::ContentMainParams params(&delegate);
|
||||||
params.instance = instance;
|
params.instance = instance;
|
||||||
params.sandbox_info = &sandbox_info;
|
params.sandbox_info = &sandbox_info;
|
||||||
|
atom::AtomCommandLine::Init(argc, argv);
|
||||||
return content::ContentMain(params);
|
return content::ContentMain(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,6 +172,7 @@ int main(int argc, const char* argv[]) {
|
||||||
content::ContentMainParams params(&delegate);
|
content::ContentMainParams params(&delegate);
|
||||||
params.argc = argc;
|
params.argc = argc;
|
||||||
params.argv = argv;
|
params.argv = argv;
|
||||||
|
atom::AtomCommandLine::Init(argc, argv);
|
||||||
return content::ContentMain(params);
|
return content::ContentMain(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
atom/app/atom_main_args.cc
Normal file
18
atom/app/atom_main_args.cc
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
// Copyright (c) 2013 GitHub, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#include "atom/app/atom_main_args.h"
|
||||||
|
|
||||||
|
namespace atom {
|
||||||
|
|
||||||
|
void AtomCommandLine::Init(int argc,
|
||||||
|
const char* const* argv) {
|
||||||
|
for (int i = 0; i < argc; ++i) {
|
||||||
|
argv_.push_back(argv[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> AtomCommandLine::argv_;
|
||||||
|
|
||||||
|
} // namespace atom
|
28
atom/app/atom_main_args.h
Normal file
28
atom/app/atom_main_args.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// Copyright (c) 2015 GitHub, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#ifndef ATOM_APP_ATOM_MAIN_ARGS_H_
|
||||||
|
#define ATOM_APP_ATOM_MAIN_ARGS_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "base/logging.h"
|
||||||
|
|
||||||
|
namespace atom {
|
||||||
|
|
||||||
|
class AtomCommandLine {
|
||||||
|
public:
|
||||||
|
static void Init(int argc, const char* const* argv);
|
||||||
|
static std::vector<std::string> argv() { return argv_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
static std::vector<std::string> argv_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(AtomCommandLine);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace atom
|
||||||
|
|
||||||
|
#endif // ATOM_APP_ATOM_MAIN_ARGS_H_
|
|
@ -7,13 +7,6 @@ util = require 'util'
|
||||||
# we need to restore it here.
|
# we need to restore it here.
|
||||||
process.argv.splice 1, 1
|
process.argv.splice 1, 1
|
||||||
|
|
||||||
# Pick out switches appended by atom-shell.
|
|
||||||
startMark = process.argv.indexOf '--atom-shell-switches-start'
|
|
||||||
endMark = process.argv.indexOf '--atom-shell-switches-end'
|
|
||||||
# And --force-device-scale-factor on Linux.
|
|
||||||
endMark++ if process.platform is 'linux'
|
|
||||||
process.argv.splice startMark, endMark - startMark + 1
|
|
||||||
|
|
||||||
# Add browser/api/lib to require's search paths,
|
# Add browser/api/lib to require's search paths,
|
||||||
# which contains javascript part of Atom's built-in libraries.
|
# which contains javascript part of Atom's built-in libraries.
|
||||||
globalPaths = module.globalPaths
|
globalPaths = module.globalPaths
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "atom/app/atom_main_args.h"
|
||||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||||
#include "base/command_line.h"
|
#include "base/command_line.h"
|
||||||
#include "base/base_paths.h"
|
#include "base/base_paths.h"
|
||||||
|
@ -97,22 +98,12 @@ void UvNoOp(uv_async_t* handle) {
|
||||||
scoped_ptr<const char*[]> StringVectorToArgArray(
|
scoped_ptr<const char*[]> StringVectorToArgArray(
|
||||||
const std::vector<std::string>& vector) {
|
const std::vector<std::string>& vector) {
|
||||||
scoped_ptr<const char*[]> array(new const char*[vector.size()]);
|
scoped_ptr<const char*[]> array(new const char*[vector.size()]);
|
||||||
for (size_t i = 0; i < vector.size(); ++i)
|
for (size_t i = 0; i < vector.size(); ++i) {
|
||||||
array[i] = vector[i].c_str();
|
array[i] = vector[i].c_str();
|
||||||
|
}
|
||||||
return array.Pass();
|
return array.Pass();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
|
||||||
std::vector<std::string> String16VectorToStringVector(
|
|
||||||
const std::vector<base::string16>& vector) {
|
|
||||||
std::vector<std::string> utf8_vector;
|
|
||||||
utf8_vector.reserve(vector.size());
|
|
||||||
for (size_t i = 0; i < vector.size(); ++i)
|
|
||||||
utf8_vector.push_back(base::UTF16ToUTF8(vector[i]));
|
|
||||||
return utf8_vector;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
base::FilePath GetResourcesPath(base::CommandLine* command_line,
|
base::FilePath GetResourcesPath(base::CommandLine* command_line,
|
||||||
bool is_browser) {
|
bool is_browser) {
|
||||||
base::FilePath exec_path(command_line->argv()[0]);
|
base::FilePath exec_path(command_line->argv()[0]);
|
||||||
|
@ -167,13 +158,8 @@ void NodeBindings::Initialize() {
|
||||||
|
|
||||||
node::Environment* NodeBindings::CreateEnvironment(
|
node::Environment* NodeBindings::CreateEnvironment(
|
||||||
v8::Handle<v8::Context> context) {
|
v8::Handle<v8::Context> context) {
|
||||||
|
auto args = AtomCommandLine::argv();
|
||||||
auto command_line = base::CommandLine::ForCurrentProcess();
|
auto command_line = base::CommandLine::ForCurrentProcess();
|
||||||
std::vector<std::string> args =
|
|
||||||
#if defined(OS_WIN)
|
|
||||||
String16VectorToStringVector(command_line->argv());
|
|
||||||
#else
|
|
||||||
command_line->argv();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Feed node the path to initialization script.
|
// Feed node the path to initialization script.
|
||||||
base::FilePath::StringType process_type = is_browser_ ?
|
base::FilePath::StringType process_type = is_browser_ ?
|
||||||
|
|
|
@ -5,7 +5,7 @@ remote = require 'remote'
|
||||||
|
|
||||||
BrowserWindow = remote.require 'browser-window'
|
BrowserWindow = remote.require 'browser-window'
|
||||||
|
|
||||||
isCI = remote.process.argv[1] == '--ci'
|
isCI = remote.process.argv[2] == '--ci'
|
||||||
|
|
||||||
describe 'browser-window module', ->
|
describe 'browser-window module', ->
|
||||||
fixtures = path.resolve __dirname, 'fixtures'
|
fixtures = path.resolve __dirname, 'fixtures'
|
||||||
|
|
4
spec/fixtures/module/process_args.js
vendored
Normal file
4
spec/fixtures/module/process_args.js
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
process.on('message', function() {
|
||||||
|
process.send(process.argv);
|
||||||
|
process.exit(0);
|
||||||
|
});
|
|
@ -17,6 +17,14 @@ describe 'node feature', ->
|
||||||
done()
|
done()
|
||||||
child.send 'message'
|
child.send 'message'
|
||||||
|
|
||||||
|
it 'preserves args', (done) ->
|
||||||
|
args = ['--expose_gc', '-test', '1']
|
||||||
|
child = child_process.fork path.join(fixtures, 'module', 'process_args.js'), args
|
||||||
|
child.on 'message', (msg) ->
|
||||||
|
assert.deepEqual args, msg.slice(2)
|
||||||
|
done()
|
||||||
|
child.send 'message'
|
||||||
|
|
||||||
it 'works in forked process', (done) ->
|
it 'works in forked process', (done) ->
|
||||||
child = child_process.fork path.join(fixtures, 'module', 'fork_ping.js')
|
child = child_process.fork path.join(fixtures, 'module', 'fork_ping.js')
|
||||||
child.on 'message', (msg) ->
|
child.on 'message', (msg) ->
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
// Check if we are running in CI.
|
// Check if we are running in CI.
|
||||||
var argv = require('remote').process.argv;
|
var argv = require('remote').process.argv;
|
||||||
var isCi = argv[1] == '--ci';
|
var isCi = argv[2] == '--ci';
|
||||||
|
|
||||||
if (!isCi) {
|
if (!isCi) {
|
||||||
var win = require('remote').getCurrentWindow();
|
var win = require('remote').getCurrentWindow();
|
||||||
|
|
|
@ -33,7 +33,7 @@ ipc.on('echo', function(event, msg) {
|
||||||
event.returnValue = msg;
|
event.returnValue = msg;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (process.argv[1] == '--ci') {
|
if (process.argv[2] == '--ci') {
|
||||||
process.removeAllListeners('uncaughtException');
|
process.removeAllListeners('uncaughtException');
|
||||||
process.on('uncaughtException', function(error) {
|
process.on('uncaughtException', function(error) {
|
||||||
console.error(error, error.stack);
|
console.error(error, error.stack);
|
||||||
|
|
Loading…
Reference in a new issue