diff options
author | sdefresne <sdefresne@chromium.org> | 2015-07-30 01:05:54 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-30 08:06:36 +0000 |
commit | 6e883e40d456dd422ac08ced1c25e7403f78bada (patch) | |
tree | 615f0986f2edb95b679d1598eaaff335e29283f1 /components | |
parent | 0289a621d385a5fa87f3635bedaae2daabc6f4b9 (diff) | |
download | chromium_src-6e883e40d456dd422ac08ced1c25e7403f78bada.zip chromium_src-6e883e40d456dd422ac08ced1c25e7403f78bada.tar.gz chromium_src-6e883e40d456dd422ac08ced1c25e7403f78bada.tar.bz2 |
Componentize VersionInfo.
Create a new component version_info that allows to get information about
the current version of Chrome running, except for the channel (which has
to be provided by the embedder).
The method to get the channel is not moved to the component because on
Windows it depends on //chrome/installer which would be non-trivial to
componentize. Since the method is embedder-specific (though it have no
bad dependencies on the other platform) it makes sense to not move it
into the component.
Fixes VersionInfo API to only expose static method (since the class did
not have any state and the API was a mix of "const" and "static" methods)
and to delegate the job to version_info component in order to limit the
API changes.
Mass rename (chrome::)VersionInfo::(Channel|CHANNEL) after the enum was
moved to the version_info namespace in the corresponding component using
tools/git/mffr.py.
Change Channel enumeration to be a "class enum" and add static_cast<int>
where needed (as class enum do not implicitly convert to int).
BUG=511912
Review URL: https://codereview.chromium.org/1257633002
Cr-Commit-Position: refs/heads/master@{#341085}
Diffstat (limited to 'components')
-rw-r--r-- | components/BUILD.gn | 1 | ||||
-rw-r--r-- | components/components.gyp | 1 | ||||
-rw-r--r-- | components/components_strings.grd | 1 | ||||
-rw-r--r-- | components/version_info.grdp | 8 | ||||
-rw-r--r-- | components/version_info.gypi | 124 | ||||
-rw-r--r-- | components/version_info/BUILD.gn | 58 | ||||
-rw-r--r-- | components/version_info/DEPS | 7 | ||||
-rw-r--r-- | components/version_info/OWNERS | 5 | ||||
-rw-r--r-- | components/version_info/version_info.cc | 100 | ||||
-rw-r--r-- | components/version_info/version_info.h | 48 | ||||
-rw-r--r-- | components/version_info/version_info_values.h.version | 13 |
11 files changed, 366 insertions, 0 deletions
diff --git a/components/BUILD.gn b/components/BUILD.gn index c22576c..413e2b8 100644 --- a/components/BUILD.gn +++ b/components/BUILD.gn @@ -114,6 +114,7 @@ group("all_components") { "//components/user_manager", "//components/user_prefs", "//components/variations", + "//components/version_info", "//components/visitedlink/browser", "//components/visitedlink/common", "//components/visitedlink/renderer", diff --git a/components/components.gyp b/components/components.gyp index 464dfad..968acd9 100644 --- a/components/components.gyp +++ b/components/components.gyp @@ -77,6 +77,7 @@ 'url_matcher.gypi', 'user_prefs.gypi', 'variations.gypi', + 'version_info.gypi', 'wallpaper.gypi', 'web_resource.gypi', 'webdata.gypi', diff --git a/components/components_strings.grd b/components/components_strings.grd index 2df5848..cba5f09 100644 --- a/components/components_strings.grd +++ b/components/components_strings.grd @@ -180,6 +180,7 @@ <part file="policy_strings.grdp" /> <part file="translate_strings.grdp" /> <part file="undo_strings.grdp" /> + <part file="version_info.grdp" /> <!-- Generic terms --> <message name="IDS_LEARN_MORE" desc="Learn more text"> diff --git a/components/version_info.grdp b/components/version_info.grdp new file mode 100644 index 0000000..934d17d --- /dev/null +++ b/components/version_info.grdp @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> +<grit-part> + + <message name="IDS_ABOUT_VERSION_UNOFFICIAL" desc="unofficial build on the about:version page"> + Developer Build + </message> + +</grit-part> diff --git a/components/version_info.gypi b/components/version_info.gypi new file mode 100644 index 0000000..fa18bfe --- /dev/null +++ b/components/version_info.gypi @@ -0,0 +1,124 @@ +# Copyright 2015 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +{ + 'variables': { + # Some plaform want to override part of the version number generation + # (for example iOS uses a different value for PATCH level for canary). + # This can be done settings "extra_version_path" variable to the path + # of a file with the corresponding value overrides. If present it will + # be loaded after all other input files. + 'extra_version_name': '', + }, + 'targets': [ + { + # GN version: //components/version_info + 'target_name': 'version_info', + 'type': 'static_library', + 'include_dirs': [ + '..', + ], + 'dependencies': [ + '../base/base.gyp:base', + '../ui/base/ui_base.gyp:ui_base', + 'components_strings.gyp:components_strings', + 'generate_version_info', + ], + 'sources': [ + 'version_info/version_info.cc', + 'version_info/version_info.h', + ], + }, + { + # GN version: //components/version_info:generate_version + 'target_name': 'generate_version_info', + 'type': 'none', + 'direct_dependent_settings': { + 'include_dirs': [ + '<(SHARED_INTERMEDIATE_DIR)', + ], + }, + # Because generate_version_info generates a header, the target must set + # the hard_dependency flag. + 'hard_dependency': 1, + 'actions': [ + { + 'action_name': 'generation_version_info', + 'message': 'Generating version information', + 'variables': { + 'extra_version_flags': [], + 'lastchange_path': '../build/util/LASTCHANGE', + 'version_py_path': '../build/util/version.py', + 'template_input_path': 'version_info/version_info_values.h.version', + # Use VERSION and BRANDING files from //chrome even if this is bad + # dependency until they are moved to src/ for VERSION and to the + # version_info component for BRANDING. Synchronisation with TPM and + # all release script is required for thoses moves. They are tracked + # by issues http://crbug.com/512347 and http://crbug.com/513603. + 'version_path': '../chrome/VERSION', + 'branding_path': '../chrome/app/theme/<(branding_path_component)/BRANDING', + }, + 'inputs': [ + '<(version_py_path)', + '<(template_input_path)', + '<(version_path)', + '<(branding_path)', + '<(lastchange_path)', + ], + 'outputs': [ + '<(SHARED_INTERMEDIATE_DIR)/components/version_info/version_info_values.h', + ], + 'action': [ + 'python', + '<(version_py_path)', + '-f', '<(version_path)', + '-f', '<(branding_path)', + '-f', '<(lastchange_path)', + '<@(extra_version_flags)', + '<(template_input_path)', + '<@(_outputs)', + ], + 'conditions': [ + ['extra_version_name!=""', { + 'variables': { + 'extra_version_flags': [ + '-f', '<(extra_version_name)', + ], + }, + 'inputs': [ + '<(extra_version_name)' + ], + }], + ], + }, + ], + }, + ], + 'conditions': [ + ['OS=="ios"', { + 'variables': { + # Controls whether the extra version path should be overridden to + # use ios/build/util/CANARY_VERSION (legacy until the bots have + # been updated to override ios_extra_version_path instead). + # TODO(sdefresne): remove once http://crbug.com/514560 is fixed. + 'use_canary_version_file%': 0, + + # Path to the file used to override the version PATH level on iOS. + # Default to ios/build/util/VERSION. + 'ios_extra_version_path%': '../ios/build/util/VERSION', + }, + 'conditions': [ + ['use_canary_version_file==1', { + 'variables': { + 'extra_version_name': '../ios/build/util/CANARY_VERSION', + }, + }, { + 'variables': { + 'extra_version_name': '<(ios_extra_version_path)', + }, + }], + ], + }], + ], +} diff --git a/components/version_info/BUILD.gn b/components/version_info/BUILD.gn new file mode 100644 index 0000000..57c3d09 --- /dev/null +++ b/components/version_info/BUILD.gn @@ -0,0 +1,58 @@ +# Copyright 2015 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import("//chrome/version.gni") + +if (is_ios) { + declare_args() { + # Path to the file used to override the version PATH level on iOS. + # Default to ios/build/util/VERSION. + ios_extra_version_path = "//ios/build/util/VERSION" + + # Controls whether the extra version path should be overridden to + # use ios/build/util/CANARY_VERSION (legacy until the bots have + # been updated to override ios_extra_version_path instead). + # TODO(sdefresne): remove once http://crbug.com/514560 is fixed. + use_canary_version_file = false + } +} + +source_set("version_info") { + sources = [ + "version_info.cc", + "version_info.h", + ] + + deps = [ + "//base", + "//components/strings", + "//ui/base", + ":generate_version_info", + ] +} + +process_version("generate_version_info") { + visibility = [ ":version_info" ] + template_file = "version_info_values.h.version" + output = "$target_gen_dir/version_info_values.h" + + if (is_ios) { + if (use_canary_version_file) { + extra_version_path = "//ios/build/util/CANARY_VERSION" + } else { + extra_version_path = ios_extra_version_path + } + + # iOS overrides PATCH level of the version with the value from the file + # named by ios_version_path, however, this needs to be the last argument + # to the version.py script, so it cannot be added to the source variable + # and instead need to be managed manually. + + inputs += [ extra_version_path ] + extra_args = [ + "-f", + rebase_path(extra_version_path, root_build_dir), + ] + } +} diff --git a/components/version_info/DEPS b/components/version_info/DEPS new file mode 100644 index 0000000..10baa5f --- /dev/null +++ b/components/version_info/DEPS @@ -0,0 +1,7 @@ +include_rules = [ + "+grit/components_strings.h", + "+ui/base", + + # version_info is used on iOS and thus cannot depend on //content. + "-content", +] diff --git a/components/version_info/OWNERS b/components/version_info/OWNERS new file mode 100644 index 0000000..3b572a4 --- /dev/null +++ b/components/version_info/OWNERS @@ -0,0 +1,5 @@ +jochen@chromium.org +jhawkins@chromium.org +sky@chromium.org +thakis@chromium.org +thestig@chromium.org diff --git a/components/version_info/version_info.cc b/components/version_info/version_info.cc new file mode 100644 index 0000000..de3f580 --- /dev/null +++ b/components/version_info/version_info.cc @@ -0,0 +1,100 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/version_info/version_info.h" + +#include "build/build_config.h" +#include "components/version_info/version_info_values.h" +#include "grit/components_strings.h" +#include "ui/base/l10n/l10n_util.h" + +namespace version_info { + +std::string GetProductNameAndVersionForUserAgent() { + return "Chrome/" + GetVersionNumber(); +} + +std::string GetProductName() { + return PRODUCT_NAME; +} + +std::string GetVersionNumber() { + return PRODUCT_VERSION; +} + +std::string GetLastChange() { + return LAST_CHANGE; +} + +bool IsOfficialBuild() { + return IS_OFFICIAL_BUILD; +} + +std::string GetOSType() { +#if defined(OS_WIN) + return "Windows"; +#elif defined(OS_IOS) + return "iOS"; +#elif defined(OS_MACOSX) + return "Mac OS X"; +#elif defined(OS_CHROMEOS) +# if defined(GOOGLE_CHROME_BUILD) + return "Chrome OS"; +# else + return "Chromium OS"; +# endif +#elif defined(OS_ANDROID) + return "Android"; +#elif defined(OS_LINUX) + return "Linux"; +#elif defined(OS_FREEBSD) + return "FreeBSD"; +#elif defined(OS_OPENBSD) + return "OpenBSD"; +#elif defined(OS_SOLARIS) + return "Solaris"; +#else + return "Unknown"; +#endif +} + +std::string GetChannelString(Channel channel) { + switch (channel) { + case Channel::STABLE: + return "stable"; + break; + case Channel::BETA: + return "beta"; + break; + case Channel::DEV: + return "dev"; + break; + case Channel::CANARY: + return "canary"; + break; + case Channel::UNKNOWN: + return "unknown"; + break; + } + return std::string(); +} + +std::string GetVersionStringWithModifier(const std::string& modifier) { + std::string current_version; + current_version += GetVersionNumber(); +#if !defined(GOOGLE_CHROME_BUILD) + current_version += " ("; + current_version += l10n_util::GetStringUTF8(IDS_ABOUT_VERSION_UNOFFICIAL); + current_version += " "; + current_version += GetLastChange(); + current_version += " "; + current_version += GetOSType(); + current_version += ")"; +#endif + if (!modifier.empty()) + current_version += " " + modifier; + return current_version; +} + +} // namespace version_info diff --git a/components/version_info/version_info.h b/components/version_info/version_info.h new file mode 100644 index 0000000..59a074e --- /dev/null +++ b/components/version_info/version_info.h @@ -0,0 +1,48 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_VERSION_INFO_VERSION_INFO_H_ +#define COMPONENTS_VERSION_INFO_VERSION_INFO_H_ + +#include <string> + +namespace version_info { + +// The possible channels for an installation, from most fun to most stable. +enum class Channel { UNKNOWN = 0, CANARY, DEV, BETA, STABLE }; + +// Returns the product name and version information for UserAgent header, +// e.g. "Chrome/a.b.c.d". +std::string GetProductNameAndVersionForUserAgent(); + +// Returns the product name, e.g. "Chromium" or "Google Chrome". +std::string GetProductName(); + +// Returns the version number, e.g. "6.0.490.1". +std::string GetVersionNumber(); + +// Returns a version control specific identifier of this release. +std::string GetLastChange(); + +// Returns whether this is an "official" release of the current version, i.e. +// whether kwnowing GetVersionNumber() is enough to completely determine what +// GetLastChange() is. +bool IsOfficialBuild(); + +// Returns the OS type, e.g. "Windows", "Linux", "FreeBDS", ... +std::string GetOSType(); + +// Returns a string equivalent of |channel|, indenpendent of whether the build +// is branded or not and without any additional modifiers. +std::string GetChannelString(Channel channel); + +// Returns a version string to be displayed in "About Chromium" dialog. +// |modifier| is a string representation of the channel with system specific +// information, e.g. "dev SyzyASan". It is appended to the returned version +// information if non-empty. +std::string GetVersionStringWithModifier(const std::string& modifier); + +} // namespace version_info + +#endif // COMPONENTS_VERSION_INFO_VERSION_INFO_H_ diff --git a/components/version_info/version_info_values.h.version b/components/version_info/version_info_values.h.version new file mode 100644 index 0000000..6232e35 --- /dev/null +++ b/components/version_info/version_info_values.h.version @@ -0,0 +1,13 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_VERSION_INFO_VERSION_INFO_VALUES_H_ +#define COMPONENTS_VERSION_INFO_VERSION_INFO_VALUES_H_ + +#define PRODUCT_NAME "@PRODUCT_FULLNAME@" +#define PRODUCT_VERSION "@MAJOR@.@MINOR@.@BUILD@.@PATCH@" +#define LAST_CHANGE "@LASTCHANGE@" +#define IS_OFFICIAL_BUILD @OFFICIAL_BUILD@ + +#endif // COMPONENTS_VERSION_INFO_VERSION_INFO_VALUES_H_ |