Commit 5210afae authored by Adenilson Cavalcanti's avatar Adenilson Cavalcanti Committed by Commit Bot

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.

Bug: 1076580, 1087999
Change-Id: I3130ba77681ae66dc34c3539c2ed10476e754d86
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2211008
Commit-Queue: Adenilson Cavalcanti <cavalcantii@chromium.org>
Reviewed-by: default avatarAdenilson Cavalcanti <cavalcantii@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773937}
parent 382a4f17
......@@ -322,6 +322,11 @@ group("gn_all") {
deps += [ "//chrome/installer/gcapi_mac:gcapi_example" ]
}
# Allow building md5sum tool for other OSes.
if (!is_android) {
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
......
# 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"
}
}
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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment