From c7db244cbe45678a281544c3a0f267d7c234d849 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Wed, 28 Aug 2019 11:21:47 -0700 Subject: [PATCH] Allow compile output to be either a zip or dir When passing a directory to compile using --zip or --dir, the -o flag had to represent a zip file the compiled contents would be written to. Now, if the path specified by the -o flag is a directory, the compiled files will be written to the directory rather than erroring out. Also when passing files to compile as file arguments, the -o flag had to represent an existing directory. Now, if the path is not an existing directory, the compiled files will create a zip file at the path that contains the compiled files. Test: manual Change-Id: I92a8e124d53cdb653eb3a7ec549f09f9ad0ef04f --- tools/aapt2/cmd/Compile.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/aapt2/cmd/Compile.cpp b/tools/aapt2/cmd/Compile.cpp index c7ac438dacfbf..d50b1de335fb3 100644 --- a/tools/aapt2/cmd/Compile.cpp +++ b/tools/aapt2/cmd/Compile.cpp @@ -740,7 +740,6 @@ int CompileCommand::Action(const std::vector& args) { } std::unique_ptr file_collection; - std::unique_ptr archive_writer; // Collect the resources files to compile if (options_.res_dir && options_.res_zip) { @@ -761,8 +760,6 @@ int CompileCommand::Action(const std::vector& args) { context.GetDiagnostics()->Error(DiagMessage(options_.res_dir.value()) << err); return 1; } - - archive_writer = CreateZipFileArchiveWriter(context.GetDiagnostics(), options_.output_path); } else if (options_.res_zip) { if (!args.empty()) { context.GetDiagnostics()->Error(DiagMessage() << "files given but --zip specified"); @@ -777,8 +774,6 @@ int CompileCommand::Action(const std::vector& args) { context.GetDiagnostics()->Error(DiagMessage(options_.res_zip.value()) << err); return 1; } - - archive_writer = CreateZipFileArchiveWriter(context.GetDiagnostics(), options_.output_path); } else { auto collection = util::make_unique(); @@ -791,7 +786,14 @@ int CompileCommand::Action(const std::vector& args) { } file_collection = std::move(collection); + } + + std::unique_ptr archive_writer; + file::FileType output_file_type = file::GetFileType(options_.output_path); + if (output_file_type == file::FileType::kDirectory) { archive_writer = CreateDirectoryArchiveWriter(context.GetDiagnostics(), options_.output_path); + } else { + archive_writer = CreateZipFileArchiveWriter(context.GetDiagnostics(), options_.output_path); } if (!archive_writer) {