diff options
author | Samuel Huang <huangs@chromium.org> | 2018-04-30 22:47:52 +0000 |
---|---|---|
committer | Edward Lesmes <ehmaldonado@google.com> | 2021-07-23 22:17:29 +0000 |
commit | 6951a286379338eaa10a712989541ca77c0c2a9c (patch) | |
tree | 2b4b9f8addfe9aa37804bb52929a235a10b23239 /zucchini_commands.cc | |
parent | 93ffc913ec7d369818a109b9ca6de7adb278e163 (diff) | |
download | zucchini-6951a286379338eaa10a712989541ca77c0c2a9c.tar.gz |
[Zucchini] Introduce Imposed Ensemble Matcher.
Previously Zucchini-gen uses built-in heuristics to perform element
matching for ensemble patch generation. This CL adds an option
(accessible via the -impose parameter) to specify elements in "old"
and "new", and how they match. This allows the default heuristics to be
overridden, and enables external applications (who perhaps have better
ideas of element matching, e.g., have access to archiving programs) to
better use Zucchini to patch archives.
Zucchini-match is updated to prints the -impose command line to repeat
its results. Also, ElementMatch::ToString() is added.
Change-Id: I541b64722904c2fcd19ed75246d87e0268fbf86c
Reviewed-on: https://chromium-review.googlesource.com/1027191
Reviewed-by: Samuel Huang <huangs@chromium.org>
Reviewed-by: Greg Thompson <grt@chromium.org>
Commit-Queue: Samuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#554909}
NOKEYCHECK=True
GitOrigin-RevId: 73a64ffde3f3b64df576aa1f2b5baebf7ec964ba
Diffstat (limited to 'zucchini_commands.cc')
-rw-r--r-- | zucchini_commands.cc | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/zucchini_commands.cc b/zucchini_commands.cc index 2d4b156..62dd20d 100644 --- a/zucchini_commands.cc +++ b/zucchini_commands.cc @@ -8,6 +8,7 @@ #include <stdint.h> #include <ostream> +#include <string> #include <utility> #include "base/command_line.h" @@ -29,6 +30,7 @@ namespace { /******** Command-line Switches ********/ constexpr char kSwitchDump[] = "dump"; +constexpr char kSwitchImpose[] = "impose"; constexpr char kSwitchKeep[] = "keep"; constexpr char kSwitchRaw[] = "raw"; @@ -56,11 +58,18 @@ zucchini::status::Code MainGen(MainParams params) { zucchini::EnsemblePatchWriter patch_writer(old_image.region(), new_image.region()); - auto generate = params.command_line.HasSwitch(kSwitchRaw) - ? zucchini::GenerateRaw - : zucchini::GenerateEnsemble; - zucchini::status::Code result = - generate(old_image.region(), new_image.region(), &patch_writer); + zucchini::status::Code result = zucchini::status::kStatusSuccess; + if (params.command_line.HasSwitch(kSwitchRaw)) { + result = GenerateRaw(old_image.region(), new_image.region(), &patch_writer); + } else { + // May be empty. + std::string imposed_matches = + params.command_line.GetSwitchValueASCII(kSwitchImpose); + result = GenerateEnsembleWithImposedMatches( + old_image.region(), new_image.region(), std::move(imposed_matches), + &patch_writer); + } + if (result != zucchini::status::kStatusSuccess) { params.out << "Fatal error encountered when generating patch." << std::endl; return result; @@ -154,9 +163,13 @@ zucchini::status::Code MainMatch(MainParams params) { << new_image.error(); return zucchini::status::kStatusFileReadError; } + + std::string imposed_matches = + params.command_line.GetSwitchValueASCII(kSwitchImpose); zucchini::status::Code status = zucchini::MatchAll({old_image.data(), old_image.length()}, - {new_image.data(), new_image.length()}, params.out); + {new_image.data(), new_image.length()}, + std::move(imposed_matches), params.out); if (status != zucchini::status::kStatusSuccess) params.err << "Fatal error found when matching executables." << std::endl; return status; |