From 724d956fd431677162239232678d5114c151a446 Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Fri, 15 Mar 2019 22:35:25 +0000 Subject: [PATCH] Move use_abi_version from vm directory to bin I need to access the flag in bin/main.cc, so it can't be in the vm directory Bug: https://github.com/dart-lang/sdk/issues/36047 Change-Id: Ib19a1b4d89295449b25f7753b2a39f6232c004e3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97122 Commit-Queue: Liam Appelbe Reviewed-by: Ryan Macnak --- runtime/bin/BUILD.gn | 23 +++++++++++++++++++++++ runtime/bin/abi_version.h | 18 ++++++++++++++++++ runtime/bin/abi_version_in.cc | 17 +++++++++++++++++ runtime/bin/builtin_impl_sources.gni | 1 + runtime/bin/main_options.cc | 27 +++++++++++++++++++++++++++ runtime/bin/main_options.h | 7 ++++++- runtime/vm/version.h | 1 - runtime/vm/version_in.cc | 14 -------------- 8 files changed, 92 insertions(+), 16 deletions(-) create mode 100644 runtime/bin/abi_version.h create mode 100644 runtime/bin/abi_version_in.cc diff --git a/runtime/bin/BUILD.gn b/runtime/bin/BUILD.gn index 51c708ce6a1..572487942d2 100644 --- a/runtime/bin/BUILD.gn +++ b/runtime/bin/BUILD.gn @@ -654,6 +654,27 @@ source_set("dart_kernel_platform_cc") { get_target_outputs(":platform_strong_dill_linkable") } +action("generate_abi_version_cc_file") { + inputs = [ + "../../tools/utils.py", + "../../tools/VERSION", + "abi_version_in.cc", + ] + output = "$target_gen_dir/abi_version.cc" + outputs = [ + output, + ] + + script = "../../tools/make_version.py" + args = [ + "--quiet", + "--output", + rebase_path(output, root_build_dir), + "--input", + rebase_path("abi_version_in.cc", root_build_dir), + ] +} + template("dart_executable") { extra_configs = [] if (defined(invoker.extra_configs)) { @@ -702,6 +723,7 @@ template("dart_executable") { "//third_party/boringssl", "//third_party/zlib", ":crashpad", + ":generate_abi_version_cc_file", ] + extra_deps defines = extra_defines @@ -731,6 +753,7 @@ template("dart_executable") { "snapshot_utils.h", "vmservice_impl.cc", "vmservice_impl.h", + "$target_gen_dir/abi_version.cc", ] + extra_sources if (is_win) { diff --git a/runtime/bin/abi_version.h b/runtime/bin/abi_version.h new file mode 100644 index 00000000000..acd0cdf93cb --- /dev/null +++ b/runtime/bin/abi_version.h @@ -0,0 +1,18 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +#ifndef RUNTIME_BIN_ABI_VERSION_H_ +#define RUNTIME_BIN_ABI_VERSION_H_ + +namespace dart { + +class AbiVersion { + public: + static int GetCurrent(); + static int GetOldestSupported(); +}; + +} // namespace dart + +#endif // RUNTIME_BIN_ABI_VERSION_H_ diff --git a/runtime/bin/abi_version_in.cc b/runtime/bin/abi_version_in.cc new file mode 100644 index 00000000000..ad737b24b63 --- /dev/null +++ b/runtime/bin/abi_version_in.cc @@ -0,0 +1,17 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +#include "bin/abi_version.h" + +namespace dart { + +int AbiVersion::GetCurrent() { + return {{ABI_VERSION}}; +} + +int AbiVersion::GetOldestSupported() { + return {{OLDEST_SUPPORTED_ABI_VERSION}}; +} + +} // namespace dart diff --git a/runtime/bin/builtin_impl_sources.gni b/runtime/bin/builtin_impl_sources.gni index d4c7489c5a1..f329f034055 100644 --- a/runtime/bin/builtin_impl_sources.gni +++ b/runtime/bin/builtin_impl_sources.gni @@ -7,6 +7,7 @@ # io_impl_sources.gypi. builtin_impl_sources = [ + "abi_version.h", "crypto.cc", "crypto.h", "crypto_android.cc", diff --git a/runtime/bin/main_options.cc b/runtime/bin/main_options.cc index a7181f5b0e6..d68bfaa8ab2 100644 --- a/runtime/bin/main_options.cc +++ b/runtime/bin/main_options.cc @@ -8,6 +8,7 @@ #include #include +#include "bin/abi_version.h" #include "bin/log.h" #include "bin/options.h" #include "bin/platform.h" @@ -324,6 +325,32 @@ bool Options::ProcessObserveOption(const char* arg, return true; } +int Options::target_abi_version_ = AbiVersion::GetCurrent(); +bool Options::ProcessAbiVersionOption(const char* arg, + CommandLineOptions* vm_options) { + const char* value = OptionProcessor::ProcessOption(arg, "--use_abi_version="); + if (value == NULL) { + return false; + } + int ver = 0; + for (int i = 0; value[i]; ++i) { + if (value[i] >= '0' && value[i] <= '9') { + ver = (ver * 10) + value[i] - '0'; + } else { + Log::PrintErr("--use_abi_version must be an int\n"); + return false; + } + } + if (ver < AbiVersion::GetOldestSupported() || + ver > AbiVersion::GetCurrent()) { + Log::PrintErr("--use_abi_version must be between %d and %d inclusive\n", + AbiVersion::GetOldestSupported(), AbiVersion::GetCurrent()); + return false; + } + target_abi_version_ = ver; + return true; +} + static bool checked_set = false; int Options::ParseArguments(int argc, diff --git a/runtime/bin/main_options.h b/runtime/bin/main_options.h index a2c2755d41a..e29069601bd 100644 --- a/runtime/bin/main_options.h +++ b/runtime/bin/main_options.h @@ -62,7 +62,8 @@ namespace bin { #define CB_OPTIONS_LIST(V) \ V(ProcessEnvironmentOption) \ V(ProcessEnableVmServiceOption) \ - V(ProcessObserveOption) + V(ProcessObserveOption) \ + V(ProcessAbiVersionOption) // This enum must match the strings in kSnapshotKindNames in main_options.cc. enum SnapshotKind { @@ -115,6 +116,8 @@ class Options { static const char* vm_service_server_ip() { return vm_service_server_ip_; } static int vm_service_server_port() { return vm_service_server_port_; } + static int target_abi_version() { return target_abi_version_; } + #if !defined(DART_PRECOMPILED_RUNTIME) static DFE* dfe() { return dfe_; } static void set_dfe(DFE* dfe) { dfe_ = dfe; } @@ -159,6 +162,8 @@ class Options { int default_port, const char* default_ip); + static int target_abi_version_; + #define OPTION_FRIEND(flag, variable) friend class OptionProcessor_##flag; STRING_OPTIONS_LIST(OPTION_FRIEND) BOOL_OPTIONS_LIST(OPTION_FRIEND) diff --git a/runtime/vm/version.h b/runtime/vm/version.h index 24540c39d77..fdc6bb0f5bc 100644 --- a/runtime/vm/version.h +++ b/runtime/vm/version.h @@ -14,7 +14,6 @@ class Version : public AllStatic { static const char* String(); static const char* SnapshotString(); static const char* CommitString(); - static int TargetAbiVersion(); static int CurrentAbiVersion(); static int OldestSupportedAbiVersion(); diff --git a/runtime/vm/version_in.cc b/runtime/vm/version_in.cc index d59584b8ed5..ae3cff78bf4 100644 --- a/runtime/vm/version_in.cc +++ b/runtime/vm/version_in.cc @@ -10,12 +10,6 @@ namespace dart { -DEFINE_FLAG(int, - use_abi_version, - Version::CurrentAbiVersion(), - "ABI version to use. Valid values are " - "{{OLDEST_SUPPORTED_ABI_VERSION}} to {{ABI_VERSION}}."); - // TODO(iposva): Avoid racy initialization. static const char* formatted_version = NULL; @@ -36,14 +30,6 @@ const char* Version::CommitString() { return commit_; } -int Version::TargetAbiVersion() { - int ver = FLAG_use_abi_version; - if (ver < OldestSupportedAbiVersion() || ver > CurrentAbiVersion()) { - ver = CurrentAbiVersion(); - } - return ver; -} - int Version::CurrentAbiVersion() { return {{ABI_VERSION}}; }