!27 按模块名自动分配资源ID缺陷

Merge pull request !27 from 陈程/master
This commit is contained in:
openharmony_ci
2022-05-11 09:23:07 +00:00
committed by Gitee
17 changed files with 43 additions and 55 deletions
+2 -26
View File
@@ -1,3 +1,4 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
@@ -173,29 +174,4 @@
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.
END OF TERMS AND CONDITIONS
+2 -2
View File
@@ -19,8 +19,8 @@ config("restool_libxml2_config") {
include_dirs +=
[ "//developtools/global_resource_tool/build/libxml2/win32/include" ]
defines = [ "LIBXML_STATIC" ]
} else {
include_dirs += [ "${LIBXML_PATH}/config" ]
} else if (is_mac) {
defines = [ "LIBXML_THREAD_ENABLED" ]
}
include_dirs += [ "${LIBXML_PATH}/include" ]
+2 -2
View File
@@ -35,7 +35,7 @@ public:
class PackageParser : public ICmdParser {
public:
PackageParser() {};
~PackageParser() = default;
virtual ~PackageParser() = default;
uint32_t Parse(int argc, char *argv[]) override;
const std::vector<std::string> &GetInputs() const;
const std::string &GetPackageName() const;
@@ -104,7 +104,7 @@ template<class T>
void CmdParser<T>::ShowUseage()
{
std::cout << "This is an OHOS Packaging Tool.\n";
std::cout << "Useage:\n";
std::cout << "Usage:\n";
std::cout << TOOL_NAME << " [arguments] Package the OHOS resources.\n";
std::cout << "[arguments]:\n";
std::cout << " -i input resource path, can add more.\n";
+2 -2
View File
@@ -28,7 +28,7 @@ namespace Restool {
class FileManager : public Singleton<FileManager> {
public:
uint32_t ScanModules(const std::vector<std::string> &inputs, const std::string &output);
const std::map<int32_t, std::vector<ResourceItem>> &GetResources() const { return alls_; };
const std::map<int32_t, std::vector<ResourceItem>> &GetResources() const { return items_; };
void SetModuleName(const std::string &moduleName) { moduleName_ = moduleName; };
uint32_t ScanIncrement(const std::string &output);
@@ -42,7 +42,7 @@ private:
const std::map<ResType, std::vector<DirectoryInfo>> &resTypeOfDirs) const;
// id, resource items
std::map<int32_t, std::vector<ResourceItem>> alls_;
std::map<int32_t, std::vector<ResourceItem>> items_;
std::string moduleName_;
};
}
+1 -1
View File
@@ -27,7 +27,7 @@ public:
ReferenceParser();
virtual ~ReferenceParser();
uint32_t ParseRefInSolidXml(const std::vector<std::string> &solidXmlFolders) const;
uint32_t ParseRefInElement(std::map<int32_t, std::vector<ResourceItem>> &alls) const;
uint32_t ParseRefInElement(std::map<int32_t, std::vector<ResourceItem>> &items) const;
uint32_t ParseRefInString(std::string &value, bool &update) const;
uint32_t ParseRefInProfile(const std::string &output) const;
uint32_t ParseRefInJson(const std::string &filePath) const;
+1 -1
View File
@@ -32,7 +32,7 @@ const static std::string ID_DEFINED_FILE = "id_defined.json";
const static std::string RESOURCE_INDEX_FILE = "resources.index";
const static std::string SEPARATOR = "/";
const static int32_t VERSION_MAX_LEN = 128;
static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 2.007" };
static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 2.008" };
const static int32_t TAG_LEN = 4;
enum class KeyType {
+1 -1
View File
@@ -116,7 +116,7 @@ public:
static bool CopyFleInner(const std::string &src, const std::string &dst);
/**
* @brief create directorys
* @brief create directories
* @param filePath: directory path
* @return true if success, other false
*/
+5 -1
View File
@@ -34,7 +34,11 @@ const map<string, string> ConfigParser::JSON_STRING_IDS = {
{ "label", "^\\$string:" },
{ "description", "^\\$string:" },
{ "theme", "^\\$theme:" },
{ "reason", "^\\$string:" }
{ "reason", "^\\$string:" },
{ "startWindowIcon", "^\\$media:" },
{ "startWindowBackground", "^\\$color:"},
{ "resource", "^\\$[a-z]+:" },
{ "extra", "^\\$[a-z]+:" }
};
const map<string, string> ConfigParser::JSON_ARRAY_IDS = {
+2 -3
View File
@@ -65,7 +65,6 @@ const vector<unique_ptr<FileEntry>> FileEntry::GetChilds() const
filePath = filePath_.GetPath() + SEPARATE + filename;
unique_ptr<FileEntry> f = make_unique<FileEntry>(filePath);
cout << filePath << endl;
f->Init();
children.push_back(move(f));
}
@@ -223,13 +222,13 @@ bool FileEntry::CreateDirsInner(const string &path, string::size_type offset)
string::size_type pos = path.find_first_of(SEPARATE.front(), offset);
if (pos == string::npos) {
#if _WIN32
return mkdir(path.c_str());
return mkdir(path.c_str()) == 0;
#else
return mkdir(path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0;
#endif
}
string subPath = path.substr(0, pos);
string subPath = path.substr(0, pos + 1);
if (!Exist(subPath)) {
#if _WIN32
if (mkdir(subPath.c_str()) != 0) {
+3 -3
View File
@@ -46,7 +46,7 @@ uint32_t FileManager::ScanModules(const vector<string> &inputs, const string &ou
uint32_t FileManager::ScanIncrement(const string &output)
{
auto &incrementManager = IncrementManager::GetInstance();
alls_ = incrementManager.GetResourceItems();
items_ = incrementManager.GetResourceItems();
vector<string> sxmlFolders;
FilterRefSolidXml(output, sxmlFolders, incrementManager.GetScanDirs());
return ParseReference(output, sxmlFolders);
@@ -67,14 +67,14 @@ uint32_t FileManager::ScanModule(const string &input, const string &output,
uint32_t FileManager::MergeResourceItem(const map<int32_t, vector<ResourceItem>> &resourceInfos)
{
return ResourceModule::MergeResourceItem(alls_, resourceInfos);
return ResourceModule::MergeResourceItem(items_, resourceInfos);
}
uint32_t FileManager::ParseReference(const string &output, const vector<string> &sxmlFolders)
{
ReferenceParser referenceParser;
if (referenceParser.ParseRefInSolidXml(sxmlFolders) != RESTOOL_SUCCESS ||
referenceParser.ParseRefInElement(alls_) != RESTOOL_SUCCESS ||
referenceParser.ParseRefInElement(items_) != RESTOOL_SUCCESS ||
referenceParser.ParseRefInProfile(output) != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
-1
View File
@@ -68,7 +68,6 @@ uint32_t IResourceCompiler::Compile(const vector<DirectoryInfo> &directoryInfos)
return a.filePath < b.filePath;
});
for (const auto &fileInfo : fileInfos) {
cout << "compile " << fileInfo.filePath << endl;
if (CompileSingleFile(fileInfo) != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
+7 -7
View File
@@ -169,7 +169,7 @@ bool JsonCompiler::HandleBoolean(const Json::Value &objectNode, ResourceItem &re
{
Json::Value valueNode = objectNode[TAG_VALUE];
if (valueNode.isString()) {
regex ref("^\\$boolean:.*");
regex ref("^\\$(ohos:)?boolean:.*");
if (!regex_match(valueNode.asString(), ref)) {
cerr << "Error: '" << valueNode.asString() << "' only refer '$boolean:xxx',";
cerr << resourceItem.GetFilePath() << endl;
@@ -290,17 +290,17 @@ bool JsonCompiler::CheckJsonStringValue(const Json::Value &valueNode, const Reso
}
const map<ResType, string> REFS = {
{ ResType::STRING, "$string:" },
{ ResType::STRARRAY, "$string:" },
{ ResType::COLOR, "$color:" },
{ ResType::FLOAT, "$float:" }
{ ResType::STRING, "\\$(ohos:)?string:" },
{ ResType::STRARRAY, "\\$(ohos:)?string:" },
{ ResType::COLOR, "\\$(ohos:)?color:" },
{ ResType::FLOAT, "\\$(ohos:)?float:" }
};
string value = valueNode.asString();
ResType type = resourceItem.GetResType();
regex ref("^\\$.+:");
smatch result;
if (regex_search(value, result, ref) && result[0] != REFS.at(type)) {
if (regex_search(value, result, ref) && !regex_match(result[0].str(), regex(REFS.at(type)))) {
cerr << "Error: '" << value << "' only refer '"<< REFS.at(type) << "xxx',";
cerr << resourceItem.GetFilePath() << endl;
return false;
@@ -311,7 +311,7 @@ bool JsonCompiler::CheckJsonStringValue(const Json::Value &valueNode, const Reso
bool JsonCompiler::CheckJsonIntegerValue(const Json::Value &valueNode, const ResourceItem &resourceItem) const
{
if (valueNode.isString()) {
regex ref("^\\$integer:.*");
regex ref("^\\$(ohos:)?integer:.*");
if (!regex_match(valueNode.asString(), ref)) {
cerr << "Error: '" << valueNode.asString() << "' only refer '$integer:xxx',";
cerr << resourceItem.GetFilePath() << endl;
+2 -2
View File
@@ -87,9 +87,9 @@ uint32_t ReferenceParser::ParseRefInSolidXml(const vector<string> &solidXmlFolde
return RESTOOL_SUCCESS;
}
uint32_t ReferenceParser::ParseRefInElement(map<int32_t, vector<ResourceItem>> &alls) const
uint32_t ReferenceParser::ParseRefInElement(map<int32_t, vector<ResourceItem>> &items) const
{
for (auto &iter : alls) {
for (auto &iter : items) {
for (auto &resourceItem : iter.second) {
if (IsNotElement(resourceItem.GetResType())) {
break;
+1 -1
View File
@@ -123,7 +123,7 @@ uint32_t ResourcePack::InitModule()
}
int32_t startId = ((it - moduleNames.begin()) + 1) * 0x01000000;
if (startId == 0x07000000) {
if (startId >= 0x07000000) {
startId = startId + 0x01000000;
}
return idWorker.Init(hapType, startId);
+2 -1
View File
@@ -75,7 +75,7 @@ bool ResourceUtil::OpenJsonFile(const string &path, Json::Value &root)
{
ifstream ifs(path, ios::binary);
if (!ifs) {
cerr << "Error: open json faild '" << path << "'" << endl;
cerr << "Error: open json failed '" << path << "'" << endl;
return false;
}
@@ -236,6 +236,7 @@ bool ResourceUtil::CreateDirs(const string &filePath)
if (!FileEntry::CreateDirs(filePath)) {
cerr << "Error: create dir fail '" << filePath << "'" << endl;
return false;
}
return true;
}
+4
View File
@@ -33,6 +33,10 @@ uint32_t PackCmdHandle(PackageParser &packageParser)
int main(int argc, char *argv[])
{
if (argv == nullptr) {
cerr << "Error: argv null" << endl;
return RESTOOL_ERROR;
}
auto &parser = CmdParser<PackageParser>::GetInstance();
if (parser.Parse(argc, argv) != RESTOOL_SUCCESS) {
parser.ShowUseage();
+6 -1
View File
@@ -43,9 +43,14 @@ bool SolidXml::GenerateSolidXml(const string &filePath)
return false;
}
xmlNodePtr rootNode = xmlDocGetRootElement(doc);
if (rootNode == nullptr) {
xmlFreeDoc(doc);
return false;
}
auto root = make_shared<XmlNode>();
nodes_.push_back(root);
Compile(xmlDocGetRootElement(doc), root);
Compile(rootNode, root);
xmlFreeDoc(doc);
return SaveToFile(filePath);
}