update_engine: Use the bsdiff library instead of its executable am: 71be9371f2 am: 0a31628e70
am: aa7ae9f9a4
Change-Id: I1680b7652392acdf18290abfc89636536bca24e8
diff --git a/Android.mk b/Android.mk
index 5acedc9..56456ee 100644
--- a/Android.mk
+++ b/Android.mk
@@ -590,9 +590,10 @@
# server-side code. This is used for delta_generator and unittests but not
# for any client code.
ue_libpayload_generator_exported_static_libraries := \
+ libbsdiff \
libpayload_consumer \
- update_metadata-protos \
liblzma \
+ update_metadata-protos \
$(ue_libpayload_consumer_exported_static_libraries) \
$(ue_update_metadata_protos_exported_static_libraries)
ue_libpayload_generator_exported_shared_libraries := \
@@ -636,9 +637,10 @@
LOCAL_LDFLAGS := $(ue_common_ldflags)
LOCAL_C_INCLUDES := $(ue_common_c_includes)
LOCAL_STATIC_LIBRARIES := \
+ libbsdiff \
libpayload_consumer \
- update_metadata-protos \
liblzma \
+ update_metadata-protos \
$(ue_common_static_libraries) \
$(ue_libpayload_consumer_exported_static_libraries) \
$(ue_update_metadata_protos_exported_static_libraries)
@@ -685,8 +687,6 @@
# Build for the host.
include $(CLEAR_VARS)
LOCAL_MODULE := delta_generator
-LOCAL_REQUIRED_MODULES := \
- bsdiff
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_CPP_EXTENSION := .cc
LOCAL_CFLAGS := $(ue_common_cflags)
@@ -826,28 +826,6 @@
test_http_server.cc
include $(BUILD_EXECUTABLE)
-# bsdiff (type: executable)
-# ========================================================
-# We need bsdiff in the update_engine_unittests directory, so we build it here.
-include $(CLEAR_VARS)
-LOCAL_MODULE := ue_unittest_bsdiff
-LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_NATIVE_TESTS)/update_engine_unittests
-LOCAL_MODULE_STEM := bsdiff
-LOCAL_CPP_EXTENSION := .cc
-LOCAL_SRC_FILES := ../../external/bsdiff/bsdiff_main.cc
-LOCAL_CFLAGS := \
- -D_FILE_OFFSET_BITS=64 \
- -Wall \
- -Werror \
- -Wextra \
- -Wno-unused-parameter
-LOCAL_STATIC_LIBRARIES := \
- libbsdiff \
- libbz \
- libdivsufsort64 \
- libdivsufsort
-include $(BUILD_EXECUTABLE)
-
# test_subprocess (type: executable)
# ========================================================
# Test helper subprocess program.
@@ -873,7 +851,6 @@
LOCAL_REQUIRED_MODULES := \
test_http_server \
test_subprocess \
- ue_unittest_bsdiff \
ue_unittest_delta_generator \
ue_unittest_disk_ext2_1k.img \
ue_unittest_disk_ext2_4k.img \
diff --git a/payload_generator/delta_diff_utils.cc b/payload_generator/delta_diff_utils.cc
index b013bfa..1664960 100644
--- a/payload_generator/delta_diff_utils.cc
+++ b/payload_generator/delta_diff_utils.cc
@@ -32,6 +32,7 @@
#include <base/strings/stringprintf.h>
#include <base/threading/simple_thread.h>
#include <brillo/data_encoding.h>
+#include <bsdiff/bsdiff.h>
#include "update_engine/common/hash_calculator.h"
#include "update_engine/common/subprocess.h"
@@ -50,8 +51,6 @@
namespace chromeos_update_engine {
namespace {
-const char* const kBsdiffPath = "bsdiff";
-
// The maximum destination size allowed for bsdiff. In general, bsdiff should
// work for arbitrary big files, but the payload generation and payload
// application requires a significant amount of RAM. We put a hard-limit of
@@ -701,24 +700,21 @@
? InstallOperation::SOURCE_COPY
: InstallOperation::MOVE);
data_blob = brillo::Blob();
- } else if (bsdiff_allowed || puffdiff_allowed) {
- // If the source file is considered bsdiff safe (no bsdiff bugs
- // triggered), see if BSDIFF encoding is smaller.
- base::FilePath old_chunk;
- TEST_AND_RETURN_FALSE(base::CreateTemporaryFile(&old_chunk));
- ScopedPathUnlinker old_unlinker(old_chunk.value());
- TEST_AND_RETURN_FALSE(utils::WriteFile(
- old_chunk.value().c_str(), old_data.data(), old_data.size()));
- base::FilePath new_chunk;
- TEST_AND_RETURN_FALSE(base::CreateTemporaryFile(&new_chunk));
- ScopedPathUnlinker new_unlinker(new_chunk.value());
- TEST_AND_RETURN_FALSE(utils::WriteFile(
- new_chunk.value().c_str(), new_data.data(), new_data.size()));
-
+ } else {
if (bsdiff_allowed) {
+ base::FilePath patch;
+ TEST_AND_RETURN_FALSE(base::CreateTemporaryFile(&patch));
+ ScopedPathUnlinker unlinker(patch.value());
+
brillo::Blob bsdiff_delta;
- TEST_AND_RETURN_FALSE(DiffFiles(
- kBsdiffPath, old_chunk.value(), new_chunk.value(), &bsdiff_delta));
+ TEST_AND_RETURN_FALSE(0 == bsdiff::bsdiff(old_data.data(),
+ old_data.size(),
+ new_data.data(),
+ new_data.size(),
+ patch.value().c_str(),
+ nullptr));
+
+ TEST_AND_RETURN_FALSE(utils::ReadFile(patch.value(), &bsdiff_delta));
CHECK_GT(bsdiff_delta.size(), static_cast<brillo::Blob::size_type>(0));
if (bsdiff_delta.size() < data_blob.size()) {
operation.set_type(
@@ -760,36 +756,6 @@
return true;
}
-// Runs the bsdiff tool in |diff_path| on two files and returns the
-// resulting delta in |out|. Returns true on success.
-bool DiffFiles(const string& diff_path,
- const string& old_file,
- const string& new_file,
- brillo::Blob* out) {
- const string kPatchFile = "delta.patchXXXXXX";
- string patch_file_path;
-
- TEST_AND_RETURN_FALSE(
- utils::MakeTempFile(kPatchFile, &patch_file_path, nullptr));
-
- vector<string> cmd;
- cmd.push_back(diff_path);
- cmd.push_back(old_file);
- cmd.push_back(new_file);
- cmd.push_back(patch_file_path);
-
- int rc = 1;
- string stdout;
- TEST_AND_RETURN_FALSE(Subprocess::SynchronousExec(cmd, &rc, &stdout));
- if (rc != 0) {
- LOG(ERROR) << diff_path << " returned " << rc << std::endl << stdout;
- return false;
- }
- TEST_AND_RETURN_FALSE(utils::ReadFile(patch_file_path, out));
- unlink(patch_file_path.c_str());
- return true;
-}
-
bool IsAReplaceOperation(InstallOperation_Type op_type) {
return (op_type == InstallOperation::REPLACE ||
op_type == InstallOperation::REPLACE_BZ ||
diff --git a/payload_generator/delta_diff_utils.h b/payload_generator/delta_diff_utils.h
index b4f3fc0..2d49459 100644
--- a/payload_generator/delta_diff_utils.h
+++ b/payload_generator/delta_diff_utils.h
@@ -103,13 +103,6 @@
brillo::Blob* out_data,
InstallOperation* out_op);
-// Runs the bsdiff tool in |diff_path| on two files and returns the
-// resulting delta in |out|. Returns true on success.
-bool DiffFiles(const std::string& diff_path,
- const std::string& old_file,
- const std::string& new_file,
- brillo::Blob* out);
-
// Generates the best allowed full operation to produce |new_data|. The allowed
// operations are based on |payload_version|. The operation blob will be stored
// in |out_blob| and the resulting operation type in |out_type|. Returns whether
diff --git a/update_engine.gyp b/update_engine.gyp
index 152bcaa..f3b199e 100644
--- a/update_engine.gyp
+++ b/update_engine.gyp
@@ -384,6 +384,9 @@
'<@(exported_deps)',
],
},
+ 'libraries': [
+ '-lbsdiff',
+ ],
},
'sources': [
'payload_generator/ab_generator.cc',