From 4acf39405c71b9eb3248d13a9ee77ac8ce7d7807 Mon Sep 17 00:00:00 2001 From: SangYong Park Date: Tue, 27 Mar 2018 21:52:19 +0900 Subject: [PATCH] Cleanup build script and gyp files Minimize change of electron's code (Later patch will be fixed brightray's gyp files.) Change-Id: I2cae341abeddd812c0997d91b90e94ff36aab46e Signed-off-by: SangYong Park --- atom/app/atom_main_delegate.cc | 2 +- common.gypi | 27 --- efl/build/system.gyp | 4 +- electron.gyp | 141 ++----------- filenames.gypi | 23 -- packaging/electron-efl.manifest | 2 +- packaging/electron-efl.spec | 23 +- script/bootstrap.py | 21 +- script/build-libchromiumcontent.py | 2 +- script/build.py | 7 +- script/clean.py | 3 +- script/update.py | 9 +- tizen/common.gypi | 43 ++++ tizen/loader/wrt_loader.cc | 2 +- tizen/script/build | 1 - tizen/src/wrt_main.cc | 231 +++++++++++++++++++++ tizen/src/wrt_main.h | 10 + vendor/brightray/brightray.gyp | 4 +- vendor/brightray/brightray.gypi | 5 - vendor/brightray/script/bootstrap | 20 +- .../vendor/libchromiumcontent/script/build | 3 +- .../vendor/libchromiumcontent/script/create-dist | 3 +- .../vendor/libchromiumcontent/script/download | 15 +- .../vendor/libchromiumcontent/script/update | 12 +- .../tools/generate_filenames_gypi.py | 37 +--- wrt.gyp | 201 ++++++++++++++++++ 26 files changed, 565 insertions(+), 286 deletions(-) create mode 100644 tizen/common.gypi create mode 100644 tizen/src/wrt_main.cc create mode 100644 tizen/src/wrt_main.h create mode 100644 wrt.gyp diff --git a/atom/app/atom_main_delegate.cc b/atom/app/atom_main_delegate.cc index e102cc3..9f9ac69 100644 --- a/atom/app/atom_main_delegate.cc +++ b/atom/app/atom_main_delegate.cc @@ -114,7 +114,7 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) { void AtomMainDelegate::PreSandboxStartup() { brightray::MainDelegate::PreSandboxStartup(); - PathService::Override(base::FILE_EXE, base::FilePath("/usr/bin/electron")); + PathService::Override(base::FILE_EXE, base::FilePath("/usr/bin/wrt")); // Set google API key. std::unique_ptr env(base::Environment::Create()); diff --git a/common.gypi b/common.gypi index 125bcb1..9f0a6f0 100644 --- a/common.gypi +++ b/common.gypi @@ -1,7 +1,6 @@ { 'includes': [ 'vendor/brightray/brightray.gypi', - 'efl/features.gypi', ], 'conditions': [ ['use_efl!=1', { @@ -22,10 +21,6 @@ 'python': 'python', 'openssl_fips': '', 'openssl_no_asm': 1, - 'use_efl%': 0, - 'desktop_linux%': 0, - 'is_tizen%': 0, - 'tizen_product_tv%': 0, 'use_openssl_def': 0, 'OPENSSL_PRODUCT': 'libopenssl.a', 'node_release_urlbase': 'https://atom.io/download/atom-shell', @@ -141,7 +136,6 @@ }], ['_target_name=="node"', { 'include_dirs': [ - '/usr/include/v8', '<(libchromiumcontent_src_dir)', '<(libchromiumcontent_src_dir)/third_party/icu/source/common', '<(libchromiumcontent_src_dir)/third_party/icu/source/i18n', @@ -280,26 +274,5 @@ }, }, }], # OS=="mac" - ['is_tizen==1', { - 'target_defaults': { - 'defines': [ - 'OS_TIZEN', - ], - }, - }], # is_tizen==1 - ['tizen_product_tv==1', { - 'target_defaults': { - 'defines': [ - 'OS_TIZEN_TV_PRODUCT', - ], - }, - }], # tizen_product_tv==1 - ['use_efl==1', { - 'target_defaults': { - 'defines': [ - 'USE_EFL', - ], - }, - }], # is_tizen==1 ], } diff --git a/efl/build/system.gyp b/efl/build/system.gyp index 3e0f94f..32c429f 100644 --- a/efl/build/system.gyp +++ b/efl/build/system.gyp @@ -32,7 +32,7 @@ 'target_name': 'ecore-x', 'type': 'none', 'conditions': [ - ['desktop_linux==1', { + ['is_tizen!=1', { 'direct_dependent_settings': { 'cflags': [ ' - + diff --git a/packaging/electron-efl.spec b/packaging/electron-efl.spec index 67b8cef..f26da7c 100755 --- a/packaging/electron-efl.spec +++ b/packaging/electron-efl.spec @@ -70,8 +70,7 @@ cp %{SOURCE1001} . %define _xmldir %TZ_SYS_RO_PACKAGES %define _out out.tizen/out/D -export DEFINE_ARGS=" - desktop_linux=0 +DEFINE_ARGS=" libchromiumcontent_component=1 use_efl=1 is_tizen=1 @@ -84,14 +83,16 @@ DEFINE_ARGS+=" %if "%{?skipbootstrap}" != "1" ./script/bootstrap.py \ - --libcc_chromium_efl_path /usr/lib \ + --libcc_source_path ./vendor/brightray/vendor/libchromiumcontent/src \ + --libcc_shared_library_path /usr/lib \ + --libcc_static_library_path /usr/lib \ --define "${DEFINE_ARGS}" \ --dev \ --disable_clang \ -v %endif -./script/build.py -c D +./script/build.py -c D -t wrt %install install -d %{_out}/packaging @@ -116,18 +117,17 @@ install -d %{buildroot}/%{_icondir} install -d %{buildroot}/%{_libdir} install -d %{buildroot}/%{_bindir} install -m 0644 packaging/%{_pkgid}.png %{buildroot}/%{_icondir} -install -m 0755 %{_out}/libnode.so %{buildroot}/%{_libdir} +install -m 0755 %{_out}/lib/libnode.so %{buildroot}/%{_libdir} install -m 0755 %{_out}/wrt-loader %{buildroot}/%{_bindir} -install -m 0755 %{_out}/electron %{buildroot}/%{_bindir} +install -m 0755 %{_out}/wrt %{buildroot}/%{_bindir} + +ln -s %{_bindir}/wrt %{buildroot}%{_bindir}/wrt-client +ln -s %{_bindir}/wrt %{buildroot}%{_bindir}/xwalk_runtime # install resource. -mkdir -p %{buildroot}/opt/usr/home/owner/data/org.tizen.electron-efl/wrt_release +mkdir -p %{buildroot}/opt/usr/home/owner/data/org.tizen.electron-efl install -m 0755 %{_out}/resources/electron.asar %{buildroot}/opt/usr/home/owner/data/org.tizen.electron-efl -ln -s %{_bindir}/electron %{buildroot}%{_bindir}/wrt -ln -s %{_bindir}/electron %{buildroot}%{_bindir}/wrt-client -ln -s %{_bindir}/electron %{buildroot}%{_bindir}/xwalk_runtime - ./node_modules/asar/bin/asar p wrt %{_out}/resources/app.asar install -m 0755 %{_out}/resources/app.asar %{buildroot}/opt/usr/home/owner/data/org.tizen.electron-efl @@ -155,7 +155,6 @@ rm -fr %{buildroot} %{_icondir}/%{_pkgid}.png %{_libdir}/libnode.so %{_xmldir}/%{_pkgid}.xml -%attr(755,root,root) %{_bindir}/electron %attr(755,root,root) %{_bindir}/wrt %attr(755,root,root) %{_bindir}/wrt-client %attr(755,root,root) %{_bindir}/wrt-loader diff --git a/script/bootstrap.py b/script/bootstrap.py index ba7f31a..20de36b 100755 --- a/script/bootstrap.py +++ b/script/bootstrap.py @@ -31,7 +31,8 @@ def main(): if sys.platform == 'cygwin': update_win32_python() - if args.libcc_chromium_efl_path == None: + use_efl = 'use_efl=1' in [d.strip() for d in defines.split(' ')] + if not use_efl: update_submodules() libcc_source_path = args.libcc_source_path @@ -47,26 +48,26 @@ def main(): libcc_shared_library_path = os.path.join(dist_dir, 'shared_library') libcc_static_library_path = os.path.join(dist_dir, 'static_library') - if PLATFORM != 'win32' and args.libcc_chromium_efl_path == None: + if PLATFORM != 'win32': if not args.disable_clang and args.clang_dir == '': # Download prebuilt clang binaries. update_clang() - if os.path.isfile('/etc/tizen-release') != True: + if PLATFORM != 'tizen': setup_python_libs() - if args.libcc_chromium_efl_path == None: + if not use_efl: update_node_modules('.') bootstrap_brightray(args.dev, args.url, args.target_arch, libcc_source_path, libcc_shared_library_path, - libcc_static_library_path, args.libcc_chromium_efl_path) + libcc_static_library_path) - if PLATFORM == 'linux' and args.libcc_chromium_efl_path == None: + if PLATFORM == 'linux' and not use_efl: download_sysroot(args.target_arch) create_chrome_version_h() touch_config_gypi() run_update(defines, args.msvs) - if args.libcc_chromium_efl_path == None: + if not use_efl: update_electron_modules('spec', args.target_arch) @@ -106,8 +107,6 @@ def parse_args(): help='The static library path of libchromiumcontent.') parser.add_argument('--defines', default='', help='The build variables passed to gyp') - parser.add_argument('--libcc_chromium_efl_path', required=False, - help='The shared library path of chromium-efl.') return parser.parse_args() @@ -142,7 +141,7 @@ def setup_python_libs(): def bootstrap_brightray(is_dev, url, target_arch, libcc_source_path, libcc_shared_library_path, - libcc_static_library_path, libcc_chromium_efl_path): + libcc_static_library_path): bootstrap = os.path.join(VENDOR_DIR, 'brightray', 'script', 'bootstrap') args = [ '--commit', LIBCHROMIUMCONTENT_COMMIT, @@ -157,8 +156,6 @@ def bootstrap_brightray(is_dev, url, target_arch, libcc_source_path, args += ['--libcc_source_path', libcc_source_path, '--libcc_shared_library_path', libcc_shared_library_path, '--libcc_static_library_path', libcc_static_library_path] - if libcc_chromium_efl_path != None: - args += ['--libcc_chromium_efl_path', libcc_chromium_efl_path] execute_stdout([sys.executable, bootstrap] + args) diff --git a/script/build-libchromiumcontent.py b/script/build-libchromiumcontent.py index e04a3b6..e0a95f6 100755 --- a/script/build-libchromiumcontent.py +++ b/script/build-libchromiumcontent.py @@ -29,7 +29,7 @@ def main(): build = os.path.join(script_dir, 'build') create_dist = os.path.join(script_dir, 'create-dist') execute_stdout([sys.executable, bootstrap]) - execute_stdout([sys.executable, update, '-t', args.target_arch, '-N', + execute_stdout([sys.executable, update, '-t', args.target_arch, '--defines', args.defines]) execute_stdout([sys.executable, build, '-R', '-t', args.target_arch]) execute_stdout([sys.executable, create_dist, '-c', 'static_library', diff --git a/script/build.py b/script/build.py index b130211..80f266d 100755 --- a/script/build.py +++ b/script/build.py @@ -5,7 +5,7 @@ import os import subprocess import sys -from lib.config import get_target_arch +from lib.config import PLATFORM, get_target_arch from lib.util import electron_gyp, import_vs_env @@ -20,13 +20,14 @@ def main(): import_vs_env(get_target_arch()) ninja = os.path.join('vendor', 'depot_tools', 'ninja') - ninja = 'ninja' if sys.platform == 'win32': ninja += '.exe' + if PLATFORM == 'tizen': + ninja = 'ninja' args = parse_args() for config in args.configuration: - if os.path.isfile('/etc/tizen-release'): + if PLATFORM == 'tizen': build_path = os.path.join('out.tizen', 'out', config[0]) else: build_path = os.path.join('out', config[0]) diff --git a/script/clean.py b/script/clean.py index 703a2b4..aaa77ea 100755 --- a/script/clean.py +++ b/script/clean.py @@ -4,6 +4,7 @@ import argparse import os import sys +from lib.config import PLATFORM from lib.util import rm_rf @@ -16,7 +17,7 @@ def main(): args = parse_args() remove_directory('dist') - if os.path.isfile('/etc/tizen-release'): + if PLATFORM == 'tizen': remove_directory('out.tizen') else: remove_directory('out') diff --git a/script/update.py b/script/update.py index e172c4c..5c9c957 100755 --- a/script/update.py +++ b/script/update.py @@ -41,7 +41,6 @@ def update_external_binaries(): def update_gyp(): - print 'update gyp !!!' # Since gyp doesn't support specify link_settings for each configuration, # we are not able to link to different libraries in "Debug" and "Release" # configurations. @@ -89,18 +88,18 @@ def run_gyp(target_arch, component): # Add the defines passed from command line. args = parse_args() - use_efl=0 for define in [d.strip() for d in args.defines.split(' ')]: if define: - if define == 'use_efl=1': - use_efl=1 defines += ['-D' + define] generator = 'ninja' if args.msvs: generator = 'msvs-ninja' - print "GYP defines ::: ", defines + if 'use_efl=1' in [d.strip() for d in args.defines.split(' ')]: + return subprocess.call([python, gyp, '-f', generator, '--depth', '.', + 'wrt.gyp', '-I' + os.path.join('tizen', 'common.gypi')] + defines, env=env) + return subprocess.call([python, gyp, '-f', generator, '--depth', '.', 'electron.gyp', '-Icommon.gypi'] + defines, env=env) diff --git a/tizen/common.gypi b/tizen/common.gypi new file mode 100644 index 0000000..b0c2055 --- /dev/null +++ b/tizen/common.gypi @@ -0,0 +1,43 @@ +{ + 'includes': [ + '../common.gypi', + '../efl/features.gypi', + ], + 'variables': { + 'clang%': 0, + 'use_efl%': 0, + 'is_tizen%': 0, + 'tizen_product_tv%': 0, + }, + 'conditions': [ + ['use_efl==1', { + 'target_defaults': { + 'defines': [ + 'USE_EFL', + ], + }, + 'variables': { + 'js_sources': [ + '<(DEPTH)/lib/browser/api/pwrt.js', + ], + }, + }], # use_efl==1 + ['is_tizen==1', { + 'target_defaults': { + 'defines': [ + 'OS_TIZEN', + ], + }, + 'variables': { + 'libchromiumcontent_libraries': '/usr/lib/libchromium-ewk.so', + }, + }], # is_tizen==1 + ['tizen_product_tv==1', { + 'target_defaults': { + 'defines': [ + 'OS_TIZEN_TV_PRODUCT', + ], + }, + }], # tizen_product_tv==1 + ], +} diff --git a/tizen/loader/wrt_loader.cc b/tizen/loader/wrt_loader.cc index bb91449..1e756e0 100644 --- a/tizen/loader/wrt_loader.cc +++ b/tizen/loader/wrt_loader.cc @@ -20,7 +20,7 @@ // with "System::Privileged" label. int main(int argc, char* argv[]) { dlog_print(DLOG_INFO, "CHROMIUM", "Begin wrt-loader"); - void* handle = dlopen("/usr/bin/electron", RTLD_NOW); + void* handle = dlopen("/usr/bin/wrt", RTLD_NOW); if (!handle) { dlog_print(DLOG_ERROR, "CHROMIUM", "Failed to load electorn"); return false; diff --git a/tizen/script/build b/tizen/script/build index 5ef809c..22091bd 100755 --- a/tizen/script/build +++ b/tizen/script/build @@ -172,7 +172,6 @@ def run_bootstrap(chromium_path, verbose): defines = [ 'libchromiumcontent_component=1', - 'desktop_linux=1', 'use_efl=1' ] diff --git a/tizen/src/wrt_main.cc b/tizen/src/wrt_main.cc new file mode 100644 index 0000000..799621c --- /dev/null +++ b/tizen/src/wrt_main.cc @@ -0,0 +1,231 @@ +// 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 "wrt_main.h" + +#include + +#if defined(OS_WIN) +#include // windows.h must be included first + +#include +#include +#include + +#include "atom/app/atom_main_delegate.h" +#include "atom/common/crash_reporter/win/crash_service_main.h" +#include "base/environment.h" +#include "base/process/launch.h" +#include "base/win/windows_version.h" +#include "content/public/app/sandbox_helper_win.h" +#include "sandbox/win/src/sandbox_types.h" +#elif defined(OS_LINUX) // defined(OS_WIN) +#include "atom/app/atom_main_delegate.h" // NOLINT +#include "content/public/app/content_main.h" +#else // defined(OS_LINUX) +#include "atom/app/atom_library_main.h" +#endif // defined(OS_MACOSX) + +#if defined(USE_EFL) +#include "efl/init.h" +#endif + +#include "atom/app/node_main.h" +#include "atom/common/atom_command_line.h" +#include "base/at_exit.h" +#include "base/i18n/icu_util.h" + +#if defined(OS_TIZEN) +#include + +#include "atom/app/runtime.h" +#include "base/logging.h" +#include "tizen/common/application_data.h" +#include "tizen/common/command_line.h" +#include "tizen/loader/prelauncher.h" +#endif + +namespace { + +const char* kRunAsNode = "ELECTRON_RUN_AS_NODE"; + +// Default command line flags for all profiles and platforms +const char* kDefaultCommandLineFlags[] = { + "allow-file-access-from-files", + "enable-tizen-app-container", +}; + +bool IsEnvSet(const char* name) { +#if defined(OS_WIN) + size_t required_size; + getenv_s(&required_size, nullptr, 0, name); + return required_size != 0; +#else + char* indicator = getenv(name); + return indicator && indicator[0] != '\0'; +#endif +} + +} // namespace + +#if defined(OS_WIN) +int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) { + int argc = 0; + wchar_t** wargv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); + + bool run_as_node = IsEnvSet(kRunAsNode); + + // Make sure the output is printed to console. + if (run_as_node || !IsEnvSet("ELECTRON_NO_ATTACH_CONSOLE")) + base::RouteStdioToConsole(false); + + // Convert argv to to UTF8 + char** argv = new char*[argc]; + for (int i = 0; i < argc; i++) { + // Compute the size of the required buffer + DWORD size = WideCharToMultiByte(CP_UTF8, + 0, + wargv[i], + -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, + 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); + } + } + + if (run_as_node) { + // Now that argv conversion is done, we can finally start. + base::AtExitManager atexit_manager; + base::i18n::InitializeICU(); + return atom::NodeMain(argc, argv); + } else if (IsEnvSet("ELECTRON_INTERNAL_CRASH_SERVICE")) { + return crash_service::Main(cmd); + } + + sandbox::SandboxInterfaceInfo sandbox_info = {0}; + content::InitializeSandboxInfo(&sandbox_info); + atom::AtomMainDelegate delegate; + + content::ContentMainParams params(&delegate); + params.instance = instance; + params.sandbox_info = &sandbox_info; + atom::AtomCommandLine::Init(argc, argv); + atom::AtomCommandLine::InitW(argc, wargv); + return content::ContentMain(params); +} + +#elif defined(OS_LINUX) // defined(OS_WIN) + +#if defined(OS_TIZEN) +// For debug purpose only. +// TODO: To be removed later +bool hasTizenPackageID(int argc, const char* const* argv) { + if (argc > 3) { + if (0 == strncmp(argv[0], "/opt/usr/globalapps/", strlen("/opt/usr/globalapps/"))) { + return true; + } + } + return false; +} + +int real_main(int argc, char* argv[]) { +#else +int main(int argc, char* argv[]) { +#endif + if (IsEnvSet(kRunAsNode)) { + base::i18n::InitializeICU(); + base::AtExitManager atexit_manager; + return atom::NodeMain(argc, const_cast(argv)); + } + +#if defined(USE_EFL) + common::CommandLine::Init(argc, argv); + common::CommandLine* runtime_cmd = common::CommandLine::ForCurrentProcess(); + std::string appid = runtime_cmd->GetAppIdFromCommandLine("/usr/bin/wrt"); + + // load manifest + if (appid != "wrt") { // TODO: Any better way to distinguish? + auto appdata_manager = common::ApplicationDataManager::GetInstance(); + common::ApplicationData* appdata = appdata_manager->GetApplicationData(appid); + if (!appdata->LoadManifestData()) { + return false; + } + } + + if (efl::Initialize(argc, const_cast(argv))) + return 1; + + // Add params for EFL port + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + + static std::vector flags; + for (auto arg : kDefaultCommandLineFlags) + command_line->AppendSwitch(const_cast(arg)); + efl::AppendPortParams(*command_line); +#endif + + atom::AtomMainDelegate delegate; + content::ContentMainParams params(&delegate); + params.argc = argc; + params.argv = const_cast(argv); + atom::AtomCommandLine::Init(argc, argv); +#if defined(OS_TIZEN) + if (hasTizenPackageID(argc,argv)) { // TODO: Check to be removed later + elm_init(argc, argv); + std::unique_ptr runtime = runtime::Runtime::MakeRuntime(¶ms); + return runtime->Exec(); + } +#endif + return content::ContentMain(params); +} + +#if defined(OS_TIZEN) +__attribute__((visibility("default"))) +int main(int argc, const char* argv[]) { + if (strcmp(argv[0], "/usr/bin/wrt-loader") == 0) { + LOG(INFO) << "run with wrt-loader"; + auto preload = [argv](void) { + }; + auto did_launch = [](const std::string& app_path) { + }; + auto prelaunch = runtime::PreLauncher::Prelaunch; + return prelaunch(argc, const_cast(argv), preload, did_launch, real_main); + } else { + LOG(INFO) << "run without wrt-loader"; + return real_main(argc, const_cast(argv)); + } +} +#endif + +#else // defined(OS_LINUX) + +int main(int argc, const char* argv[]) { + if (IsEnvSet(kRunAsNode)) { + return AtomInitializeICUandStartNode(argc, const_cast(argv)); + } + + return AtomMain(argc, argv); +} + +#endif // defined(OS_MACOSX) diff --git a/tizen/src/wrt_main.h b/tizen/src/wrt_main.h new file mode 100644 index 0000000..30663a4 --- /dev/null +++ b/tizen/src/wrt_main.h @@ -0,0 +1,10 @@ +// Copyright (c) 2013 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_H_ +#define ATOM_APP_ATOM_MAIN_H_ + +#include "content/public/app/content_main.h" + +#endif // ATOM_APP_ATOM_MAIN_H_ diff --git a/vendor/brightray/brightray.gyp b/vendor/brightray/brightray.gyp index def490d..018a859 100644 --- a/vendor/brightray/brightray.gyp +++ b/vendor/brightray/brightray.gyp @@ -1,6 +1,6 @@ { 'conditions': [ - ['desktop_linux==0', { + ['is_tizen==1', { 'variables': { # The libraries brightray will be compiled to. 'linux_system_libraries': 'chromium-efl dbus-1 evas gmodule-2.0 nss icu-i18n icu-uc' @@ -72,8 +72,6 @@ 'link_settings': { 'libraries': [ '<@(libchromiumcontent_libraries)', - '<@(libchromiumcontent_shared_root_libraries)', -# '