From 4dc38d39e98c5703a62790d1ba6ed4d4fb52fb81 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Mon, 17 Jun 2019 13:37:55 -0700 Subject: [PATCH] refactor: replace atom_version and friends with electron_version (#18847) --- BUILD.gn | 4 +-- atom/app/atom_library_main.mm | 2 +- atom/app/atom_main_delegate_mac.mm | 4 +-- atom/app/node_main.cc | 4 +-- atom/browser/api/atom_api_net_log.cc | 4 +-- .../api/atom_api_power_save_blocker.cc | 2 +- atom/browser/browser_linux.cc | 2 +- atom/browser/browser_win.cc | 4 +-- atom/browser/ui/file_dialog_win.cc | 2 +- atom/browser/ui/message_box_win.cc | 2 +- atom/common/api/electron_bindings.cc | 4 +-- atom/common/application_info.cc | 10 +++--- atom/common/application_info_linux.cc | 10 +++--- atom/common/atom_version.h | 33 ------------------ atom/common/crash_reporter/crash_reporter.cc | 6 ++-- atom/common/electron_version.h | 34 +++++++++++++++++++ script/bump-version.js | 14 ++++---- 17 files changed, 71 insertions(+), 70 deletions(-) delete mode 100644 atom/common/atom_version.h create mode 100644 atom/common/electron_version.h diff --git a/BUILD.gn b/BUILD.gn index dd6a69b96e42..53c6c5fa1616 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -51,8 +51,8 @@ if (is_mas_build) { config("branding") { defines = [ - "ATOM_PRODUCT_NAME=\"$electron_product_name\"", - "ATOM_PROJECT_NAME=\"$electron_project_name\"", + "ELECTRON_PRODUCT_NAME=\"$electron_product_name\"", + "ELECTRON_PROJECT_NAME=\"$electron_project_name\"", ] } diff --git a/atom/app/atom_library_main.mm b/atom/app/atom_library_main.mm index bd241ca2f74f..5f2974ee51a3 100644 --- a/atom/app/atom_library_main.mm +++ b/atom/app/atom_library_main.mm @@ -31,7 +31,7 @@ int AtomInitializeICUandStartNode(int argc, char* argv[]) { atom::MainApplicationBundlePath() .Append("Contents") .Append("Frameworks") - .Append(ATOM_PRODUCT_NAME " Framework.framework")); + .Append(ELECTRON_PRODUCT_NAME " Framework.framework")); base::i18n::InitializeICU(); return atom::NodeMain(argc, argv); } diff --git a/atom/app/atom_main_delegate_mac.mm b/atom/app/atom_main_delegate_mac.mm index 4f7dbc515f7e..786c624b33a6 100644 --- a/atom/app/atom_main_delegate_mac.mm +++ b/atom/app/atom_main_delegate_mac.mm @@ -38,13 +38,13 @@ base::FilePath GetHelperAppPath(const base::FilePath& frameworks_path, void AtomMainDelegate::OverrideFrameworkBundlePath() { base::mac::SetOverrideFrameworkBundlePath( - GetFrameworksPath().Append(ATOM_PRODUCT_NAME " Framework.framework")); + GetFrameworksPath().Append(ELECTRON_PRODUCT_NAME " Framework.framework")); } void AtomMainDelegate::OverrideChildProcessPath() { base::FilePath frameworks_path = GetFrameworksPath(); base::FilePath helper_path = - GetHelperAppPath(frameworks_path, ATOM_PRODUCT_NAME); + GetHelperAppPath(frameworks_path, ELECTRON_PRODUCT_NAME); if (!base::PathExists(helper_path)) helper_path = GetHelperAppPath(frameworks_path, GetApplicationName()); if (!base::PathExists(helper_path)) diff --git a/atom/app/node_main.cc b/atom/app/node_main.cc index 3b0d7b23c492..dd23c299197a 100644 --- a/atom/app/node_main.cc +++ b/atom/app/node_main.cc @@ -11,8 +11,8 @@ #include "atom/browser/javascript_environment.h" #include "atom/browser/node_debugger.h" #include "atom/common/api/electron_bindings.h" -#include "atom/common/atom_version.h" #include "atom/common/crash_reporter/crash_reporter.h" +#include "atom/common/electron_version.h" #include "atom/common/native_mate_converters/string16_converter.h" #include "atom/common/node_bindings.h" #include "atom/common/node_includes.h" @@ -88,7 +88,7 @@ int NodeMain(int argc, char* argv[]) { mate::Dictionary versions; if (process.Get("versions", &versions)) { - versions.SetReadOnly(ATOM_PROJECT_NAME, ATOM_VERSION_STRING); + versions.SetReadOnly(ELECTRON_PROJECT_NAME, ELECTRON_VERSION_STRING); } node::LoadEnvironment(env); diff --git a/atom/browser/api/atom_api_net_log.cc b/atom/browser/api/atom_api_net_log.cc index afde84329da1..b714c535785f 100644 --- a/atom/browser/api/atom_api_net_log.cc +++ b/atom/browser/api/atom_api_net_log.cc @@ -8,7 +8,7 @@ #include "atom/browser/atom_browser_context.h" #include "atom/browser/net/system_network_context_manager.h" -#include "atom/common/atom_version.h" +#include "atom/common/electron_version.h" #include "atom/common/native_mate_converters/callback.h" #include "atom/common/native_mate_converters/file_path_converter.h" #include "atom/common/node_includes.h" @@ -77,7 +77,7 @@ v8::Local NetLog::StartLogging(mate::Arguments* args) { auto command_line_string = base::CommandLine::ForCurrentProcess()->GetCommandLineString(); - auto channel_string = std::string("Electron " ATOM_VERSION); + auto channel_string = std::string("Electron " ELECTRON_VERSION); base::Value custom_constants = base::Value::FromUniquePtrValue( net_log::ChromeNetLog::GetPlatformConstants(command_line_string, channel_string)); diff --git a/atom/browser/api/atom_api_power_save_blocker.cc b/atom/browser/api/atom_api_power_save_blocker.cc index f68c25f81088..bf2f6c72cdd3 100644 --- a/atom/browser/api/atom_api_power_save_blocker.cc +++ b/atom/browser/api/atom_api_power_save_blocker.cc @@ -96,7 +96,7 @@ device::mojom::WakeLock* PowerSaveBlocker::GetWakeLock() { wake_lock_provider->GetWakeLockWithoutContext( device::mojom::WakeLockType::kPreventAppSuspension, - device::mojom::WakeLockReason::kOther, ATOM_PRODUCT_NAME, + device::mojom::WakeLockReason::kOther, ELECTRON_PRODUCT_NAME, mojo::MakeRequest(&wake_lock_)); } return wake_lock_.get(); diff --git a/atom/browser/browser_linux.cc b/atom/browser/browser_linux.cc index acadea7913e5..4aae2f3aaae9 100644 --- a/atom/browser/browser_linux.cc +++ b/atom/browser/browser_linux.cc @@ -10,7 +10,7 @@ #include "atom/browser/native_window.h" #include "atom/browser/window_list.h" #include "atom/common/application_info.h" -#include "atom/common/atom_version.h" +#include "atom/common/electron_version.h" #include "base/command_line.h" #include "base/environment.h" #include "base/process/launch.h" diff --git a/atom/browser/browser_win.cc b/atom/browser/browser_win.cc index e37eb0aec399..549c5ff1e630 100644 --- a/atom/browser/browser_win.cc +++ b/atom/browser/browser_win.cc @@ -12,7 +12,7 @@ #include "atom/browser/ui/win/jump_list.h" #include "atom/common/application_info.h" -#include "atom/common/atom_version.h" +#include "atom/common/electron_version.h" #include "atom/common/native_mate_converters/string16_converter.h" #include "base/base_paths.h" #include "base/file_version_info.h" @@ -338,7 +338,7 @@ std::string Browser::GetExecutableFileVersion() const { return base::UTF16ToUTF8(version_info->product_version()); } - return ATOM_VERSION_STRING; + return ELECTRON_VERSION_STRING; } std::string Browser::GetExecutableFileProductName() const { diff --git a/atom/browser/ui/file_dialog_win.cc b/atom/browser/ui/file_dialog_win.cc index fcceca2fdbd6..a2be90a781a8 100644 --- a/atom/browser/ui/file_dialog_win.cc +++ b/atom/browser/ui/file_dialog_win.cc @@ -71,7 +71,7 @@ struct RunState { bool CreateDialogThread(RunState* run_state) { auto thread = - std::make_unique(ATOM_PRODUCT_NAME "FileDialogThread"); + std::make_unique(ELECTRON_PRODUCT_NAME "FileDialogThread"); thread->init_com_with_mta(false); if (!thread->Start()) return false; diff --git a/atom/browser/ui/message_box_win.cc b/atom/browser/ui/message_box_win.cc index cc27ef0d45c5..0dc96f39ddc5 100644 --- a/atom/browser/ui/message_box_win.cc +++ b/atom/browser/ui/message_box_win.cc @@ -226,7 +226,7 @@ int ShowMessageBoxSync(const MessageBoxSettings& settings) { void ShowMessageBox(const MessageBoxSettings& settings, MessageBoxCallback callback) { auto thread = - std::make_unique(ATOM_PRODUCT_NAME "MessageBoxThread"); + std::make_unique(ELECTRON_PRODUCT_NAME "MessageBoxThread"); thread->init_com_with_mta(false); if (!thread->Start()) { std::move(callback).Run(settings.cancel_id, settings.checkbox_checked); diff --git a/atom/common/api/electron_bindings.cc b/atom/common/api/electron_bindings.cc index a76f16846cbd..4c38e93dfde1 100644 --- a/atom/common/api/electron_bindings.cc +++ b/atom/common/api/electron_bindings.cc @@ -13,7 +13,7 @@ #include "atom/browser/browser.h" #include "atom/common/api/locker.h" #include "atom/common/application_info.h" -#include "atom/common/atom_version.h" +#include "atom/common/electron_version.h" #include "atom/common/heap_snapshot.h" #include "atom/common/native_mate_converters/file_path_converter.h" #include "atom/common/native_mate_converters/string16_converter.h" @@ -106,7 +106,7 @@ void ElectronBindings::BindTo(v8::Isolate* isolate, mate::Dictionary versions; if (dict.Get("versions", &versions)) { - versions.SetReadOnly(ATOM_PROJECT_NAME, ATOM_VERSION_STRING); + versions.SetReadOnly(ELECTRON_PROJECT_NAME, ELECTRON_VERSION_STRING); versions.SetReadOnly("chrome", CHROME_VERSION_STRING); } } diff --git a/atom/common/application_info.cc b/atom/common/application_info.cc index c0f771576839..7d8b24ee82e7 100644 --- a/atom/common/application_info.cc +++ b/atom/common/application_info.cc @@ -5,7 +5,7 @@ #include "atom/common/application_info.h" #include "atom/browser/browser.h" -#include "atom/common/atom_version.h" +#include "atom/common/electron_version.h" #include "base/no_destructor.h" #include "base/strings/stringprintf.h" #include "chrome/common/chrome_version.h" @@ -42,12 +42,12 @@ std::string GetApplicationUserAgent() { std::string name, user_agent; if (!base::RemoveChars(browser->GetName(), " ", &name)) name = browser->GetName(); - if (name == ATOM_PRODUCT_NAME) { - user_agent = "Chrome/" CHROME_VERSION_STRING " " ATOM_PRODUCT_NAME - "/" ATOM_VERSION_STRING; + if (name == ELECTRON_PRODUCT_NAME) { + user_agent = "Chrome/" CHROME_VERSION_STRING " " ELECTRON_PRODUCT_NAME + "/" ELECTRON_VERSION_STRING; } else { user_agent = base::StringPrintf( - "%s/%s Chrome/%s " ATOM_PRODUCT_NAME "/" ATOM_VERSION_STRING, + "%s/%s Chrome/%s " ELECTRON_PRODUCT_NAME "/" ELECTRON_VERSION_STRING, name.c_str(), browser->GetVersion().c_str(), CHROME_VERSION_STRING); } return content::BuildUserAgentFromProduct(user_agent); diff --git a/atom/common/application_info_linux.cc b/atom/common/application_info_linux.cc index ea69acad1288..c499bc80c312 100644 --- a/atom/common/application_info_linux.cc +++ b/atom/common/application_info_linux.cc @@ -10,7 +10,7 @@ #include #include -#include "atom/common/atom_version.h" +#include "atom/common/electron_version.h" #include "atom/common/platform_util.h" #include "base/environment.h" #include "base/logging.h" @@ -50,7 +50,7 @@ std::string GetApplicationName() { // attempt #3: Electron's name if (ret.empty()) { - ret = ATOM_PRODUCT_NAME; + ret = ELECTRON_PRODUCT_NAME; } return ret; @@ -59,9 +59,9 @@ std::string GetApplicationName() { std::string GetApplicationVersion() { std::string ret; - // ensure ATOM_PRODUCT_NAME and ATOM_PRODUCT_STRING match up - if (GetApplicationName() == ATOM_PRODUCT_NAME) - ret = ATOM_VERSION_STRING; + // ensure ELECTRON_PRODUCT_NAME and GetApplicationVersion match up + if (GetApplicationName() == ELECTRON_PRODUCT_NAME) + ret = ELECTRON_VERSION_STRING; // try to use the string set in app.setVersion() if (ret.empty()) diff --git a/atom/common/atom_version.h b/atom/common/atom_version.h deleted file mode 100644 index dc43033d6e3c..000000000000 --- a/atom/common/atom_version.h +++ /dev/null @@ -1,33 +0,0 @@ -// 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_COMMON_ATOM_VERSION_H_ -#define ATOM_COMMON_ATOM_VERSION_H_ - -#define ATOM_MAJOR_VERSION 7 -#define ATOM_MINOR_VERSION 0 -#define ATOM_PATCH_VERSION 0 -// clang-format off -#define ATOM_PRE_RELEASE_VERSION -nightly.20190616 -// clang-format on - -#ifndef ATOM_STRINGIFY -#define ATOM_STRINGIFY(n) ATOM_STRINGIFY_HELPER(n) -#define ATOM_STRINGIFY_HELPER(n) #n -#endif - -#ifndef ATOM_PRE_RELEASE_VERSION -#define ATOM_VERSION_STRING \ - ATOM_STRINGIFY(ATOM_MAJOR_VERSION) \ - "." ATOM_STRINGIFY(ATOM_MINOR_VERSION) "." ATOM_STRINGIFY(ATOM_PATCH_VERSION) -#else -#define ATOM_VERSION_STRING \ - ATOM_STRINGIFY(ATOM_MAJOR_VERSION) \ - "." ATOM_STRINGIFY(ATOM_MINOR_VERSION) "." ATOM_STRINGIFY( \ - ATOM_PATCH_VERSION) ATOM_STRINGIFY(ATOM_PRE_RELEASE_VERSION) -#endif - -#define ATOM_VERSION "v" ATOM_VERSION_STRING - -#endif // ATOM_COMMON_ATOM_VERSION_H_ diff --git a/atom/common/crash_reporter/crash_reporter.cc b/atom/common/crash_reporter/crash_reporter.cc index ca404969db41..63625e61caf7 100644 --- a/atom/common/crash_reporter/crash_reporter.cc +++ b/atom/common/crash_reporter/crash_reporter.cc @@ -8,7 +8,7 @@ #include "atom/browser/browser.h" #include "atom/common/atom_constants.h" -#include "atom/common/atom_version.h" +#include "atom/common/electron_version.h" #include "atom/common/native_mate_converters/file_path_converter.h" #include "atom/common/native_mate_converters/map_converter.h" #include "base/command_line.h" @@ -59,8 +59,8 @@ void CrashReporter::SetUploadParameters(const StringMap& parameters) { upload_parameters_ = parameters; upload_parameters_["process_type"] = process_type_.empty() ? "browser" : process_type_; - upload_parameters_["prod"] = ATOM_PRODUCT_NAME; - upload_parameters_["ver"] = ATOM_VERSION_STRING; + upload_parameters_["prod"] = ELECTRON_PRODUCT_NAME; + upload_parameters_["ver"] = ELECTRON_VERSION_STRING; // Setting platform dependent parameters. SetUploadParameters(); diff --git a/atom/common/electron_version.h b/atom/common/electron_version.h new file mode 100644 index 000000000000..bcc79a937c53 --- /dev/null +++ b/atom/common/electron_version.h @@ -0,0 +1,34 @@ +// 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_COMMON_ELECTRON_VERSION_H_ +#define ATOM_COMMON_ELECTRON_VERSION_H_ + +#define ELECTRON_MAJOR_VERSION 7 +#define ELECTRON_MINOR_VERSION 0 +#define ELECTRON_PATCH_VERSION 0 +// clang-format off +#define ELECTRON_PRE_RELEASE_VERSION -nightly.20190616 +// clang-format on + +#ifndef ELECTRON_STRINGIFY +#define ELECTRON_STRINGIFY(n) ELECTRON_STRINGIFY_HELPER(n) +#define ELECTRON_STRINGIFY_HELPER(n) #n +#endif + +#ifndef ELECTRON_PRE_RELEASE_VERSION +#define ELECTRON_VERSION_STRING \ + ELECTRON_STRINGIFY(ELECTRON_MAJOR_VERSION) \ + "." ELECTRON_STRINGIFY(ELECTRON_MINOR_VERSION) "." ELECTRON_STRINGIFY( \ + ELECTRON_PATCH_VERSION) +#else +#define ELECTRON_VERSION_STRING \ + ELECTRON_STRINGIFY(ELECTRON_MAJOR_VERSION) \ + "." ELECTRON_STRINGIFY(ELECTRON_MINOR_VERSION) "." ELECTRON_STRINGIFY( \ + ELECTRON_PATCH_VERSION) ELECTRON_STRINGIFY(ELECTRON_PRE_RELEASE_VERSION) +#endif + +#define ELECTRON_VERSION "v" ELECTRON_VERSION_STRING + +#endif // ATOM_COMMON_ELECTRON_VERSION_H_ diff --git a/script/bump-version.js b/script/bump-version.js index c1027b9ebfe0..ae1a87607e43 100644 --- a/script/bump-version.js +++ b/script/bump-version.js @@ -138,20 +138,20 @@ async function commitVersionBump (version) { await GitProcess.exec(gitArgs, gitDir) } -// updates atom_version.h file with new semver values +// updates electron_version.h file with new semver values // TODO(codebytere): auto-generate this async function updateVersionH (components) { - const filePath = path.resolve(__dirname, '..', 'atom', 'common', 'atom_version.h') + const filePath = path.resolve(__dirname, '..', 'atom', 'common', 'electron_version.h') const data = await readFile(filePath, 'utf8') const arr = data.split('\n') const pre = components.pre && components.pre.length >= 2 ? `-${components.pre[0]}.${components.pre[1]}` : null arr.forEach((item, idx) => { - if (item.includes('#define ATOM_MAJOR_VERSION')) { - arr[idx] = `#define ATOM_MAJOR_VERSION ${components.major}` - arr[idx + 1] = `#define ATOM_MINOR_VERSION ${components.minor}` - arr[idx + 2] = `#define ATOM_PATCH_VERSION ${components.patch}` - arr[idx + 4] = pre ? `#define ATOM_PRE_RELEASE_VERSION ${pre}` : '// #define ATOM_PRE_RELEASE_VERSION' + if (item.includes('#define ELECTRON_MAJOR_VERSION')) { + arr[idx] = `#define ELECTRON_MAJOR_VERSION ${components.major}` + arr[idx + 1] = `#define ELECTRON_MINOR_VERSION ${components.minor}` + arr[idx + 2] = `#define ELECTRON_PATCH_VERSION ${components.patch}` + arr[idx + 4] = pre ? `#define ELECTRON_PRE_RELEASE_VERSION ${pre}` : '// #define ELECTRON_PRE_RELEASE_VERSION' } }) await writeFile(filePath, arr.join('\n'))