From a7bb8ccce85c6e8bd619cce32d34a5d372ef85b7 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Sat, 2 Mar 2019 09:33:28 +0900 Subject: [PATCH] Add Deno.version.gnArgs (#1845) To display specific build args passed to GN. --- BUILD.gn | 12 ++++++++++++ js/version.ts | 4 +++- js/version_test.ts | 4 ++++ rollup.config.js | 4 +++- tools/setup.py | 2 +- tools/write_gn_args.py | 16 ++++++++++++++++ 6 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 tools/write_gn_args.py diff --git a/BUILD.gn b/BUILD.gn index 4e7ab41adb..6c2528704b 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -221,6 +221,10 @@ bundle("main_bundle") { deps = [ ":deno_runtime_declaration", ":msg_ts", + ":write_gn_args", + ] + data = [ + "$target_gen_dir/gn_args.txt", ] } @@ -260,3 +264,11 @@ snapshot("snapshot_compiler") { ":compiler_bundle", ] } + +action("write_gn_args") { + script = "//tools/write_gn_args.py" + outputs = [ + "$target_gen_dir/gn_args.txt", + ] + args = [ rebase_path(outputs[0], root_build_dir) ] +} diff --git a/js/version.ts b/js/version.ts index 805e565a07..984550a746 100644 --- a/js/version.ts +++ b/js/version.ts @@ -3,12 +3,14 @@ interface Version { deno: string; v8: string; typescript: string; + gnArgs: string; } export const version: Version = { deno: "", v8: "", - typescript: "TS_VERSION" // This string will be replaced by rollup + typescript: "TS_VERSION", // This string will be replaced by rollup + gnArgs: `GN_ARGS` // This string will be replaced by rollup }; /** diff --git a/js/version_test.ts b/js/version_test.ts index d3d1bc3dfe..bef00dbc3f 100644 --- a/js/version_test.ts +++ b/js/version_test.ts @@ -6,3 +6,7 @@ test(function version() { assert(pattern.test(Deno.version.v8)); assert(pattern.test(Deno.version.typescript)); }); + +test(function versionGnArgs() { + assert(Deno.version.gnArgs.length > 100); +}); diff --git a/rollup.config.js b/rollup.config.js index 34f998b739..9c69fcf2a5 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -20,6 +20,7 @@ const typescriptPath = path.resolve( __dirname, "third_party/node_modules/typescript/lib/typescript.js" ); +const gnArgs = fs.readFileSync("gen/gn_args.txt", "utf-8").trim(); // We will allow generated modules to be resolvable by TypeScript based on // the current build path @@ -228,7 +229,8 @@ export default function makeConfig(commandOptions) { // replace strings replace({ - TS_VERSION: typescript.version + TS_VERSION: typescript.version, + GN_ARGS: gnArgs }), // would prefer to use `rollup-plugin-virtual` to inject the empty module, but there diff --git a/tools/setup.py b/tools/setup.py index 4958cca2ab..95b3b880af 100755 --- a/tools/setup.py +++ b/tools/setup.py @@ -2,7 +2,7 @@ # Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import third_party from util import build_mode, build_path, enable_ansi_colors, root_path, run -from util import shell_quote +from util import shell_quote, run_output import os import re import sys diff --git a/tools/write_gn_args.py b/tools/write_gn_args.py new file mode 100644 index 0000000000..764dcc6c19 --- /dev/null +++ b/tools/write_gn_args.py @@ -0,0 +1,16 @@ +# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +import os +import sys +import third_party +from util import run_output, build_path + +out_filename = sys.argv[1] + +args_list = run_output([ + third_party.gn_path, "args", + build_path(), "--list", "--short", "--overrides-only" +], + env=third_party.google_env()) + +with open(out_filename, "w") as f: + f.write(args_list)