diff --git a/BUILD.gn b/BUILD.gn index 16b0cde5606e..da0a2c865960 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -11,6 +11,7 @@ import("//tools/v8_context_snapshot/v8_context_snapshot.gni") import("//v8/gni/snapshot_toolchain.gni") import("build/asar.gni") import("build/npm.gni") +import("build/templated_file.gni") import("build/tsc.gni") import("build/webpack/webpack.gni") import("buildflags/buildflags.gni") @@ -307,6 +308,32 @@ source_set("manifests") { } } +npm_action("electron_version_args") { + script = "generate-version-json" + + outputs = [ + "$target_gen_dir/electron_version.args", + ] + + args = rebase_path(outputs) + + inputs = [ + "ELECTRON_VERSION", + "script/generate-version-json.js", + ] +} + +templated_file("electron_version_header") { + deps = [ + ":electron_version_args", + ] + + template = "build/templates/electron_version.tmpl" + output = "$target_gen_dir/electron_version.h" + + args_files = get_target_outputs(":electron_version_args") +} + static_library("electron_lib") { configs += [ "//v8:external_startup_data" ] configs += [ "//third_party/electron_node:node_internals" ] @@ -315,6 +342,7 @@ static_library("electron_lib") { deps = [ ":atom_js2c", + ":electron_version_header", ":manifests", ":resources", "atom/common/api:mojo", diff --git a/atom/app/node_main.cc b/atom/app/node_main.cc index dd23c299197a..91f4a6a61ebe 100644 --- a/atom/app/node_main.cc +++ b/atom/app/node_main.cc @@ -12,7 +12,6 @@ #include "atom/browser/node_debugger.h" #include "atom/common/api/electron_bindings.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" @@ -20,6 +19,7 @@ #include "base/feature_list.h" #include "base/task/thread_pool/thread_pool.h" #include "base/threading/thread_task_runner_handle.h" +#include "electron/electron_version.h" #include "gin/array_buffer.h" #include "gin/public/isolate_holder.h" #include "gin/v8_initializer.h" diff --git a/atom/browser/api/atom_api_net_log.cc b/atom/browser/api/atom_api_net_log.cc index b714c535785f..cf89075e9c6d 100644 --- a/atom/browser/api/atom_api_net_log.cc +++ b/atom/browser/api/atom_api_net_log.cc @@ -8,7 +8,6 @@ #include "atom/browser/atom_browser_context.h" #include "atom/browser/net/system_network_context_manager.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" @@ -16,6 +15,7 @@ #include "chrome/browser/browser_process.h" #include "components/net_log/chrome_net_log.h" #include "content/public/browser/storage_partition.h" +#include "electron/electron_version.h" #include "native_mate/dictionary.h" #include "native_mate/handle.h" #include "net/url_request/url_request_context_getter.h" diff --git a/atom/browser/browser_linux.cc b/atom/browser/browser_linux.cc index 4aae2f3aaae9..935248d60d6b 100644 --- a/atom/browser/browser_linux.cc +++ b/atom/browser/browser_linux.cc @@ -10,10 +10,10 @@ #include "atom/browser/native_window.h" #include "atom/browser/window_list.h" #include "atom/common/application_info.h" -#include "atom/common/electron_version.h" #include "base/command_line.h" #include "base/environment.h" #include "base/process/launch.h" +#include "electron/electron_version.h" #if defined(USE_X11) #include "chrome/browser/ui/libgtkui/gtk_util.h" diff --git a/atom/browser/browser_win.cc b/atom/browser/browser_win.cc index 549c5ff1e630..75903f27924e 100644 --- a/atom/browser/browser_win.cc +++ b/atom/browser/browser_win.cc @@ -12,7 +12,6 @@ #include "atom/browser/ui/win/jump_list.h" #include "atom/common/application_info.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" @@ -25,6 +24,7 @@ #include "base/win/registry.h" #include "base/win/win_util.h" #include "base/win/windows_version.h" +#include "electron/electron_version.h" #include "ui/events/keycodes/keyboard_code_conversion_win.h" namespace atom { diff --git a/atom/common/api/electron_bindings.cc b/atom/common/api/electron_bindings.cc index 4c38e93dfde1..42fb30366f97 100644 --- a/atom/common/api/electron_bindings.cc +++ b/atom/common/api/electron_bindings.cc @@ -13,7 +13,6 @@ #include "atom/browser/browser.h" #include "atom/common/api/locker.h" #include "atom/common/application_info.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" @@ -26,6 +25,7 @@ #include "base/system/sys_info.h" #include "base/threading/thread_restrictions.h" #include "chrome/common/chrome_version.h" +#include "electron/electron_version.h" #include "native_mate/dictionary.h" #include "services/resource_coordinator/public/cpp/memory_instrumentation/global_memory_dump.h" #include "services/resource_coordinator/public/cpp/memory_instrumentation/memory_instrumentation.h" diff --git a/atom/common/application_info.cc b/atom/common/application_info.cc index 7d8b24ee82e7..06b6a11197d3 100644 --- a/atom/common/application_info.cc +++ b/atom/common/application_info.cc @@ -5,11 +5,11 @@ #include "atom/common/application_info.h" #include "atom/browser/browser.h" -#include "atom/common/electron_version.h" #include "base/no_destructor.h" #include "base/strings/stringprintf.h" #include "chrome/common/chrome_version.h" #include "content/public/common/user_agent.h" +#include "electron/electron_version.h" namespace atom { diff --git a/atom/common/application_info_linux.cc b/atom/common/application_info_linux.cc index c499bc80c312..fa16ded4dcc0 100644 --- a/atom/common/application_info_linux.cc +++ b/atom/common/application_info_linux.cc @@ -10,11 +10,11 @@ #include #include -#include "atom/common/electron_version.h" #include "atom/common/platform_util.h" #include "base/environment.h" #include "base/logging.h" #include "chrome/browser/ui/libgtkui/gtk_util.h" +#include "electron/electron_version.h" namespace { diff --git a/atom/common/crash_reporter/crash_reporter.cc b/atom/common/crash_reporter/crash_reporter.cc index 63625e61caf7..234bb300a004 100644 --- a/atom/common/crash_reporter/crash_reporter.cc +++ b/atom/common/crash_reporter/crash_reporter.cc @@ -8,7 +8,6 @@ #include "atom/browser/browser.h" #include "atom/common/atom_constants.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" @@ -18,6 +17,7 @@ #include "base/strings/string_split.h" #include "base/threading/thread_restrictions.h" #include "content/public/common/content_switches.h" +#include "electron/electron_version.h" namespace crash_reporter { diff --git a/atom/common/electron_version.h b/atom/common/electron_version.h deleted file mode 100644 index e6bafc7296f7..000000000000 --- a/atom/common/electron_version.h +++ /dev/null @@ -1,34 +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_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.20190619 -// 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/build/generate-template.py b/build/generate-template.py new file mode 100644 index 000000000000..8d5cc04210ef --- /dev/null +++ b/build/generate-template.py @@ -0,0 +1,16 @@ +import json +import sys +from string import Template + +inpath = sys.argv[1] +outpath = sys.argv[2] +argpaths = sys.argv[3:] + +with open(inpath, 'r') as infile, open(outpath, 'w') as outfile: + data = {} + for argpath in argpaths: + with open(argpath, 'r') as argfile: + data.update(json.load(argfile)) + + s = Template(infile.read()).substitute(data) + outfile.write(s) diff --git a/build/templated_file.gni b/build/templated_file.gni new file mode 100644 index 000000000000..b75c49ce2aac --- /dev/null +++ b/build/templated_file.gni @@ -0,0 +1,39 @@ +template("templated_file") { + assert(defined(invoker.template), "Need template file to run") + assert(defined(invoker.output), "Need output file to run") + + if (defined(invoker.values)) { + args_path = "$target_gen_dir/$target_name.args" + write_file(args_path, invoker.values, "json") + } + + action(target_name) { + forward_variables_from(invoker, + [ + "deps", + "public_deps", + "inputs", + "outputs", + ]) + inputs = [ + invoker.template, + ] + outputs = [ + invoker.output, + ] + script = "//electron/build/generate-template.py" + args = [ + rebase_path(invoker.template), + rebase_path(invoker.output), + ] + + if (defined(invoker.values)) { + args += rebase_path(args_path) + } + + if (defined(invoker.args_files)) { + args += rebase_path(invoker.args_files) + inputs += invoker.args_files + } + } +} diff --git a/build/templates/electron_version.tmpl b/build/templates/electron_version.tmpl new file mode 100644 index 000000000000..2baa4fc66049 --- /dev/null +++ b/build/templates/electron_version.tmpl @@ -0,0 +1,23 @@ +// Copyright (c) 2019 Slack Technologies, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef ELECTRON_ELECTRON_VERSION_H +#define ELECTRON_ELECTRON_VERSION_H + +#define ELECTRON_MAJOR_VERSION $major +#define ELECTRON_MINOR_VERSION $minor +#define ELECTRON_PATCH_VERSION $patch +#if $has_prerelease +#define ELECTRON_PRE_RELEASE_VERSION -$prerelease +#endif + +#ifndef ELECTRON_PRE_RELEASE_VERSION +#define ELECTRON_VERSION_STRING "$major.$minor.$patch" +#else +#define ELECTRON_VERSION_STRING "$major.$minor.$patch-$prerelease" +#endif + +#define ELECTRON_VERSION "v" ELECTRON_VERSION_STRING + +#endif // ELECTRON_ELECTRON_VERSION_H diff --git a/package.json b/package.json index f04166119b28..95b201429105 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "bump-version": "./script/bump-version.js", "check-tls": "python ./script/tls.py", "clang-format": "find atom/ chromium_src/ -iname *.h -o -iname *.cc -o -iname *.mm | xargs clang-format -i", + "generate-version-json": "node script/generate-version-json.js", "lint": "node ./script/lint.js && npm run lint:clang-format && npm run lint:docs", "lint:js": "node ./script/lint.js --js", "lint:clang-format": "python script/run-clang-format.py -r -c atom/ chromium_src/ || (echo \"\\nCode not formatted correctly.\" && exit 1)", diff --git a/script/bump-version.js b/script/bump-version.js index 5d08adf0bd2b..abec751b42d1 100644 --- a/script/bump-version.js +++ b/script/bump-version.js @@ -57,7 +57,6 @@ async function main () { await Promise.all([ updateVersion(version), updatePackageJSON(version), - updateVersionH(components), updateWinRC(components) ]) @@ -125,25 +124,6 @@ async function commitVersionBump (version) { await GitProcess.exec(gitArgs, gitDir) } -// 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', '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 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')) -} - // updates atom.rc file with new semver values async function updateWinRC (components) { const filePath = path.resolve(__dirname, '..', 'atom', 'browser', 'resources', 'win', 'atom.rc') diff --git a/script/generate-version-json.js b/script/generate-version-json.js new file mode 100644 index 000000000000..442fbc53dce0 --- /dev/null +++ b/script/generate-version-json.js @@ -0,0 +1,28 @@ +const fs = require('fs') +const path = require('path') +const semver = require('semver') + +const outputPath = process.argv[2] + +const currentVersion = fs.readFileSync(path.resolve(__dirname, '../ELECTRON_VERSION'), 'utf8').trim() + +const parsed = semver.parse(currentVersion) + +let prerelease = '' +if (parsed.prerelease && parsed.prerelease.length > 0) { + prerelease = parsed.prerelease.join('.') +} + +const { + major, + minor, + patch +} = parsed + +fs.writeFileSync(outputPath, JSON.stringify({ + major, + minor, + patch, + prerelease, + has_prerelease: prerelease === '' ? 0 : 1 +}, null, 2))