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

* refactor: auto generate electron_version.h from the version file

* Update BUILD.gn

Co-Authored-By: Jeremy Apthorp <nornagon@nornagon.net>
This commit is contained in:
Samuel Attard 2019-06-19 14:31:55 -07:00 committed by GitHub
parent 504edf2cf6
commit 7201845894
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 143 additions and 62 deletions

View file

@ -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
build/templated_file.gni Normal file
View file

@ -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
}
}
}

View file

@ -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