!266 merge ignore_file2 into master

支持根据文件路径匹配忽略规则

Created-by: leeduo
Commit-by: liduo
Merged-by: openharmony_ci
Description: ### 一、内容说明(相关的Issue)
支持根据文件路径匹配忽略规则


### 二、建议测试周期和提测地址  
  建议测试完成时间:xxxx.xx.xx  
  投产上线时间:xxxx.xx.xx  
  提测地址:CI环境/压测环境  
  测试账号:  

### 三、变更内容
  * 3.1 关联PR列表

  * 3.2 数据库和部署说明  
    1. 常规更新 
    2. 重启unicorn
    3. 重启sidekiq
    4. 迁移任务:是否有迁移任务,没有写 "无"
    5. rake脚本:`bundle exec xxx RAILS_ENV = production`;没有写 "无"

  * 3.4 其他技术优化内容(做了什么,变更了什么)
	不涉及


  * 3.5 废弃通知(什么字段、方法弃用?)
	不涉及


  * 3.6  后向不兼容变更(是否有无法向后兼容的变更?)
	不涉及

  
### 四、研发自测点(自测哪些?冒烟用例全部自测?)
  自测测试结论:Pass


### 五、测试关注点(需要提醒QA重点关注的、可能会忽略的地方)
  检查点:不涉及

  接口测试:不涉及

  性能测试:不涉及

  并发测试:不涉及

  其他:不涉及



