diff --git a/BUILD.gn b/BUILD.gn index ce5fafb7ea6c1a87dc396dd88cb55e914ce265f8..e9c112954ec8b2af3cb1ed5e4e075ae4ada7c686 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -73,7 +73,7 @@ ohos_executable("restool") { } else { external_deps = [ "zlib:libz" ] } - use_exceptions = true + cflags = [ "-std=c++17" ] if (is_mingw) { ldflags = [ diff --git a/README_zh.md b/README_zh.md index 9e921cf2b764e861a07ba8b8eff7fa4b793a51eb..36db00920191e85d0a887408a8b32875643f72f3 100644 --- a/README_zh.md +++ b/README_zh.md @@ -47,8 +47,6 @@ restool(资源编译工具)是一种资源构建工具。通过编译资源 | --dependEntry | 可缺省 | 带参数 | FA模型下单独编译feature时,指定entry模块的编译结果目录。 | | --icon-check | 可缺省 | 不带参数 | 开启icon和startWindowIcon的PNG图片校验功能。 | | --target-config | 可缺省 | 带参数 | 与“-i”命令同时使用,支持选择编译。
具体可参考如下**target-config参数说明**。| -| --thread | 可缺省 | 带参数 | 指定资源编译时开启的子线程数量。| -| --ignored-file | 可缺省 | 带参数 | 指定资源编译时文件和文件夹的忽略规则,格式为正则表达式,多个规则之间以“:”分隔。例如:“\\.git:\\.svn”表示忽略名称为“.git”、“.svn”的文件和文件夹。| **target-config参数说明** diff --git a/include/cmd/package_parser.h b/include/cmd/package_parser.h index 510b78e721ba375da510a9415f31cba314ebba48..a1dee33e0b01d6f1fe2b2230d67ecb4a1709eeeb 100644 --- a/include/cmd/package_parser.h +++ b/include/cmd/package_parser.h @@ -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; diff --git a/include/resconfig_parser.h b/include/resconfig_parser.h index 12307349e49e3b36d0e6053c4f74d9a23d836feb..5a74e0df24dd395ffacb6e12b4492da66cd6574d 100644 --- a/include/resconfig_parser.h +++ b/include/resconfig_parser.h @@ -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_; }; diff --git a/include/resource_data.h b/include/resource_data.h index 5056ebbd3bd210043b059a359684bacddd87d4f9..68bd0b14ebc57e45683225328c84d8a5c6bd6fbd 100644 --- a/include/resource_data.h +++ b/include/resource_data.h @@ -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 g_resourceSet; static std::set 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', diff --git a/include/resource_util.h b/include/resource_util.h index f01fc978554bed5c2cd8f1e3cb06c5d436777dbb..8f487ec52e317a630cba679f61be49a95e871ab9 100644 --- a/include/resource_util.h +++ b/include/resource_util.h @@ -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 ®ex, 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 DEFAULT_IGNORE_FILE_REGEX; + enum class IgnoreType { + IGNORE_FILE, + IGNORE_DIR, + IGNORE_ALL + }; + static const std::map IGNORE_FILE_REGEX; static std::string GetLocaleLimitkey(const KeyParam &KeyParam); static std::string GetDeviceTypeLimitkey(const KeyParam &KeyParam); static std::string GetResolutionLimitkey(const KeyParam &KeyParam); diff --git a/include/restool_errors.h b/include/restool_errors.h index d89f64787ec99b6a3c07a4647279709537d27418..6e76210c0bd4c1b652fae1ef1c9a3b876b5d2fb1 100644 --- a/include/restool_errors.h +++ b/include/restool_errors.h @@ -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"; diff --git a/src/cmd/cmd_parser.cpp b/src/cmd/cmd_parser.cpp index 6ae4ab5e50e0c5dc2c4b8ce7e5e15ffba636ab80..1652df74e3a39b432f1e33d89d92e7b00bf3ce67 100644 --- a/src/cmd/cmd_parser.cpp +++ b/src/cmd/cmd_parser.cpp @@ -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"; } } } diff --git a/src/cmd/package_parser.cpp b/src/cmd/package_parser.cpp index 0f2ba4a295453d8f99e01ee04888236510e42148..67ad9cd21b4cd37b9407b2b545f83fcd41d92c09 100644 --- a/src/cmd/package_parser.cpp +++ b/src/cmd/package_parser.cpp @@ -14,17 +14,13 @@ */ #include "cmd/package_parser.h" - #include #include -#include -#include - -#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) diff --git a/src/resconfig_parser.cpp b/src/resconfig_parser.cpp index e72fa1ed8a560e0f3557681551b5130a0bd3d79c..478bfe2e3f5bad393241f0ea76966249defff017 100644 --- a/src/resconfig_parser.cpp +++ b/src/resconfig_parser.cpp @@ -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; -} } } } diff --git a/src/resource_util.cpp b/src/resource_util.cpp index 0600f4efd92e68e3250724aca5ba32020af85fc8..70c42503db68023f11ddd43d0a4da4f15562d471 100644 --- a/src/resource_util.cpp +++ b/src/resource_util.cpp @@ -29,7 +29,7 @@ namespace OHOS { namespace Global { namespace Restool { using namespace std; -const map ResourceUtil::DEFAULT_IGNORE_FILE_REGEX = { +const map ResourceUtil::IGNORE_FILE_REGEX = { { "\\.git", IgnoreType::IGNORE_ALL }, { "\\.svn", IgnoreType::IGNORE_ALL }, { ".+\\.scc", IgnoreType::IGNORE_ALL }, @@ -41,8 +41,6 @@ const map ResourceUtil::DEFAULT_IGNORE_FILE_REGEX = { { "thumbs\\.db", IgnoreType::IGNORE_ALL }, { ".+~", IgnoreType::IGNORE_ALL } }; -static std::map 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 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 ®ex, 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; -} } } } diff --git a/src/restool_errors.cpp b/src/restool_errors.cpp index 599285c023295a5744fe85a095462e2ed66c51b9..6c5dfa5d5ee54ff84e87e2a237b7eef44db053d4 100644 --- a/src/restool_errors.cpp +++ b/src/restool_errors.cpp @@ -307,13 +307,6 @@ const std::map 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,