0

Re-Re-land migrate md5sum tool to portable zlib utils

Use the set of portable code from zlib that shouldn't have
extra dependencies (e.g. 'base').

Also allow building the tool for other targets (e.g. Linux,
OSX, etc) as that allows easier testing and profiling.

Compilation is disabled for Windows, see crbug.com/1090428.

Bug: 1076580, 1087999
Change-Id: Id633b5aa287cd6b24c72af51a23c73d50617c68b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2227312
Reviewed-by: Mirko Bonadei <mbonadei@chromium.org>
Reviewed-by: Adenilson Cavalcanti <cavalcantii@chromium.org>
Reviewed-by: David Turner <digit@chromium.org>
Reviewed-by: Takuto Ikuta <tikuta@chromium.org>
Commit-Queue: Mirko Bonadei <mbonadei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774555}
This commit is contained in:
Adenilson Cavalcanti
2020-06-03 09:32:10 +00:00
committed by Commit Bot
parent b36df818b1
commit 3d10c9b5eb
6 changed files with 74 additions and 32 deletions

@ -322,6 +322,13 @@ group("gn_all") {
deps += [ "//chrome/installer/gcapi_mac:gcapi_example" ]
}
# Allow building md5sum tool for other OSes (android is added below).
# For Windows, see: crbug.com/1090428.
# TODO(cavalcantii): move it out of 'android' folder.
if (!is_win) {
deps += [ "//tools/android/md5sum" ]
}
if (is_android) {
deps += [
"//base:base_junit_tests",

@ -35,6 +35,15 @@ if (build_with_chromium) {
}
}
# It seems that Fuchsia bot will fail to build if we don't explicitly
# add this config as part of utils_portable.
config("zlib_portable_utils_config") {
include_dirs = [
"//third_party/zlib",
"//third_party/zlib/google",
]
}
# This allows other users of Chromium's zlib library, but don't use Chromium's
# //base, to reuse some boilerplate code.
static_library("compression_utils_portable") {
@ -43,4 +52,5 @@ static_library("compression_utils_portable") {
"compression_utils_portable.h",
]
deps = [ "//third_party/zlib" ]
public_configs = [ ":zlib_portable_utils_config" ]
}

@ -14,6 +14,7 @@
*/
#if defined(USE_SYSTEM_ZLIB)
#include <zlib.h>
/* AOSP build requires relative paths. */
#else
#include "zlib.h"
#endif

@ -1,39 +1,49 @@
# Copyright 2014 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.
if (current_cpu == "arm" || current_cpu == "arm64") {
import("//build/config/arm.gni")
}
import("//build/config/android/config.gni")
import("//build/symlink.gni")
if (is_android) {
import("//build/config/android/config.gni")
import("//build/symlink.gni")
group("md5sum") {
data_deps = [
":md5sum_bin_host($default_toolchain)",
":md5sum_prepare_dist($default_toolchain)",
]
group("md5sum") {
data_deps = [
":md5sum_bin_host($default_toolchain)",
":md5sum_prepare_dist($default_toolchain)",
]
# TODO(cjhopman): Remove once group data_deps are fixed.
deps = data_deps
# TODO(cjhopman): Remove once group data_deps are fixed.
deps = data_deps
}
if (current_toolchain == default_toolchain) {
import("//build/config/android/rules.gni")
create_native_executable_dist("md5sum_prepare_dist") {
dist_dir = "$root_build_dir/md5sum_dist"
binary = "$root_build_dir/md5sum_bin"
deps = [ ":md5sum_bin" ]
}
binary_symlink("md5sum_bin_host") {
binary_label = ":md5sum_bin($host_toolchain)"
output_name = "md5sum_bin_host"
}
}
} else {
# We don't need all that stuff for other OSes.
group("md5sum") {
data_deps = []
}
}
executable("md5sum_bin") {
sources = [ "md5sum.cc" ]
deps = [
"//base",
"//third_party/zlib/google:compression_utils",
"//third_party/zlib/google:compression_utils_portable",
]
}
if (current_toolchain == default_toolchain) {
import("//build/config/android/rules.gni")
create_native_executable_dist("md5sum_prepare_dist") {
dist_dir = "$root_build_dir/md5sum_dist"
binary = "$root_build_dir/md5sum_bin"
deps = [ ":md5sum_bin" ]
}
binary_symlink("md5sum_bin_host") {
binary_label = ":md5sum_bin($host_toolchain)"
output_name = "md5sum_bin_host"
}
}

@ -1,3 +1,3 @@
include_rules = [
"+third_party/zlib/google/compression_utils.h",
"+third_party/zlib/google/compression_utils_portable.h",
]

@ -22,7 +22,7 @@
#include "base/logging.h"
#include "base/strings/string_split.h"
#include "third_party/zlib/google/compression_utils.h"
#include "third_party/zlib/google/compression_utils_portable.h"
namespace {
@ -82,12 +82,26 @@ std::vector<std::string> MakeFileSet(const char** files) {
std::vector<std::string> MakeFileListFromCompressedList(const char* data) {
std::vector<std::string> file_list;
std::string gzipdata;
// Expected compressed input is using Base64 encoding, we got convert it
// to a regular string before passing it to zlib.
base::Base64Decode(base::StringPiece(data), &gzipdata);
std::string output;
compression::GzipUncompress(gzipdata, &output);
for (const auto& file :
base::SplitStringPiece(output, kFilePathDelimiter, base::KEEP_WHITESPACE,
base::SPLIT_WANT_NONEMPTY)) {
size_t compressed_size = gzipdata.size();
unsigned long decompressed_size = zlib_internal::GetGzipUncompressedSize(
reinterpret_cast<const Bytef*>(gzipdata.c_str()), compressed_size);
std::string decompressed(decompressed_size, '#');
// We can skip an extraneous copy by relying on a C++11 std::string guarantee
// of contiguous memory access to a string.
zlib_internal::UncompressHelper(
zlib_internal::WrapperType::GZIP,
reinterpret_cast<unsigned char*>(&decompressed[0]), &decompressed_size,
reinterpret_cast<const unsigned char*>(gzipdata.c_str()),
compressed_size);
for (const auto& file : base::SplitStringPiece(
decompressed, kFilePathDelimiter, base::KEEP_WHITESPACE,
base::SPLIT_WANT_NONEMPTY)) {
file_list.push_back(file.as_string());
}
return file_list;