Commit 00c7f91f authored by Adenilson Cavalcanti's avatar Adenilson Cavalcanti Committed by Commit Bot

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: Ic036685029be99b06753ea18f9fc62ce7c1a6540
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2225526Reviewed-by: default avatarTao Bai <michaelbai@chromium.org>
Reviewed-by: default avatarAdenilson Cavalcanti <cavalcantii@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Commit-Queue: Adenilson Cavalcanti <cavalcantii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774325}
parent 1af6c5b4
...@@ -322,6 +322,12 @@ group("gn_all") { ...@@ -322,6 +322,12 @@ group("gn_all") {
deps += [ "//chrome/installer/gcapi_mac:gcapi_example" ] deps += [ "//chrome/installer/gcapi_mac:gcapi_example" ]
} }
# Allow building md5sum tool for other OSes (android is added below).
# For Windows, see: crbug.com/1090428.
if (!is_android || !is_win) {
deps += [ "//tools/android/md5sum" ]
}
if (is_android) { if (is_android) {
deps += [ deps += [
"//base:base_junit_tests", "//base:base_junit_tests",
......
...@@ -35,6 +35,15 @@ if (build_with_chromium) { ...@@ -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 # This allows other users of Chromium's zlib library, but don't use Chromium's
# //base, to reuse some boilerplate code. # //base, to reuse some boilerplate code.
static_library("compression_utils_portable") { static_library("compression_utils_portable") {
...@@ -43,4 +52,5 @@ static_library("compression_utils_portable") { ...@@ -43,4 +52,5 @@ static_library("compression_utils_portable") {
"compression_utils_portable.h", "compression_utils_portable.h",
] ]
deps = [ "//third_party/zlib" ] deps = [ "//third_party/zlib" ]
public_configs = [ ":zlib_portable_utils_config" ]
} }
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
#if defined(USE_SYSTEM_ZLIB) #if defined(USE_SYSTEM_ZLIB)
#include <zlib.h> #include <zlib.h>
/* AOSP build requires relative paths. */
#else #else
#include "zlib.h" #include "zlib.h"
#endif #endif
......
# Copyright 2014 The Chromium Authors. All rights reserved. # Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
if (current_cpu == "arm" || current_cpu == "arm64") {
import("//build/config/arm.gni")
}
import("//build/config/android/config.gni") if (is_android) {
import("//build/symlink.gni") import("//build/config/android/config.gni")
import("//build/symlink.gni")
group("md5sum") { group("md5sum") {
data_deps = [ data_deps = [
":md5sum_bin_host($default_toolchain)", ":md5sum_bin_host($default_toolchain)",
":md5sum_prepare_dist($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. if (current_toolchain == default_toolchain) {
deps = data_deps 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") { executable("md5sum_bin") {
sources = [ "md5sum.cc" ] sources = [ "md5sum.cc" ]
deps = [ deps = [
"//base", "//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 = [ include_rules = [
"+third_party/zlib/google/compression_utils.h", "+third_party/zlib/google/compression_utils_portable.h",
] ]
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_split.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 { namespace {
...@@ -82,12 +82,26 @@ std::vector<std::string> MakeFileSet(const char** files) { ...@@ -82,12 +82,26 @@ std::vector<std::string> MakeFileSet(const char** files) {
std::vector<std::string> MakeFileListFromCompressedList(const char* data) { std::vector<std::string> MakeFileListFromCompressedList(const char* data) {
std::vector<std::string> file_list; std::vector<std::string> file_list;
std::string gzipdata; 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); base::Base64Decode(base::StringPiece(data), &gzipdata);
std::string output;
compression::GzipUncompress(gzipdata, &output); size_t compressed_size = gzipdata.size();
for (const auto& file : unsigned long decompressed_size = zlib_internal::GetGzipUncompressedSize(
base::SplitStringPiece(output, kFilePathDelimiter, base::KEEP_WHITESPACE, reinterpret_cast<const Bytef*>(gzipdata.c_str()), compressed_size);
base::SPLIT_WANT_NONEMPTY)) { 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()); file_list.push_back(file.as_string());
} }
return file_list; 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