Skip to content

Commit

Permalink
Fix ijar failing on empty jars.
Browse files Browse the repository at this point in the history
The problem happens when all the files are filtered out. In such case a dummy file is created, but not accounted for in the size estimation.
Fixes bazelbuild#10162
  • Loading branch information
comius committed Jan 25, 2021
1 parent 0898a2a commit 952c34f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions third_party/ijar/ijar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const char *TARGET_LABEL_KEY = "Target-Label: ";
const size_t TARGET_LABEL_KEY_LENGTH = strlen(TARGET_LABEL_KEY);
const char *INJECTING_RULE_KIND_KEY = "Injecting-Rule-Kind: ";
const size_t INJECTING_RULE_KIND_KEY_LENGTH = strlen(INJECTING_RULE_KIND_KEY);
const char *DUMMY_FILE = "dummy";
const size_t DUMMY_PATH_LENGTH = strlen(DUMMY_FILE);

class JarExtractorProcessor : public ZipExtractorProcessor {
public:
Expand Down Expand Up @@ -369,7 +371,7 @@ static void OpenFilesAndProcessJar(const char *file_out, const char *file_in,
abort();
}
u8 output_length =
in->CalculateOutputLength() +
std::max(in->CalculateOutputLength(), 103ull + DUMMY_PATH_LENGTH) +
EstimateManifestOutputSize(target_label, injecting_rule_kind);
std::unique_ptr<ZipBuilder> out(ZipBuilder::Create(file_out, output_length));
if (out == NULL) {
Expand All @@ -388,7 +390,7 @@ static void OpenFilesAndProcessJar(const char *file_out, const char *file_in,

// Add dummy file, since javac doesn't like truly empty jars.
if (out->GetNumberFiles() == 0) {
out->WriteEmptyFile("dummy");
out->WriteEmptyFile(DUMMY_FILE);
}
// Finish writing the output file
if (out->Finish() < 0) {
Expand Down

0 comments on commit 952c34f

Please sign in to comment.