Move version_info into //base
This is a step to move version_info from //components into //base,
which is a dependency of cached feature flags which is also getting
moved to //base.
//components/version_info is left as a facade of //base/version_info.
This CL leaves two copies of Channel.java, one in //components
(copy of the auto-generated) and one in //base (auto-generated),
in order to perform the migration to //base downstream. Soon after,
https://crrev/c/5142488 will delete
//components/version_info/.../Channel.java. I cannot do it on the same
CL because of the Java @interface Channel which cannot easily be made
into a facade. The upstream references are migrated in this same CL.
Bug: 1515661
Change-Id: Ibc4e1ccbd067f71afad793a8b7505797b545337e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5147768
Code-Coverage: [email protected] <[email protected]>
Reviewed-by: Richard (Torne) Coles <[email protected]>
Commit-Queue: Henrique Nakashima <[email protected]>
Reviewed-by: Lei Zhang <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1243557}
diff --git a/components/version_info/BUILD.gn b/components/version_info/BUILD.gn
index 817b82b..786766d 100644
--- a/components/version_info/BUILD.gn
+++ b/components/version_info/BUILD.gn
@@ -2,58 +2,36 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import("//base/version_info/use_unofficial_version_number.gni")
import("//build/config/chrome_build.gni")
-import("//build/util/lastchange.gni")
-import("//build/util/process_version.gni")
-declare_args() {
- use_unofficial_version_number = !is_chrome_branded
-}
-
-static_library("version_info") {
+# Facade for "//base/version_info"
+source_set("version_info") {
sources = [
- "version_info.cc",
"version_info.h",
+ "version_info_values.h",
]
-
- deps = [
- "//base:sanitizer_buildflags",
- "//build:branding_buildflags",
- "//build:chromeos_buildflags",
- ]
-
public_deps = [
":channel",
":generate_version_info",
"//base",
+ "//base/version_info",
]
}
-# Isolate the //ui/base dependency in this target.
-static_library("version_string") {
- sources = [
- "version_string.cc",
- "version_string.h",
- ]
-
- deps = [ ":version_info" ]
-
- if (use_unofficial_version_number) {
- defines = [ "USE_UNOFFICIAL_VERSION_NUMBER" ]
- }
+# Facade for "//base/version_info:version_string"
+source_set("version_string") {
+ sources = [ "version_string.h" ]
+ public_deps = [ "//base/version_info:version_string" ]
}
+# Facade for "//base/version_info:channel"
source_set("channel") {
sources = [ "channel.h" ]
- public_deps = [ "//base" ]
+ public_deps = [ "//base/version_info:channel" ]
}
-process_version("generate_version_info") {
- template_file = "version_info_values.h.version"
- sources = [
- "//chrome/VERSION",
- branding_file_path,
- lastchange_file,
- ]
- output = "$target_gen_dir/version_info_values.h"
+# Facade for "//base/version_info:generate_version_info"
+group("generate_version_info") {
+ public_deps = [ "//base/version_info:generate_version_info" ]
}
diff --git a/components/version_info/android/BUILD.gn b/components/version_info/android/BUILD.gn
index 8b7314f..7a3557e 100644
--- a/components/version_info/android/BUILD.gn
+++ b/components/version_info/android/BUILD.gn
@@ -2,61 +2,19 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import("//build/config/android/channel.gni")
import("//build/config/android/rules.gni")
-import("//build/util/process_version.gni")
-import("//third_party/jni_zero/jni_zero.gni")
-_version_constants_java_file = "$target_gen_dir/java/org/chromium/components/version_info/VersionConstants.java"
-
-# Depend on this on the Java side to get org.components.version_info.Channel and
-# org.components.version_info.VersionConstants.
android_library("version_constants_java") {
sources = [
- "java/src/org/chromium/components/version_info/VersionConstantsBridge.java",
+ "java/src/org/chromium/components/version_info/Channel.java",
+ "java/src/org/chromium/components/version_info/VersionConstants.java",
"java/src/org/chromium/components/version_info/VersionInfo.java",
- _version_constants_java_file,
]
- deps = [
- ":generate_version_constants",
- "//build/android:build_java",
- "//third_party/androidx:androidx_annotation_annotation_java",
- "//third_party/jni_zero:jni_zero_java",
- ]
- srcjar_deps = [ ":channel_enum_srcjar" ]
+ public_deps = [ "//base/version_info/android:version_constants_java" ]
+ deps = [ "//third_party/androidx:androidx_annotation_annotation_java" ]
}
-# Depend on this on the native side to get version_info::GetChannel. It requires
-# version_constants_java for its JNI call.
static_library("channel_getter") {
- sources = [
- "channel_getter.cc",
- "channel_getter.h",
- ]
- deps = [
- ":version_constants_bridge_jni",
- "..:channel",
- "//base", # for jni_generator_helper.h
- ]
-}
-
-java_cpp_enum("channel_enum_srcjar") {
- sources = [ "../channel.h" ]
-}
-
-process_version("generate_version_constants") {
- process_only = true
- template_file = "java/VersionConstants.java.version"
- output = _version_constants_java_file
- sources = [ "//chrome/VERSION" ]
- extra_args = [
- "-e",
- "CHANNEL=str.upper('$android_channel')",
- ]
-}
-
-generate_jni("version_constants_bridge_jni") {
- sources = [
- "java/src/org/chromium/components/version_info/VersionConstantsBridge.java",
- ]
+ sources = [ "channel_getter.h" ]
+ public_deps = [ "//base/version_info/android:channel_getter" ]
}
diff --git a/components/version_info/android/channel_getter.cc b/components/version_info/android/channel_getter.cc
deleted file mode 100644
index 9c7fa37..0000000
--- a/components/version_info/android/channel_getter.cc
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2018 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "components/version_info/android/channel_getter.h"
-
-#include "components/version_info/android/version_constants_bridge_jni/VersionConstantsBridge_jni.h"
-
-namespace version_info {
-namespace android {
-
-Channel GetChannel() {
- JNIEnv* env = base::android::AttachCurrentThread();
- return static_cast<Channel>(Java_VersionConstantsBridge_getChannel(env));
-}
-
-} // namespace android
-} // namespace version_info
diff --git a/components/version_info/android/channel_getter.h b/components/version_info/android/channel_getter.h
index 1e928c7..cda90b2 100644
--- a/components/version_info/android/channel_getter.h
+++ b/components/version_info/android/channel_getter.h
@@ -1,18 +1,10 @@
-// Copyright 2018 The Chromium Authors
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_VERSION_INFO_ANDROID_CHANNEL_GETTER_H_
#define COMPONENTS_VERSION_INFO_ANDROID_CHANNEL_GETTER_H_
-#include "components/version_info/channel.h"
-
-namespace version_info {
-namespace android {
-
-Channel GetChannel();
-
-} // namespace android
-} // namespace version_info
+#include "base/version_info/android/channel_getter.h"
#endif // COMPONENTS_VERSION_INFO_ANDROID_CHANNEL_GETTER_H_
diff --git a/components/version_info/android/java/VersionConstants.java.version b/components/version_info/android/java/VersionConstants.java.version
deleted file mode 100644
index 825eef8..0000000
--- a/components/version_info/android/java/VersionConstants.java.version
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2018 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package org.chromium.components.version_info;
-
-// Constants shared by Android Chrome and WebView. Chrome specific constants are
-// in ChromeVersionConstants.
-public class VersionConstants {
- public static final String PRODUCT_VERSION = "@MAJOR@.@MINOR@.@BUILD@.@PATCH@";
- @SuppressWarnings({"ComplexBooleanConstant", "IdentityBinaryExpression"})
- public static final boolean IS_OFFICIAL_BUILD = @OFFICIAL_BUILD@ == 1;
-
- public static final int PRODUCT_MAJOR_VERSION = @MAJOR@;
- public static final int PRODUCT_BUILD_VERSION = @BUILD@;
-
- public static final int CHANNEL = Channel.@CHANNEL@;
-}
diff --git a/components/version_info/android/java/src/org/chromium/components/version_info/Channel.java b/components/version_info/android/java/src/org/chromium/components/version_info/Channel.java
new file mode 100644
index 0000000..3cf0f51
--- /dev/null
+++ b/components/version_info/android/java/src/org/chromium/components/version_info/Channel.java
@@ -0,0 +1,41 @@
+// Copyright 2024 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// TODO(crbug.com/1515661): Migrate to org.chromium.base.version_info.Channel.
+
+// This file is copied from a file autogenerated by
+// java_cpp_enum.py
+// From
+// ../../components/version_info/channel.h
+
+package org.chromium.components.version_info;
+
+import androidx.annotation.IntDef;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@IntDef({
+ Channel.UNKNOWN,
+ Channel.DEFAULT,
+ Channel.CANARY,
+ Channel.DEV,
+ Channel.BETA,
+ Channel.STABLE
+})
+@Retention(RetentionPolicy.SOURCE)
+public @interface Channel {
+ int UNKNOWN = 0;
+
+ /**
+ * DEFAULT is an alias for UNKNOWN because the build files use DEFAULT but the code uses
+ * UNKNOWN. TODO(paulmiller): Combine DEFAULT & UNKNOWN.
+ */
+ int DEFAULT = UNKNOWN;
+
+ int CANARY = 1;
+ int DEV = 2;
+ int BETA = 3;
+ int STABLE = 4;
+}
diff --git a/components/version_info/android/java/src/org/chromium/components/version_info/VersionConstants.java b/components/version_info/android/java/src/org/chromium/components/version_info/VersionConstants.java
new file mode 100644
index 0000000..003cacd
--- /dev/null
+++ b/components/version_info/android/java/src/org/chromium/components/version_info/VersionConstants.java
@@ -0,0 +1,8 @@
+// Copyright 2018 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.components.version_info;
+
+/** Facade for org.chromium.base.version_info.VersionConstants */
+public class VersionConstants extends org.chromium.base.version_info.VersionConstants {}
diff --git a/components/version_info/android/java/src/org/chromium/components/version_info/VersionConstantsBridge.java b/components/version_info/android/java/src/org/chromium/components/version_info/VersionConstantsBridge.java
deleted file mode 100644
index c57de46..0000000
--- a/components/version_info/android/java/src/org/chromium/components/version_info/VersionConstantsBridge.java
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2018 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package org.chromium.components.version_info;
-
-import org.jni_zero.CalledByNative;
-
-/** Bridge between native and VersionConstants.java. */
-public class VersionConstantsBridge {
- @CalledByNative
- public static int getChannel() {
- return VersionConstants.CHANNEL;
- }
-}
diff --git a/components/version_info/android/java/src/org/chromium/components/version_info/VersionInfo.java b/components/version_info/android/java/src/org/chromium/components/version_info/VersionInfo.java
index 81e6e433..d318c1c 100644
--- a/components/version_info/android/java/src/org/chromium/components/version_info/VersionInfo.java
+++ b/components/version_info/android/java/src/org/chromium/components/version_info/VersionInfo.java
@@ -4,54 +4,5 @@
package org.chromium.components.version_info;
-/**
- * A utility class for querying information about the current Chromium build.
- * Intentionally doesn't depend on native so that the data can be accessed before
- * libchrome.so is loaded.
- */
-public class VersionInfo {
- /** @return Whether this build is a local build. */
- public static boolean isLocalBuild() {
- return VersionConstants.CHANNEL == Channel.DEFAULT;
- }
-
- /** @return Whether this build is a canary build. */
- public static boolean isCanaryBuild() {
- return VersionConstants.CHANNEL == Channel.CANARY;
- }
-
- /** @return Whether this build is a dev build. */
- public static boolean isDevBuild() {
- return VersionConstants.CHANNEL == Channel.DEV;
- }
-
- /** @return Whether this build is a beta build. */
- public static boolean isBetaBuild() {
- return VersionConstants.CHANNEL == Channel.BETA;
- }
-
- /** @return Whether this build is a stable build. */
- public static boolean isStableBuild() {
- return VersionConstants.CHANNEL == Channel.STABLE;
- }
-
- /** @return Whether this is an official (i.e. non-development) build. */
- public static boolean isOfficialBuild() {
- return VersionConstants.IS_OFFICIAL_BUILD;
- }
-
- /** @return The version number. */
- public static String getProductVersion() {
- return VersionConstants.PRODUCT_VERSION;
- }
-
- /** @return The major version number. */
- public static int getProductMajorVersion() {
- return VersionConstants.PRODUCT_MAJOR_VERSION;
- }
-
- /** @return The build number. */
- public static int getBuildVersion() {
- return VersionConstants.PRODUCT_BUILD_VERSION;
- }
-}
+/** Facade for org.chromium.base.version_info.VersionInfo */
+public class VersionInfo extends org.chromium.base.version_info.VersionInfo {}
diff --git a/components/version_info/channel.h b/components/version_info/channel.h
index 714bd7b2..63b53e7 100644
--- a/components/version_info/channel.h
+++ b/components/version_info/channel.h
@@ -5,43 +5,6 @@
#ifndef COMPONENTS_VERSION_INFO_CHANNEL_H_
#define COMPONENTS_VERSION_INFO_CHANNEL_H_
-#include <string_view>
-
-#include "base/notreached.h"
-
-namespace version_info {
-
-// The possible channels for an installation, from most fun to most stable.
-// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.version_info
-enum class Channel {
- UNKNOWN = 0,
- // DEFAULT is an alias for UNKNOWN because the build files use DEFAULT but the
- // code uses UNKNOWN. TODO(paulmiller): Combine DEFAULT & UNKNOWN.
- DEFAULT = UNKNOWN,
- CANARY = 1,
- DEV = 2,
- BETA = 3,
- STABLE = 4,
-};
-
-// Returns a string equivalent of |channel|, independent of whether the build
-// is branded or not and without any additional modifiers.
-constexpr std::string_view GetChannelString(Channel channel) {
- switch (channel) {
- case Channel::STABLE:
- return "stable";
- case Channel::BETA:
- return "beta";
- case Channel::DEV:
- return "dev";
- case Channel::CANARY:
- return "canary";
- case Channel::UNKNOWN:
- return "unknown";
- }
- NOTREACHED_NORETURN();
-}
-
-} // namespace version_info
+#include "base/version_info/channel.h"
#endif // COMPONENTS_VERSION_INFO_CHANNEL_H_
diff --git a/components/version_info/version_info.cc b/components/version_info/version_info.cc
deleted file mode 100644
index 081f81fe..0000000
--- a/components/version_info/version_info.cc
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2015 The Chromium Authors
-// 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 <string>
-
-#include "base/no_destructor.h"
-#include "base/strings/strcat.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/version.h"
-
-namespace version_info {
-
-const std::string GetProductNameAndVersionForReducedUserAgent(
- const std::string& build_version) {
- return base::StrCat(
- {"Chrome/", GetMajorVersionNumber(), ".0.", build_version, ".0"});
-}
-
-int GetMajorVersionNumberAsInt() {
- DCHECK(GetVersion().IsValid());
- return GetVersion().components()[0];
-}
-
-std::string GetMajorVersionNumber() {
- return base::NumberToString(GetMajorVersionNumberAsInt());
-}
-
-const base::Version& GetVersion() {
- static const base::NoDestructor<base::Version> version(GetVersionNumber());
- return *version;
-}
-
-} // namespace version_info
diff --git a/components/version_info/version_info.h b/components/version_info/version_info.h
index 95786e3..3a129457 100644
--- a/components/version_info/version_info.h
+++ b/components/version_info/version_info.h
@@ -5,120 +5,6 @@
#ifndef COMPONENTS_VERSION_INFO_VERSION_INFO_H_
#define COMPONENTS_VERSION_INFO_VERSION_INFO_H_
-#include <string>
-
-#include "base/sanitizer_buildflags.h"
-#include "base/strings/string_piece.h"
-#include "build/branding_buildflags.h"
-#include "build/build_config.h"
-#include "components/version_info/channel.h"
-#include "components/version_info/version_info_values.h"
-
-namespace base {
-class Version;
-}
-
-namespace version_info {
-
-// Returns the product name and reduced version information for the User-Agent
-// header, in the format: Chrome/<major_version>.0.build_version.0, where
-// `build_version` is a frozen BUILD number.
-const std::string GetProductNameAndVersionForReducedUserAgent(
- const std::string& build_version);
-
-// Returns the product name, e.g. "Chromium" or "Google Chrome".
-constexpr base::StringPiece GetProductName() {
- return PRODUCT_NAME;
-}
-
-// Returns the version number, e.g. "6.0.490.1".
-constexpr base::StringPiece GetVersionNumber() {
- return PRODUCT_VERSION;
-}
-
-// Returns the product name and version information for the User-Agent header,
-// in the format: Chrome/<major_version>.<minor_version>.<build>.<patch>.
-constexpr base::StringPiece GetProductNameAndVersionForUserAgent() {
- return "Chrome/" PRODUCT_VERSION;
-}
-
-// Returns the major component (aka the milestone) of the version as an int,
-// e.g. 6 when the version is "6.0.490.1".
-int GetMajorVersionNumberAsInt();
-
-// Like GetMajorVersionNumberAsInt(), but returns a string.
-std::string GetMajorVersionNumber();
-
-// Returns the result of GetVersionNumber() as a base::Version.
-const base::Version& GetVersion();
-
-// Returns a version control specific identifier of this release.
-constexpr base::StringPiece GetLastChange() {
- return LAST_CHANGE;
-}
-
-// Returns whether this is an "official" release of the current version, i.e.
-// whether knowing GetVersionNumber() is enough to completely determine what
-// GetLastChange() is.
-constexpr bool IsOfficialBuild() {
- return IS_OFFICIAL_BUILD;
-}
-
-// Returns the OS type, e.g. "Windows", "Linux", "FreeBSD", ...
-constexpr base::StringPiece GetOSType() {
-#if BUILDFLAG(IS_WIN)
- return "Windows";
-#elif BUILDFLAG(IS_IOS)
- return "iOS";
-#elif BUILDFLAG(IS_MAC)
- return "Mac OS X";
-#elif BUILDFLAG(IS_CHROMEOS)
-#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
- return "ChromeOS";
-#else
- return "ChromiumOS";
-#endif
-#elif BUILDFLAG(IS_ANDROID)
- return "Android";
-#elif BUILDFLAG(IS_LINUX)
- return "Linux";
-#elif BUILDFLAG(IS_FREEBSD)
- return "FreeBSD";
-#elif BUILDFLAG(IS_OPENBSD)
- return "OpenBSD";
-#elif BUILDFLAG(IS_SOLARIS)
- return "Solaris";
-#elif BUILDFLAG(IS_FUCHSIA)
- return "Fuchsia";
-#else
- return "Unknown";
-#endif
-}
-
-// Returns a list of sanitizers enabled in this build.
-constexpr base::StringPiece GetSanitizerList() {
- return ""
-#if defined(ADDRESS_SANITIZER)
- "address "
-#endif
-#if BUILDFLAG(IS_HWASAN)
- "hwaddress "
-#endif
-#if defined(LEAK_SANITIZER)
- "leak "
-#endif
-#if defined(MEMORY_SANITIZER)
- "memory "
-#endif
-#if defined(THREAD_SANITIZER)
- "thread "
-#endif
-#if defined(UNDEFINED_SANITIZER)
- "undefined "
-#endif
- ;
-}
-
-} // namespace version_info
+#include "base/version_info/version_info.h"
#endif // COMPONENTS_VERSION_INFO_VERSION_INFO_H_
diff --git a/components/version_info/version_info_values.h b/components/version_info/version_info_values.h
new file mode 100644
index 0000000..535b074
--- /dev/null
+++ b/components/version_info/version_info_values.h
@@ -0,0 +1,10 @@
+// Copyright 2023 The Chromium Authors
+// 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_
+
+#include "base/version_info/version_info_values.h"
+
+#endif // COMPONENTS_VERSION_INFO_VERSION_INFO_VALUES_H_
diff --git a/components/version_info/version_info_values.h.version b/components/version_info/version_info_values.h.version
deleted file mode 100644
index 05c4463..0000000
--- a/components/version_info/version_info_values.h.version
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright 2010 The Chromium Authors
-// 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_
diff --git a/components/version_info/version_string.cc b/components/version_info/version_string.cc
deleted file mode 100644
index a185398..0000000
--- a/components/version_info/version_string.cc
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2017 The Chromium Authors
-// 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_string.h"
-
-#include "components/version_info/version_info.h"
-
-namespace version_info {
-
-std::string GetVersionStringWithModifier(const std::string& modifier) {
- std::string current_version;
- current_version += GetVersionNumber();
-#if defined(USE_UNOFFICIAL_VERSION_NUMBER)
- current_version += " (Developer Build ";
- current_version += GetLastChange();
- current_version += " ";
- current_version += GetOSType();
- current_version += ")";
-#endif // USE_UNOFFICIAL_VERSION_NUMBER
- if (!modifier.empty())
- current_version += " " + modifier;
- return current_version;
-}
-
-} // namespace version_info
diff --git a/components/version_info/version_string.h b/components/version_info/version_string.h
index 38a2e60..7d7bb3b 100644
--- a/components/version_info/version_string.h
+++ b/components/version_info/version_string.h
@@ -5,16 +5,6 @@
#ifndef COMPONENTS_VERSION_INFO_VERSION_STRING_H_
#define COMPONENTS_VERSION_INFO_VERSION_STRING_H_
-#include <string>
-
-namespace version_info {
-
-// 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
+#include "base/version_info/version_string.h"
#endif // COMPONENTS_VERSION_INFO_VERSION_STRING_H_