2014-11-14 14:48:12 -08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef AAPT_FILES_H
|
|
|
|
#define AAPT_FILES_H
|
|
|
|
|
2016-10-21 17:56:45 -07:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "android-base/macros.h"
|
|
|
|
#include "utils/FileMap.h"
|
|
|
|
|
2015-08-14 14:26:04 -07:00
|
|
|
#include "Diagnostics.h"
|
|
|
|
#include "Maybe.h"
|
2014-11-14 14:48:12 -08:00
|
|
|
#include "Source.h"
|
2015-08-14 14:26:04 -07:00
|
|
|
#include "util/StringPiece.h"
|
|
|
|
|
2014-11-14 14:48:12 -08:00
|
|
|
namespace aapt {
|
2015-08-14 14:26:04 -07:00
|
|
|
namespace file {
|
2014-11-14 14:48:12 -08:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
constexpr const char sDirSep = '\\';
|
|
|
|
#else
|
|
|
|
constexpr const char sDirSep = '/';
|
|
|
|
#endif
|
|
|
|
|
|
|
|
enum class FileType {
|
2016-10-19 12:18:14 -07:00
|
|
|
kUnknown = 0,
|
|
|
|
kNonexistant,
|
|
|
|
kRegular,
|
|
|
|
kDirectory,
|
|
|
|
kCharDev,
|
|
|
|
kBlockDev,
|
|
|
|
kFifo,
|
|
|
|
kSymlink,
|
|
|
|
kSocket,
|
2014-11-14 14:48:12 -08:00
|
|
|
};
|
|
|
|
|
2016-10-21 17:56:45 -07:00
|
|
|
FileType GetFileType(const StringPiece& path);
|
2014-11-14 14:48:12 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Appends a path to `base`, separated by the directory separator.
|
|
|
|
*/
|
2016-10-21 17:56:45 -07:00
|
|
|
void AppendPath(std::string* base, StringPiece part);
|
2014-11-14 14:48:12 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Makes all the directories in `path`. The last element in the path
|
|
|
|
* is interpreted as a directory.
|
|
|
|
*/
|
|
|
|
bool mkdirs(const StringPiece& path);
|
|
|
|
|
2015-04-09 19:53:22 -07:00
|
|
|
/**
|
|
|
|
* Returns all but the last part of the path.
|
|
|
|
*/
|
2016-10-21 17:56:45 -07:00
|
|
|
StringPiece GetStem(const StringPiece& path);
|
2015-08-14 14:26:04 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the last part of the path with extension.
|
|
|
|
*/
|
2016-10-21 17:56:45 -07:00
|
|
|
StringPiece GetFilename(const StringPiece& path);
|
2015-08-14 14:26:04 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the extension of the path. This is the entire string after
|
|
|
|
* the first '.' of the last part of the path.
|
|
|
|
*/
|
2016-10-21 17:56:45 -07:00
|
|
|
StringPiece GetExtension(const StringPiece& path);
|
2015-08-14 14:26:04 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a package name (com.android.app) to a path: com/android/app
|
|
|
|
*/
|
2016-10-21 17:56:45 -07:00
|
|
|
std::string PackageToPath(const StringPiece& package);
|
2015-08-14 14:26:04 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a FileMap for the file at path.
|
|
|
|
*/
|
2016-10-21 17:56:45 -07:00
|
|
|
Maybe<android::FileMap> MmapPath(const StringPiece& path,
|
|
|
|
std::string* out_error);
|
2015-04-09 19:53:22 -07:00
|
|
|
|
2016-04-28 11:12:38 -07:00
|
|
|
/**
|
|
|
|
* Reads the file at path and appends each line to the outArgList vector.
|
|
|
|
*/
|
2016-10-21 17:56:45 -07:00
|
|
|
bool AppendArgsFromFile(const StringPiece& path,
|
|
|
|
std::vector<std::string>* out_arglist,
|
|
|
|
std::string* out_error);
|
2016-04-28 11:12:38 -07:00
|
|
|
|
2014-11-14 14:48:12 -08:00
|
|
|
/*
|
|
|
|
* Filter that determines which resource files/directories are
|
|
|
|
* processed by AAPT. Takes a pattern string supplied by the user.
|
2016-10-21 17:56:45 -07:00
|
|
|
* Pattern format is specified in the FileFilter::SetPattern() method.
|
2014-11-14 14:48:12 -08:00
|
|
|
*/
|
|
|
|
class FileFilter {
|
2016-10-19 12:18:14 -07:00
|
|
|
public:
|
2016-10-21 17:56:45 -07:00
|
|
|
explicit FileFilter(IDiagnostics* diag) : diag_(diag) {}
|
2016-10-19 12:18:14 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Patterns syntax:
|
|
|
|
* - Delimiter is :
|
|
|
|
* - Entry can start with the flag ! to avoid printing a warning
|
|
|
|
* about the file being ignored.
|
|
|
|
* - Entry can have the flag "<dir>" to match only directories
|
|
|
|
* or <file> to match only files. Default is to match both.
|
|
|
|
* - Entry can be a simplified glob "<prefix>*" or "*<suffix>"
|
|
|
|
* where prefix/suffix must have at least 1 character (so that
|
|
|
|
* we don't match a '*' catch-all pattern.)
|
|
|
|
* - The special filenames "." and ".." are always ignored.
|
|
|
|
* - Otherwise the full string is matched.
|
|
|
|
* - match is not case-sensitive.
|
|
|
|
*/
|
2016-10-21 17:56:45 -07:00
|
|
|
bool SetPattern(const StringPiece& pattern);
|
2016-10-19 12:18:14 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Applies the filter, returning true for pass, false for fail.
|
|
|
|
*/
|
|
|
|
bool operator()(const std::string& filename, FileType type) const;
|
|
|
|
|
|
|
|
private:
|
2016-10-21 17:56:45 -07:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(FileFilter);
|
|
|
|
|
|
|
|
IDiagnostics* diag_;
|
|
|
|
std::vector<std::string> pattern_tokens_;
|
2014-11-14 14:48:12 -08:00
|
|
|
};
|
|
|
|
|
2016-10-19 12:18:14 -07:00
|
|
|
} // namespace file
|
|
|
|
} // namespace aapt
|
2014-11-14 14:48:12 -08:00
|
|
|
|
2016-10-19 12:18:14 -07:00
|
|
|
#endif // AAPT_FILES_H
|