See merge request: openharmony/developtools_global_resource_tool!266
This commit is contained in:
openharmony_ci
2025-10-11 19:30:36 +08:00
13 changed files with 78 additions and 28 deletions
+4 -1
View File
@@ -48,7 +48,10 @@ restool(资源编译工具)是一种资源构建工具。通过编译资源
| --icon-check | 可缺省 | 不带参数 | 开启icon和startWindowIcon的PNG图片校验功能。 |
| --target-config | 可缺省 | 带参数 | 与“-i”命令同时使用,支持选择编译。<br>具体可参考如下**target-config参数说明**。|
| --thread | 可缺省 | 带参数 | 指定资源编译时开启的子线程数量。|
| --ignored-file | 可缺省 | 带参数 | 指定资源编译时文件和文件夹的忽略规则,格式为正则表达式,多个规则之间以“:”分隔。例如:“\\.git:\\.svn”表示忽略名称为“.git”、“.svn”的文件和文件夹。|
| --ignored-file | 可缺省 | 带参数 | 指定资源文件和文件夹的忽略规则,格式为正则表达式,匹配文件名称,多个规则之间以“:”分隔。例如:“\\.git:\\.svn”表示忽略名称为“.git”、“.svn”的文件和文件夹。|
| --ignored-path | 可缺省 | 带参数 | 指定资源文件和文件夹的忽略规则,格式为正则表达式,匹配文件名称和文件路径,多个规则之间以“:”分隔。例如:“.+/rawfile/\\.git:.+/rawfile/\\.svn”表示忽略rawfile目录下的“.git”、“.svn”的文件和文件夹。|
**target-config参数说明**
+1 -1
View File
@@ -86,7 +86,7 @@ private:
uint32_t ParseTargetConfig(const std::string &argValue);
uint32_t AddCompressionPath(const std::string &argValue);
uint32_t ParseThread(const std::string &argValue);
uint32_t ParseIgnoreFileRegex(const std::string &argValue);
uint32_t ParseIgnoreFileRegex(const std::string &argValue, const bool &isIgnorePath = false);
static const struct option CMD_OPTS[];
static const std::string CMD_PARAMS;
+1 -1
View File
@@ -39,7 +39,7 @@ private:
uint32_t GetModuleNames(const cJSON *node, int c, HandleBack callback);
uint32_t GetBool(const std::string &nodeName, const cJSON *node, int c, HandleBack callback);
uint32_t GetNumber(const std::string &nodeName, const cJSON *node, int c, HandleBack callback);
uint32_t GetIgnorePatterns(const std::string &nodeName, const cJSON *node, int c);
uint32_t GetIgnorePatterns(const std::string &nodeName, const cJSON *node, int c, const bool &isPath);
cJSON *root_;
std::string filePath_;
};
+2 -1
View File
@@ -50,7 +50,7 @@ const static std::string LONG_PATH_HEAD = "\\\\?\\";
const static int32_t VERSION_MAX_LEN = 128;
static const std::string RESTOOL_NAME = "Restool";
static const std::string RESTOOLV2_NAME = "RestoolV2";
static const std::string RESTOOL_VERSION = { " 6.0.0.002" };
static const std::string RESTOOL_VERSION = { " 6.0.0.003" };
const static int32_t TAG_LEN = 4;
constexpr static int DEFAULT_POOL_SIZE = 8;
static std::set<std::string> g_resourceSet;
@@ -157,6 +157,7 @@ enum Option {
COMPRESSED_CONFIG = 7,
THREAD = 8,
IGNORED_FILE = 9,
IGNORED_PATH = 10,
STARTID = 'e',
FORCEWRITE = 'f',
HELP = 'h',
+13 -3
View File
@@ -147,11 +147,10 @@ public:
/**
* @brief ignore file or directory
* @param filename: file or directory name
* @param isFile: ture if is file, other false
* @param fileEntry: file or directory
* @return true if ignore, other false
*/
static bool IsIgnoreFile(const std::string &filename, bool isFile);
static bool IsIgnoreFile(const FileEntry &fileEntry);
/**
* @brief generate hash string
@@ -282,6 +281,17 @@ public:
*/
static void SetUseCustomIgnoreRegex(const bool &isUseCustomRegex);
/**
* @brief get whether use custom ignore regex pattern
*/
static bool IsUseCustomIgnoreRegex();
/**
* @brief set whether to use ignore regex pattern matching for file paths
* @param isUseCustomRegex: true is use custom ignore file regex
*/
static void SetIgnorePath(const bool &isIgnorePath);
private:
static const std::map<std::string, IgnoreType> DEFAULT_IGNORE_FILE_REGEX;
static std::string GetLocaleLimitkey(const KeyParam &KeyParam);
+2 -3
View File
@@ -86,8 +86,7 @@ uint32_t BinaryFilePacker::CopyBinaryFile(const string &filePath, const string &
PrintError(GetError(ERR_CODE_INVALID_RESOURCE_PATH).FormatCause(filePath.c_str(), "not a directory"));
return RESTOOL_ERROR;
}
if (ResourceUtil::IsIgnoreFile(fileType, false)) {
if (ResourceUtil::IsIgnoreFile(FileEntry(filePath))) {
return RESTOOL_SUCCESS;
}
@@ -110,7 +109,7 @@ uint32_t BinaryFilePacker::CopyBinaryFileImpl(const string &src, const string &d
}
for (const auto &entry : f.GetChilds()) {
string filename = entry->GetFilePath().GetFilename();
if (ResourceUtil::IsIgnoreFile(filename, entry->IsFile())) {
if (ResourceUtil::IsIgnoreFile(*entry)) {
continue;
}
+2
View File
@@ -114,6 +114,8 @@ void CmdParser::ShowUseage()
std::cout << " --compressed-config Path of opt-compression.json.\n";
std::cout << " --thread Subthreads count.\n";
std::cout << " --ignored-file Regular patterns of ignored files, split by ':'(like \\.git:\\.svn).\n";
std::cout << " --ignored-path Regular patterns of ignored file paths, split by ':'";
std::cout << "(like .+/rawfile/\\.git:.+/resfile/\\.svn).\n";
}
}
}
+9 -2
View File
@@ -53,6 +53,7 @@ const struct option PackageParser::CMD_OPTS[] = {
{ "compressed-config", required_argument, nullptr, Option::COMPRESSED_CONFIG},
{ "thread", required_argument, nullptr, Option::THREAD},
{ "ignored-file", required_argument, nullptr, Option::IGNORED_FILE},
{ "ignored-path", required_argument, nullptr, Option::IGNORED_PATH},
{ 0, 0, 0, 0},
};
@@ -478,11 +479,16 @@ uint32_t PackageParser::ParseThread(const std::string &argValue)
return RESTOOL_SUCCESS;
}
uint32_t PackageParser::ParseIgnoreFileRegex(const std::string &argValue)
uint32_t PackageParser::ParseIgnoreFileRegex(const std::string &argValue, const bool &isIgnorePath)
{
if (ResourceUtil::IsUseCustomIgnoreRegex()) {
PrintError(GetError(ERR_CODE_EXCLUSIVE_OPTION).FormatCause("--ignored-file", "--ignored-path"));
return RESTOOL_ERROR;
}
std::stringstream in(argValue);
std::string regex;
ResourceUtil::SetUseCustomIgnoreRegex(true);
ResourceUtil::SetIgnorePath(isIgnorePath);
while (getline(in, regex, ':')) {
bool isSucceed = ResourceUtil::AddIgnoreFileRegex(regex, IgnoreType::IGNORE_ALL);
if (!isSucceed) {
@@ -567,7 +573,8 @@ void PackageParser::InitCommand()
handles_.emplace(Option::DEFINED_SYSIDS, bind(&PackageParser::AddSysIdDefined, this, _1));
handles_.emplace(Option::COMPRESSED_CONFIG, bind(&PackageParser::AddCompressionPath, this, _1));
handles_.emplace(Option::THREAD, bind(&PackageParser::ParseThread, this, _1));
handles_.emplace(Option::IGNORED_FILE, bind(&PackageParser::ParseIgnoreFileRegex, this, _1));
handles_.emplace(Option::IGNORED_FILE, bind(&PackageParser::ParseIgnoreFileRegex, this, _1, false));
handles_.emplace(Option::IGNORED_PATH, bind(&PackageParser::ParseIgnoreFileRegex, this, _1, true));
}
uint32_t PackageParser::HandleProcess(int c, const string &argValue)
+1 -1
View File
@@ -47,7 +47,7 @@ uint32_t IResourceCompiler::Compile(const vector<DirectoryInfo> &directoryInfos)
return RESTOOL_ERROR;
}
for (const auto &it : f.GetChilds()) {
if (ResourceUtil::IsIgnoreFile(it->GetFilePath().GetFilename(), it->IsFile())) {
if (ResourceUtil::IsIgnoreFile(*it)) {
continue;
}
+9 -2
View File
@@ -95,7 +95,9 @@ void ResConfigParser::InitFileListCommand(HandleBack callback)
fileListHandles_.emplace("thread", bind(&ResConfigParser::GetNumber, this, "thread", _1,
Option::THREAD, callback));
fileListHandles_.emplace("ignoreResourcePattern", bind(&ResConfigParser::GetIgnorePatterns, this,
"ignoreResourcePattern", _1, Option::IGNORED_FILE));
"ignoreResourcePattern", _1, Option::IGNORED_FILE, false));
fileListHandles_.emplace("ignoreResourcePathPattern", bind(&ResConfigParser::GetIgnorePatterns, this,
"ignoreResourcePathPattern", _1, Option::IGNORED_PATH, true));
}
uint32_t ResConfigParser::GetString(const std::string &nodeName, const cJSON *node, int c, HandleBack callback)
@@ -199,13 +201,18 @@ uint32_t ResConfigParser::GetNumber(const std::string &nodeName, const cJSON *no
return RESTOOL_SUCCESS;
}
uint32_t ResConfigParser::GetIgnorePatterns(const std::string &nodeName, const cJSON *node, int c)
uint32_t ResConfigParser::GetIgnorePatterns(const std::string &nodeName, const cJSON *node, int c, const bool &isPath)
{
if (!node) {
PrintError(GetError(ERR_CODE_JSON_NODE_MISSING).FormatCause(nodeName.c_str()).SetPosition(filePath_));
return RESTOOL_ERROR;
}
if (ResourceUtil::IsUseCustomIgnoreRegex()) {
PrintError(GetError(ERR_CODE_EXCLUSIVE_OPTION).FormatCause("--ignored-file", "--ignored-path"));
return RESTOOL_ERROR;
}
ResourceUtil::SetUseCustomIgnoreRegex(true);
ResourceUtil::SetIgnorePath(isPath);
HandleBack callback = [](int c, const string &argValue) {
bool isSucceed = ResourceUtil::AddIgnoreFileRegex(argValue, IgnoreType::IGNORE_ALL);
if (!isSucceed) {
+4 -4
View File
@@ -170,7 +170,7 @@ bool ResourceAppend::ScanSubLimitkeyResources(const FileEntry entry, const strin
{
for (const auto &child : entry.GetChilds()) {
string limitKey = child->GetFilePath().GetFilename();
if (ResourceUtil::IsIgnoreFile(limitKey, child->IsFile())) {
if (ResourceUtil::IsIgnoreFile(*child)) {
continue;
}
@@ -219,7 +219,7 @@ bool ResourceAppend::ScanLimitKey(const unique_ptr<FileEntry> &entry,
for (const auto &child : entry->GetChilds()) {
string fileCuster = child->GetFilePath().GetFilename();
if (ResourceUtil::IsIgnoreFile(fileCuster, child->IsFile())) {
if (ResourceUtil::IsIgnoreFile(*child)) {
continue;
}
@@ -251,7 +251,7 @@ bool ResourceAppend::ScanFiles(const unique_ptr<FileEntry> &entry,
{
for (const auto &child : entry->GetChilds()) {
string filename = child->GetFilePath().GetFilename();
if (ResourceUtil::IsIgnoreFile(filename, child->IsFile())) {
if (ResourceUtil::IsIgnoreFile(*child)) {
continue;
}
@@ -433,7 +433,7 @@ bool ResourceAppend::ScanRawFilesOrResFiles(const string &path, const string &ou
for (const auto &child : entry.GetChilds()) {
string filename = child->GetFilePath().GetFilename();
if (ResourceUtil::IsIgnoreFile(filename, child->IsFile())) {
if (ResourceUtil::IsIgnoreFile(*child)) {
continue;
}
+2 -2
View File
@@ -35,7 +35,7 @@ bool ResourceDirectory::ScanResources(const string &resourcesDir, function<bool(
for (const auto &it : f.GetChilds()) {
string limitKey = it->GetFilePath().GetFilename();
if (ResourceUtil::IsIgnoreFile(limitKey, it->IsFile())) {
if (ResourceUtil::IsIgnoreFile(*it)) {
continue;
}
@@ -75,7 +75,7 @@ bool ResourceDirectory::ScanResourceLimitKeyDir(const string &resourceTypeDir, c
for (const auto &it : f.GetChilds()) {
string dirPath = it->GetFilePath().GetPath();
string fileCluster = it->GetFilePath().GetFilename();
if (ResourceUtil::IsIgnoreFile(fileCluster, it->IsFile())) {
if (ResourceUtil::IsIgnoreFile(*it)) {
continue;
}
+28 -7
View File
@@ -43,6 +43,7 @@ const map<string, IgnoreType> ResourceUtil::DEFAULT_IGNORE_FILE_REGEX = {
};
static std::map<std::string, IgnoreType> g_userIgnoreFileRegex;
static bool g_isUseCustomRegex = false;
static bool g_isIgnorePath = false;
static std::mutex fileMutex_;
@@ -251,29 +252,39 @@ bool ResourceUtil::CreateDirs(const string &filePath)
return true;
}
bool ResourceUtil::IsIgnoreFile(const string &filename, bool isFile)
bool ResourceUtil::IsIgnoreFile(const FileEntry &fileEntry)
{
map<string, IgnoreType> regexs;
std::string regexSources;
string key = filename;
string fileName = fileEntry.GetFilePath().GetFilename();
string filePath = fileEntry.GetFilePath().GetPath();
filePath = regex_replace(filePath, regex("\\\\+"), "/");
if (g_isUseCustomRegex) {
regexs = g_userIgnoreFileRegex;
regexSources = "user";
} else {
regexs = DEFAULT_IGNORE_FILE_REGEX;
regexSources = "default";
transform(key.begin(), key.end(), key.begin(), ::tolower);
transform(fileName.begin(), fileName.end(), fileName.begin(), ::tolower);
}
bool isFile = fileEntry.IsFile();
for (const auto &iter : regexs) {
if ((iter.second == IgnoreType::IGNORE_FILE && !isFile) ||
(iter.second == IgnoreType::IGNORE_DIR && isFile)) {
if ((iter.second == IgnoreType::IGNORE_FILE && !isFile) || (iter.second == IgnoreType::IGNORE_DIR && isFile)) {
continue;
}
if (regex_match(key, regex(iter.first))) {
cout << "Info: file '" << filename << "' is ignored by " << regexSources << " regular pattern '"
if (regex_match(fileName, regex(iter.first))) {
cout << "Info: file '" << fileName << "' is ignored by " << regexSources << " filename pattern '"
<< iter.first << "'." << endl;
return true;
}
if (g_isUseCustomRegex && g_isIgnorePath) {
if (regex_match(filePath, regex(iter.first))) {
cout << "Info: file '" << filePath << "' is ignored by " << regexSources << " filepath pattern '"
<< iter.first << "'." << endl;
return true;
}
}
}
return false;
}
@@ -540,6 +551,16 @@ void ResourceUtil::SetUseCustomIgnoreRegex(const bool &isUseCustomRegex)
{
g_isUseCustomRegex = isUseCustomRegex;
}
void ResourceUtil::SetIgnorePath(const bool &isIgnorePath)
{
g_isIgnorePath = isIgnorePath;
}
bool ResourceUtil::IsUseCustomIgnoreRegex()
{
return g_isUseCustomRegex;
}
}
}
}