diff options
author | Ryan Mitchell <rtmitchell@google.com> | 2018-04-12 11:51:16 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-04-12 11:51:16 -0700 |
commit | a086da2cd0bd938142e461c8bb46e30fc3474882 (patch) | |
tree | 740f2ad0311b6465041f20d2271844398c6386ab /tools/aapt2/cmd/Compile.cpp | |
parent | f8817064c1a07fcd41110034f56042e5fa5725b4 (diff) | |
parent | 68dc7ca5689b920c97db566387b1423384bb46e6 (diff) |
Merge "AAPT: Multiple period legacy support and errors" into pi-dev am: f845891031
am: 68dc7ca568
Change-Id: I9da94ea0e84ff3caf28597b1038ed6e4ac158280
Diffstat (limited to 'tools/aapt2/cmd/Compile.cpp')
-rw-r--r-- | tools/aapt2/cmd/Compile.cpp | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/tools/aapt2/cmd/Compile.cpp b/tools/aapt2/cmd/Compile.cpp index 1db63350670c..6fe86107d6c0 100644 --- a/tools/aapt2/cmd/Compile.cpp +++ b/tools/aapt2/cmd/Compile.cpp @@ -100,10 +100,20 @@ static Maybe<ResourcePathData> ExtractResourcePathData(const std::string& path, std::string& filename = parts[parts.size() - 1]; StringPiece name = filename; StringPiece extension; - size_t dot_pos = filename.find('.'); - if (dot_pos != std::string::npos) { - extension = name.substr(dot_pos + 1, filename.size() - (dot_pos + 1)); - name = name.substr(0, dot_pos); + + const std::string kNinePng = ".9.png"; + if (filename.size() > kNinePng.size() + && std::equal(kNinePng.rbegin(), kNinePng.rend(), filename.rbegin())) { + // Split on .9.png if this extension is present at the end of the file path + name = name.substr(0, filename.size() - kNinePng.size()); + extension = "9.png"; + } else { + // Split on the last period occurrence + size_t dot_pos = filename.rfind('.'); + if (dot_pos != std::string::npos) { + extension = name.substr(dot_pos + 1, filename.size() - (dot_pos + 1)); + name = name.substr(0, dot_pos); + } } return ResourcePathData{Source(path), dir_str.to_string(), name.to_string(), @@ -799,12 +809,13 @@ int Compile(const std::vector<StringPiece>& args, IDiagnostics* diagnostics) { // We use a different extension (not necessary anymore, but avoids altering the existing // build system logic). path_data.extension = "arsc"; + } else if (const ResourceType* type = ParseResourceType(path_data.resource_dir)) { if (*type != ResourceType::kRaw) { if (path_data.extension == "xml") { compile_func = &CompileXml; - } else if ((!options.no_png_crunch && path_data.extension == "png") || - path_data.extension == "9.png") { + } else if ((!options.no_png_crunch && path_data.extension == "png") + || path_data.extension == "9.png") { compile_func = &CompilePng; } } @@ -815,6 +826,17 @@ int Compile(const std::vector<StringPiece>& args, IDiagnostics* diagnostics) { continue; } + // Treat periods as a reserved character that should not be present in a file name + // Legacy support for AAPT which did not reserve periods + if (compile_func != &CompileFile && !options.legacy_mode + && std::count(path_data.name.begin(), path_data.name.end(), '.') != 0) { + error = true; + context.GetDiagnostics()->Error(DiagMessage() << "resource file '" << path_data.source.path + << "' name cannot contain '.' other than for" + << "specifying the extension"); + continue; + } + // Compile the file. const std::string out_path = BuildIntermediateContainerFilename(path_data); error |= !compile_func(&context, options, path_data, archive_writer.get(), out_path); |