Skip to content
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

refactor: auto generate electron_version.h from the version file #18866

Merged
merged 2 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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[0]) ]
MarshallOfSound marked this conversation as resolved.
Show resolved Hide resolved

inputs = [
"ELECTRON_VERSION",
"script/generate-version-json.js",
MarshallOfSound marked this conversation as resolved.
Show resolved Hide resolved
]
}

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" ]
Expand All @@ -315,6 +342,7 @@ static_library("electron_lib") {

deps = [
":atom_js2c",
":electron_version_header",
":manifests",
":resources",
"atom/common/api:mojo",
Expand Down
2 changes: 1 addition & 1 deletion atom/app/node_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
#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"
#include "base/command_line.h"
#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"
Expand Down
2 changes: 1 addition & 1 deletion atom/browser/api/atom_api_net_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

#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"
#include "base/command_line.h"
#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"
Expand Down
2 changes: 1 addition & 1 deletion atom/browser/browser_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion atom/browser/browser_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion atom/common/api/electron_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion atom/common/application_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
2 changes: 1 addition & 1 deletion atom/common/application_info_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#include <memory>
#include <string>

#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 {

Expand Down
2 changes: 1 addition & 1 deletion atom/common/crash_reporter/crash_reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {

Expand Down
34 changes: 0 additions & 34 deletions atom/common/electron_version.h

This file was deleted.

16 changes: 16 additions & 0 deletions build/generate-template.py
Original file line number Diff line number Diff line change
@@ -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)
39 changes: 39 additions & 0 deletions build/templated_file.gni
Original file line number Diff line number Diff line change
@@ -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
}
}
}
23 changes: 23 additions & 0 deletions build/templates/electron_version.tmpl
Original file line number Diff line number Diff line change
@@ -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
MarshallOfSound marked this conversation as resolved.
Show resolved Hide resolved

#endif // ELECTRON_ELECTRON_VERSION_H
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
20 changes: 0 additions & 20 deletions script/bump-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ async function main () {
await Promise.all([
updateVersion(version),
updatePackageJSON(version),
updateVersionH(components),
updateWinRC(components)
])

Expand Down Expand Up @@ -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')
Expand Down
28 changes: 28 additions & 0 deletions script/generate-version-json.js
Original file line number Diff line number Diff line change
@@ -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))