!232 Revert "support specify ignored files patterns"

Merge pull request !232 from liduo/revert_ignore510
This commit is contained in:
openharmony_ci
2025-04-15 02:27:39 +00:00
committed by Gitee
12 changed files with 30 additions and 133 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ ohos_executable("restool") {
} else {
external_deps = [ "zlib:libz" ]
}
use_exceptions = true
cflags = [ "-std=c++17" ]
if (is_mingw) {
ldflags = [
-2
View File
@@ -47,8 +47,6 @@ restool(资源编译工具)是一种资源构建工具。通过编译资源
| --dependEntry | 可缺省 | 带参数 | FA模型下单独编译feature时,指定entry模块的编译结果目录。 |
| --icon-check | 可缺省 | 不带参数 | 开启icon和startWindowIcon的PNG图片校验功能。 |
| --target-config | 可缺省 | 带参数 | 与“-i”命令同时使用,支持选择编译。<br>具体可参考如下**target-config参数说明**。|
| --thread | 可缺省 | 带参数 | 指定资源编译时开启的子线程数量。|
| --ignored-file | 可缺省 | 带参数 | 指定资源编译时文件和文件夹的忽略规则,格式为正则表达式,多个规则之间以“:”分隔。例如:“\\.git:\\.svn”表示忽略名称为“.git”、“.svn”的文件和文件夹。|
**target-config参数说明**
-1
View File
@@ -86,7 +86,6 @@ 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);
static const struct option CMD_OPTS[];
static const std::string CMD_PARAMS;
-1
View File
@@ -39,7 +39,6 @@ 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);
cJSON *root_;
std::string filePath_;
};
+1 -8
View File
@@ -49,19 +49,13 @@ const static std::string SOLUTIONS_ARROW = "> ";
const static std::string LONG_PATH_HEAD = "\\\\?\\";
const static int32_t VERSION_MAX_LEN = 128;
const static int32_t INT_TO_BYTES = sizeof(uint32_t);
static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 5.1.0.008" };
static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 5.1.0.007" };
const static int32_t TAG_LEN = 4;
constexpr static int DEFAULT_POOL_SIZE = 8;
static std::set<std::string> g_resourceSet;
static std::set<std::string> g_hapResourceSet;
const static int8_t INVALID_ID = -1;
enum class IgnoreType {
IGNORE_FILE,
IGNORE_DIR,
IGNORE_ALL
};
enum class KeyType {
LANGUAGE = 0,
REGION = 1,
@@ -154,7 +148,6 @@ enum Option {
DEFINED_SYSIDS = 6,
COMPRESSED_CONFIG = 7,
THREAD = 8,
IGNORED_FILE = 9,
STARTID = 'e',
FORCEWRITE = 'f',
HELP = 'h',
+6 -16
View File
@@ -266,23 +266,13 @@ public:
* @return limit type string
*/
static std::string KeyTypeToStr(KeyType type);
/**
* @brief add ignore file regex pattern
* @param regex: the regex pattern
* @param ignoreType: the ignore file type
* @return if add succeed, return true
*/
static bool AddIgnoreFileRegex(const std::string &regex, IgnoreType ignoreType);
/**
* @brief set whether use custom ignore regex pattern
* @param isUseCustomRegex: true is use custom ignore file regex
*/
static void SetUseCustomIgnoreRegex(const bool &isUseCustomRegex);
private:
static const std::map<std::string, IgnoreType> DEFAULT_IGNORE_FILE_REGEX;
enum class IgnoreType {
IGNORE_FILE,
IGNORE_DIR,
IGNORE_ALL
};
static const std::map<std::string, IgnoreType> IGNORE_FILE_REGEX;
static std::string GetLocaleLimitkey(const KeyParam &KeyParam);
static std::string GetDeviceTypeLimitkey(const KeyParam &KeyParam);
static std::string GetResolutionLimitkey(const KeyParam &KeyParam);
-1
View File
@@ -84,7 +84,6 @@ constexpr uint32_t ERR_CODE_RES_HEADER_PATH_EMPTY = 11210023;
constexpr uint32_t ERR_CODE_DUMP_MISSING_INPUT = 11210024;
constexpr uint32_t ERR_CODE_DUMP_INVALID_INPUT = 11210025;
constexpr uint32_t ERR_CODE_INVALID_THREAD_COUNT = 11210026;
constexpr uint32_t ERR_CODE_INVALID_IGNORE_FILE = 11210027;
// 11211xxx resource pack error
const std::string ERR_TYPE_RESOURCE_PACK = "Resource Pack Error";
+17 -19
View File
@@ -90,30 +90,28 @@ void CmdParser::ShowUseage()
"For details about the usage of dump, see '-h'.\n";
std::cout << "\n";
std::cout << "[options]:\n";
std::cout << " -i/--inputPath Input resource path, can add multiple.\n";
std::cout << " -p/--packageName Package name.\n";
std::cout << " -o/--outputPath Output path.\n";
std::cout << " -r/--resHeader Resource header file path(like ./ResourceTable.js, ./ResrouceTable.h).\n";
std::cout << " -f/--forceWrite If output path exists,force delete it.\n";
std::cout << " -v/--version Print tool version.\n";
std::cout << " -m/--modules Module names, can add multiple, split by ','(like entry1,entry2,...).\n";
std::cout << " -j/--json Path of module.json(in Stage model) or onfig.json(in FA model).\n";
std::cout << " -e/--startId Start id mask, e.g 0x01000000,";
std::cout << " in the scope [0x01000000, 0x06FFFFFF),[0x08000000, 0xFFFFFFFF).\n";
std::cout << " -x/--append Resources folder path.\n";
std::cout << " -z/--combine Flag for incremental compilation.\n";
std::cout << " -h/--help Displays this help menu.\n";
std::cout << " -l/--fileList Input json file of the option set, e.g resConfig.json.";
std::cout << " -i/--inputPath input resource path, can add more.\n";
std::cout << " -p/--packageName package name.\n";
std::cout << " -o/--outputPath output path.\n";
std::cout << " -r/--resHeader resource header file path(like ./ResourceTable.js, ./ResrouceTable.h).\n";
std::cout << " -f/--forceWrite if output path exists,force delete it.\n";
std::cout << " -v/--version print tool version.\n";
std::cout << " -m/--modules module name, can add more, split by ','(like entry1,entry2,...).\n";
std::cout << " -j/--json config.json path.\n";
std::cout << " -e/--startId start id mask, e.g 0x01000000,";
std::cout << " in [0x01000000, 0x06FFFFFF),[0x08000000, 0xFFFFFFFF)\n";
std::cout << " -x/--append resources folder path\n";
std::cout << " -z/--combine flag for incremental compilation\n";
std::cout << " -h/--help Displays this help menu\n";
std::cout << " -l/--fileList input json file of the option set, e.g resConfig.json.";
std::cout << " For details, see the developer documentation.\n";
std::cout << " --ids Save id_defined.json direcory.\n";
std::cout << " --defined-ids Input id_defined.json path.\n";
std::cout << " --ids save id_defined.json direcory\n";
std::cout << " --defined-ids input id_defined.json path\n";
std::cout << " --dependEntry Build result directory of the specified entry module when the feature";
std::cout << " module resources are independently built in the FA model.\n";
std::cout << " --icon-check Enable the PNG image verification function for icons and startwindows.\n";
std::cout << " --target-config When used with '-i', selective compilation is supported.\n";
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 << " --compressed-config opt-compression.json path.\n";
}
}
}
+3 -23
View File
@@ -14,17 +14,13 @@
*/
#include "cmd/package_parser.h"
#include <algorithm>
#include <climits>
#include <regex>
#include <sstream>
#include "file_entry.h"
#include "resconfig_parser.h"
#include "resource_pack.h"
#include "resource_util.h"
#include "select_compile_parse.h"
#include "file_entry.h"
#include "resource_pack.h"
namespace OHOS {
namespace Global {
@@ -52,7 +48,6 @@ const struct option PackageParser::CMD_OPTS[] = {
{ "defined-sysids", required_argument, nullptr, Option::DEFINED_SYSIDS},
{ "compressed-config", required_argument, nullptr, Option::COMPRESSED_CONFIG},
{ "thread", required_argument, nullptr, Option::THREAD},
{ "ignored-file", required_argument, nullptr, Option::IGNORED_FILE},
{ 0, 0, 0, 0},
};
@@ -248,7 +243,7 @@ uint32_t PackageParser::ForceWrite()
uint32_t PackageParser::PrintVersion()
{
cout << "Info: Restool version = " << RESTOOL_VERSION << endl;
cout << "Info: Restool version= " << RESTOOL_VERSION << endl;
exit(RESTOOL_SUCCESS);
return RESTOOL_SUCCESS;
}
@@ -477,20 +472,6 @@ uint32_t PackageParser::ParseThread(const std::string &argValue)
return RESTOOL_SUCCESS;
}
uint32_t PackageParser::ParseIgnoreFileRegex(const std::string &argValue)
{
std::stringstream in(argValue);
std::string regex;
ResourceUtil::SetUseCustomIgnoreRegex(true);
while (getline(in, regex, ':')) {
bool isSucceed = ResourceUtil::AddIgnoreFileRegex(regex, IgnoreType::IGNORE_ALL);
if (!isSucceed) {
return RESTOOL_ERROR;
}
}
return RESTOOL_SUCCESS;
}
size_t PackageParser::GetThreadCount() const
{
return threadCount_;
@@ -566,7 +547,6 @@ 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));
}
uint32_t PackageParser::HandleProcess(int c, const string &argValue)
-22
View File
@@ -94,8 +94,6 @@ void ResConfigParser::InitFileListCommand(HandleBack callback)
Option::COMPRESSED_CONFIG, 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));
}
uint32_t ResConfigParser::GetString(const std::string &nodeName, const cJSON *node, int c, HandleBack callback)
@@ -198,26 +196,6 @@ 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)
{
if (!node) {
PrintError(GetError(ERR_CODE_JSON_NODE_MISSING).FormatCause(nodeName.c_str()).SetPosition(filePath_));
return RESTOOL_ERROR;
}
ResourceUtil::SetUseCustomIgnoreRegex(true);
HandleBack callback = [](int c, const string &argValue) {
bool isSucceed = ResourceUtil::AddIgnoreFileRegex(argValue, IgnoreType::IGNORE_ALL);
if (!isSucceed) {
return RESTOOL_ERROR;
}
return RESTOOL_SUCCESS;
};
if (GetArray(nodeName, node, c, callback) != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
return RESTOOL_SUCCESS;
}
}
}
}
+2 -32
View File
@@ -29,7 +29,7 @@ namespace OHOS {
namespace Global {
namespace Restool {
using namespace std;
const map<string, IgnoreType> ResourceUtil::DEFAULT_IGNORE_FILE_REGEX = {
const map<string, ResourceUtil::IgnoreType> ResourceUtil::IGNORE_FILE_REGEX = {
{ "\\.git", IgnoreType::IGNORE_ALL },
{ "\\.svn", IgnoreType::IGNORE_ALL },
{ ".+\\.scc", IgnoreType::IGNORE_ALL },
@@ -41,8 +41,6 @@ const map<string, IgnoreType> ResourceUtil::DEFAULT_IGNORE_FILE_REGEX = {
{ "thumbs\\.db", IgnoreType::IGNORE_ALL },
{ ".+~", IgnoreType::IGNORE_ALL }
};
static std::map<std::string, IgnoreType> g_userIgnoreFileRegex;
static bool g_isUseCustomRegex = false;
static std::mutex fileMutex_;
@@ -249,25 +247,14 @@ bool ResourceUtil::CreateDirs(const string &filePath)
bool ResourceUtil::IsIgnoreFile(const string &filename, bool isFile)
{
map<string, IgnoreType> regexs;
std::string regexSources;
if (g_isUseCustomRegex) {
regexs = g_userIgnoreFileRegex;
regexSources = "user";
} else {
regexs = DEFAULT_IGNORE_FILE_REGEX;
regexSources = "default";
}
string key = filename;
transform(key.begin(), key.end(), key.begin(), ::tolower);
for (const auto &iter : regexs) {
for (const auto &iter : IGNORE_FILE_REGEX) {
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 '"
<< iter.first << "'." << endl;
return true;
}
}
@@ -519,23 +506,6 @@ string ResourceUtil::KeyTypeToStr(KeyType type)
}
return ret;
}
bool ResourceUtil::AddIgnoreFileRegex(const std::string &regex, IgnoreType ignoreType)
{
try {
std::regex rg(regex);
} catch (std::regex_error err) {
PrintError(GetError(ERR_CODE_INVALID_IGNORE_FILE).FormatCause(regex.c_str(), err.what()));
return false;
}
g_userIgnoreFileRegex[regex] = ignoreType;
return true;
}
void ResourceUtil::SetUseCustomIgnoreRegex(const bool &isUseCustomRegex)
{
g_isUseCustomRegex = isUseCustomRegex;
}
}
}
}
-7
View File
@@ -307,13 +307,6 @@ const std::map<uint32_t, ErrorInfo> ERRORS_MAP = {
"",
{},
{} } },
{ ERR_CODE_INVALID_IGNORE_FILE,
{ ERR_CODE_INVALID_IGNORE_FILE,
ERR_TYPE_COMMAND_PARSE,
"Invalid ignore file pattern '%s', %s",
"",
{ "Make sure the argument of the option --ignored-file is not empty and contains valid regular expressions." },
{} } },
// 11211xxx
{ ERR_CODE_OUTPUT_EXIST,