!12 适配BUILD.gn脚本

Merge pull request !12 from 陈程/master
This commit is contained in:
openharmony_sig_ci
2022-03-10 15:40:25 +00:00
committed by Gitee
46 changed files with 1846 additions and 287 deletions
+85
View File
@@ -0,0 +1,85 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# 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.
import("//build/ohos.gni")
import("//build/test.gni")
ohos_executable("restool") {
sources = [
"src/xml/key_manager.cpp",
"src/xml/solid_xml.cpp",
"src/xml/xml_converter.cpp",
"src/xml/xml_key_node.cpp",
"src/cmd_list.cpp",
"src/cmd_parser.cpp",
"src/config_parser.cpp",
"src/factory_resource_compiler.cpp",
"src/file_entry.cpp",
"src/file_manager.cpp",
"src/generic_compiler.cpp",
"src/header.cpp",
"src/i_resource_compiler.cpp",
"src/id_worker.cpp",
"src/increment_index.cpp",
"src/increment_list.cpp",
"src/increment_manager.cpp",
"src/json_compiler.cpp",
"src/key_parser.cpp",
"src/module_combine.cpp",
"src/preview_manager.cpp",
"src/reference_parser.cpp",
"src/resource_directory.cpp",
"src/resource_item.cpp",
"src/resource_merge.cpp",
"src/resource_module.cpp",
"src/resource_module_inc.cpp",
"src/resource_pack.cpp",
"src/resource_table.cpp",
"src/resource_util.cpp",
"src/restool.cpp",
"src/solid_xml_compiler.cpp",
"src/sqlite_database.cpp",
"src/task_handle.cpp"
]
include_dirs = []
if (is_mingw) {
include_dirs += [
"//developtools/global_resource_tool/build/libxml2/win32/include"
]
}
include_dirs += [
"include",
"//third_party/libxml2/include",
"//third_party/jsoncpp/include",
"//third_party/sqlite/include",
"//third_party/bounds_checking_function/include"
]
deps = [
"//developtools/global_resource_tool/build/jsoncpp:restool_jsoncpp",
"//developtools/global_resource_tool/build/sqlite3:restool_sqlite",
"//developtools/global_resource_tool/build/libxml2:restool_libxml2",
"//developtools/global_resource_tool/build/bounds_checking_function:restool_bounds_checking_function"
]
cflags = [ "-std=c++17" ]
if (is_mingw) {
ldflags = [ "-static", "-lws2_32" ]
}
subsystem_name = "developtools"
part_name = "global_restool"
}
ohos_unittest_py("restool_test") {
sources = [ "test/test.py" ]
}
+5 -5
View File
@@ -22,7 +22,7 @@ set(sqlite3_dir ${CMAKE_SOURCE_DIR}/../../third_party/sqlite)
include_directories(include)
include_directories(${jsoncpp_dir}/include)
include_directories(${bound_checking_function_dir}/include)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/third_party/libxml2/libxml2/include)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/build/libxml2/include)
include_directories(${sqlite3_dir}/include)
aux_source_directory(src restool_source)
@@ -31,7 +31,7 @@ aux_source_directory(src/xml restool_source)
add_executable(restool ${restool_source})
target_link_libraries(restool myxml2 jsoncpp securec sqlite3)
add_subdirectory(third_party/libxml2)
add_subdirectory(third_party/jsoncpp)
add_subdirectory(third_party/bounds_checking_function)
add_subdirectory(third_party/sqlite3)
add_subdirectory(build/libxml2)
add_subdirectory(build/jsoncpp)
add_subdirectory(build/bounds_checking_function)
add_subdirectory(build/sqlite3)
+39 -80
View File
@@ -1,80 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
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.
This is the configuration file template for OpenHarmony OSS Audit Tool, please copy it to your project root dir and modify it refer to OpenHarmony/tools_oat/README.
All configurations in this file will be merged to OAT-Default.xml, if you have any questions or concerns, please create issue in OpenHarmony/tools_oat and @jalenchen or chenyaxun.
licensefile:
1.If the project don't have "LICENSE" in root dir, please define all the license files in this project in , OAT will check license files according to this rule.
policylist:
1. policy: If the OAT-Default.xml policies do not meet your requirements, please add policies here.
2. policyitem: The fields type, name, path, desc is required, and the fields rule, group, filefilter is optional,the default value is:
<policyitem type="" name="" path="" desc="" rule="may" group="defaultGroup" filefilter="defaultPolicyFilter"/>
3. policyitem type:
"compatibility" is used to check license compatibility in the specified path;
"license" is used to check source license header in the specified path;
"copyright" is used to check source copyright header in the specified path;
"import" is used to check source dependency in the specified path, such as import ... ,include ...
"filetype" is used to check file type in the specified path, supported file types: archive, binary
"filename" is used to check whether the specified file exists in the specified path(projectroot means the root dir of the project), supported file names: LICENSE, README, README.OpenSource
4. policyitem name: This field is used for define the license, copyright, "*" means match all, the "!" prefix means could not match this value. For example, "!GPL" means can not use GPL license.
5. policyitem path: This field is used for define the source file scope to apply this policyitem, the "!" prefix means exclude the files. For example, "!.*/lib/.*" means files in lib dir will be exclude while process this policyitem.
6. policyitem rule and group: These two fields are used together to merge policy results. "may" policyitems in the same group means any one in this group passed, the result will be passed.
7. policyitem filefilter: Used to bind filefilter which define filter rules.
7. policyitem desc: Used to describe the reason of this policy item, committers will check this while merging the code.
8. filefilter: Filter rules, the type filename is used to filter file name, the type filepath is used to filter file path.
Note:If the text contains special characters, please escape them according to the following rules:
" == &quot;
& == &amp;
' == &apos;
< == &lt;
> == &gt;
-->
<configuration>
<oatconfig>
<licensefile></licensefile>
<policylist>
<policy name="projectPolicy" desc="">
</policy>
</policylist>
<filefilterlist>
<filefilter name="defaultFilter" desc="Files not to check">
<filteritem type="filename" name="*.iml|*.json|*.txt" desc="desc files"/>
<filteritem type="filepath" name="target/.*" desc="Compile output files"/>
<filteritem type="filepath" name="out/.*" desc="Compile output files"/>
<filteritem type="filepath" name="log/.*" desc="log files"/>
<filteritem type="filepath" name=".idea/.*" desc="IDE temp files"/>
<filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/>
<filteritem type="filepath" name="src/test/.*" desc="Test files"/>
</filefilter>
<filefilter name="defaultPolicyFilter" desc="Filters for compatibilitylicense header policies">
</filefilter>
<filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">
</filefilter>
<filefilter name="licenseFileNamePolicyFilter" desc="Filters for LICENSE file policies">
</filefilter>
<filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies">
</filefilter>
<filefilter name="readmeOpenSourcefileNamePolicyFilter" desc="Filters for README.OpenSource file policies">
</filefilter>
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies">
</filefilter>
</filefilterlist>
</oatconfig>
</configuration>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
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.
This is the configuration file template for OpenHarmony OSS Audit Tool, please copy it to your project root dir and modify it refer to OpenHarmony/tools_oat/README.
-->
<configuration>
<oatconfig>
<licensefile></licensefile>
<policylist>
<policy name="projectPolicy" desc="">
</policy>
</policylist>
<filefilterlist>
<filefilter name="defaultFilter" desc="Files not to check">
<filteritem type="filepath" name=".*.png" desc="Temp files"/>
</filefilter>
<filefilter name="defaultPolicyFilter" desc="Filters for compatibilitylicense header policies">
<filteritem type="filepath" name="build/libxml2/win32/include/libxml/xmlversion.h" desc="NoLicenseHeader"/>
</filefilter>
<filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">
<filteritem type="filepath" name="build/libxml2/win32/include/libxml/xmlversion.h" desc="InvalidCopyright file"/>
</filefilter>
</filefilterlist>
</oatconfig>
</configuration>
+24 -9
View File
@@ -10,22 +10,37 @@ restool(resource tool) is used in computer.In OpenHarmony SDK toolchain.When IDE
|----global_resource_tool
| |----include
| |----src
| |----third_party dependence third patry lib make script
| |----test
| |----build dependence third patry lib make script
| |----CMakeLists.txt
| |----BUILD.gn
| |----win32.cmake windows cross compile script
```
## Instructions
### Compile
### Quickly Build
1. gcc/g++ version 9.3.0 required
2. cmake version mini 3.15 required
3. mkdir build
4. cd build
5. cmake ../restool_standard
6. make
7. compile result restool binary
1. ubuntu 18 preinstalled gcc/g++
2. cmake version mini 3.15 required
3. mkdir build
4. cd build
5. cmake ../global_resource_tool
6. make
7. compile result restool binary
### SDK Build
1. ./build.sh --product-name ohos-sdk
SDK build refer to https://gitee.com/openharmony/build/blob/master/README_zh.md
### Test
1.in PC, run python test/test.py param1 param2
param1: restool path
param2: result path
### Help
+24 -9
View File
@@ -10,22 +10,37 @@
|----global_resource_tool
| |----include
| |----src
| |----third_party 依赖三方库编译脚本
| |----test
| |----build 依赖三方库编译脚本
| |----BUILD.gn
| |----CMakeLists.txt
| |----win32.cmake windows交叉编译脚本
```
## 使用说明
### 代码编译命令
### 快速调试编译
1. 编译环境gcc/g++ 9.3.0
2. cmake 版本最低3.15
3. 与global_resource_tool同级目录新建build
4. cd build
5. cmake ../global_resource_tool
6. make
7. 编译结果输出restool
1. ubuntu 18 系统预装 gcc/g++
2. cmake 版本最低3.15
3. 与global_resource_tool同级目录新建build
4. cd build
5. cmake ../global_resource_tool
6. make
7. 编译结果输出restool
### SDK编译命令
1. ./build.sh --product-nane ohos-sdk
SDK 编译参考https://gitee.com/openharmony/build/blob/master/README_zh.md 仓编译sdk说明。
### 测试用例
1.PC 上运行 python test/test.py 参数1 参数2
参数1 restool 命令路径
参数2 输出结果路径
### 命令帮助
+37
View File
@@ -0,0 +1,37 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# 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.
import("//build/ohos.gni")
import("//third_party/bounds_checking_function/libsec_src.gni")
ohos_static_library("restool_bounds_checking_function") {
sources = libsec_sources
include_dirs = [
"//third_party/bounds_checking_function/include"
]
cflags_cc = [ "-std=c++17" ]
cflags_c =[
"-Wno-attributes",
"-Wno-inconsistent-dllimport",
"-D_INC_STRING_S",
"-D_INC_WCHAR_S",
"-D_SECIMP=//",
"-D_STDIO_S_DEFINED",
"-D_INC_STDIO_S",
"-D_INC_STDLIB_S",
"-D_INC_MEMORY_S"
]
subsystem_name = "developtools"
part_name = "global_restool"
}
+30
View File
@@ -0,0 +1,30 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# 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.
import("//build/ohos.gni")
ohos_static_library("restool_jsoncpp") {
sources = [
"//third_party/jsoncpp/src/lib_json/json_reader.cpp",
"//third_party/jsoncpp/src/lib_json/json_value.cpp",
"//third_party/jsoncpp/src/lib_json/json_writer.cpp"
]
include_dirs = [
"//third_party/jsoncpp/include"
]
cflags = [ "-std=c++17" ]
use_exceptions = true
subsystem_name = "developtools"
part_name = "global_restool"
}
+143
View File
@@ -0,0 +1,143 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# 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.
import("//build/ohos.gni")
LIBXML_PATH = "//third_party/libxml2"
config("restool_libxml2_config") {
include_dirs = []
if (is_mingw) {
include_dirs += [
"//developtools/global_resource_tool/build/libxml2/win32/include"
]
defines = [ "LIBXML_STATIC"]
} else {
include_dirs += [
"${LIBXML_PATH}/config"
]
}
include_dirs += [
"${LIBXML_PATH}/include"
]
cflags_cc = [
"-std=c++17"
]
cflags_c = [
"-Wno-implicit-fallthrough",
"-Wno-implicit-function-declaration",
"-Wno-int-conversion"
]
}
ohos_static_library("restool_libxml2") {
sources = [
"${LIBXML_PATH}/DOCBparser.c",
"${LIBXML_PATH}/HTMLparser.c",
"${LIBXML_PATH}/HTMLtree.c",
"${LIBXML_PATH}/SAX.c",
"${LIBXML_PATH}/SAX2.c",
"${LIBXML_PATH}/buf.c",
"${LIBXML_PATH}/c14n.c",
"${LIBXML_PATH}/catalog.c",
"${LIBXML_PATH}/chvalid.c",
"${LIBXML_PATH}/debugXML.c",
"${LIBXML_PATH}/dict.c",
"${LIBXML_PATH}/encoding.c",
"${LIBXML_PATH}/entities.c",
"${LIBXML_PATH}/error.c",
"${LIBXML_PATH}/globals.c",
"${LIBXML_PATH}/hash.c",
"${LIBXML_PATH}/include/libxml/DOCBparser.h",
"${LIBXML_PATH}/include/libxml/HTMLparser.h",
"${LIBXML_PATH}/include/libxml/HTMLtree.h",
"${LIBXML_PATH}/include/libxml/SAX.h",
"${LIBXML_PATH}/include/libxml/SAX2.h",
"${LIBXML_PATH}/include/libxml/c14n.h",
"${LIBXML_PATH}/include/libxml/catalog.h",
"${LIBXML_PATH}/include/libxml/chvalid.h",
"${LIBXML_PATH}/include/libxml/debugXML.h",
"${LIBXML_PATH}/include/libxml/dict.h",
"${LIBXML_PATH}/include/libxml/encoding.h",
"${LIBXML_PATH}/include/libxml/entities.h",
"${LIBXML_PATH}/include/libxml/globals.h",
"${LIBXML_PATH}/include/libxml/hash.h",
"${LIBXML_PATH}/include/libxml/list.h",
"${LIBXML_PATH}/include/libxml/nanoftp.h",
"${LIBXML_PATH}/include/libxml/nanohttp.h",
"${LIBXML_PATH}/include/libxml/parser.h",
"${LIBXML_PATH}/include/libxml/parserInternals.h",
"${LIBXML_PATH}/include/libxml/pattern.h",
"${LIBXML_PATH}/include/libxml/relaxng.h",
"${LIBXML_PATH}/include/libxml/schemasInternals.h",
"${LIBXML_PATH}/include/libxml/schematron.h",
"${LIBXML_PATH}/include/libxml/threads.h",
"${LIBXML_PATH}/include/libxml/tree.h",
"${LIBXML_PATH}/include/libxml/uri.h",
"${LIBXML_PATH}/include/libxml/valid.h",
"${LIBXML_PATH}/include/libxml/xinclude.h",
"${LIBXML_PATH}/include/libxml/xlink.h",
"${LIBXML_PATH}/include/libxml/xmlIO.h",
"${LIBXML_PATH}/include/libxml/xmlautomata.h",
"${LIBXML_PATH}/include/libxml/xmlerror.h",
"${LIBXML_PATH}/include/libxml/xmlexports.h",
"${LIBXML_PATH}/include/libxml/xmlmemory.h",
"${LIBXML_PATH}/include/libxml/xmlmodule.h",
"${LIBXML_PATH}/include/libxml/xmlreader.h",
"${LIBXML_PATH}/include/libxml/xmlregexp.h",
"${LIBXML_PATH}/include/libxml/xmlsave.h",
"${LIBXML_PATH}/include/libxml/xmlschemas.h",
"${LIBXML_PATH}/include/libxml/xmlschemastypes.h",
"${LIBXML_PATH}/include/libxml/xmlstring.h",
"${LIBXML_PATH}/include/libxml/xmlunicode.h",
"${LIBXML_PATH}/include/libxml/xmlwriter.h",
"${LIBXML_PATH}/include/libxml/xpath.h",
"${LIBXML_PATH}/include/libxml/xpathInternals.h",
"${LIBXML_PATH}/include/libxml/xpointer.h",
"${LIBXML_PATH}/legacy.c",
"${LIBXML_PATH}/list.c",
"${LIBXML_PATH}/nanoftp.c",
"${LIBXML_PATH}/nanohttp.c",
"${LIBXML_PATH}/parser.c",
"${LIBXML_PATH}/parserInternals.c",
"${LIBXML_PATH}/pattern.c",
"${LIBXML_PATH}/relaxng.c",
"${LIBXML_PATH}/schematron.c",
"${LIBXML_PATH}/threads.c",
"${LIBXML_PATH}/tree.c",
"${LIBXML_PATH}/uri.c",
"${LIBXML_PATH}/valid.c",
"${LIBXML_PATH}/xinclude.c",
"${LIBXML_PATH}/xlink.c",
"${LIBXML_PATH}/xmlIO.c",
"${LIBXML_PATH}/xmlmemory.c",
"${LIBXML_PATH}/xmlmodule.c",
"${LIBXML_PATH}/xmlreader.c",
"${LIBXML_PATH}/xmlregexp.c",
"${LIBXML_PATH}/xmlsave.c",
"${LIBXML_PATH}/xmlschemas.c",
"${LIBXML_PATH}/xmlschemastypes.c",
"${LIBXML_PATH}/xmlstring.c",
"${LIBXML_PATH}/xmlunicode.c",
"${LIBXML_PATH}/xmlwriter.c",
"${LIBXML_PATH}/xpath.c",
"${LIBXML_PATH}/xpointer.c",
"${LIBXML_PATH}/xzlib.c"
]
public_configs = [ ":restool_libxml2_config" ]
subsystem_name = "developtools"
part_name = "global_restool"
}
@@ -1,9 +1,22 @@
cmake_minimum_required(VERSION 3.15)
project(myxml2 LANGUAGES C)
#include(CheckCSourceCompiles)
#include(CheckIncludeFiles)
#include(CheckStructHasMember)
#include(CheckFunctionExists)
#include(CheckLibraryExists)
#include(CheckSymbolExists)
include(CheckCSourceCompiles)
include(CheckIncludeFiles)
include(CheckStructHasMember)
include(CheckFunctionExists)
include(CheckIncludeFiles)
include(CheckIncludeFile)
include(CheckLibraryExists)
include(CheckStructHasMember)
include(CheckSymbolExists)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
set(LIBXML2_WITH_AUTOMATA ON)
@@ -77,7 +90,7 @@ if(NOT GETHOSTBYNAME_ARG_CAST_CONST)
else()
set(GETHOSTBYNAME_ARG_CAST "/**/")
endif()
check_include_files(arpa/inet.h HAVE_ARPA_INET_H)
CHECK_INCLUDE_FILE(arpa/inet.h HAVE_ARPA_INET_H)
check_include_files(arpa/nameser.h HAVE_ARPA_NAMESER_H)
check_struct_has_member("struct sockaddr_storage" ss_family "sys/socket.h;sys/types.h" HAVE_SS_FAMILY)
check_struct_has_member("struct sockaddr_storage" __ss_family "sys/socket.h;sys/types.h" HAVE_BROKEN_SS_FAMILY)
@@ -337,6 +350,8 @@ set(libxml2_original_source
${libxml2_original}/xzlib.c
)
#set(CMAKE_THREAD_LIBS_INIT "-lpthread")
#message("pthread " ${CMAKE_THREAD_LIBS_INIT})
find_package(Threads REQUIRED)
add_library(myxml2 STATIC ${libxml2_original_header} ${libxml2_original_other_header} ${libxml2_original_source})
target_link_libraries(myxml2 PRIVATE Threads::Threads)
@@ -345,4 +360,7 @@ if(WIN32)
target_link_libraries(myxml2 PRIVATE ws2_32)
set(WIN32_EXTRA_LIBADD "-lws2_32")
endif()
configure_file(${libxml2_original}/include/libxml/xmlversion.h.in ${libxml2_original}/include/libxml/xmlversion.h)
configure_file(${libxml2_original}/include/libxml/xmlversion.h.in ${libxml2_original}/include/libxml/xmlversion.h)
file(COPY ${libxml2_original_header} DESTINATION ./include/libxml)
file(COPY ${libxml2_original}/include/libxml/xmlversion.h DESTINATION ./include/libxml)
+288
View File
@@ -0,0 +1,288 @@
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
/* Define if __attribute__((destructor)) is accepted */
#define ATTRIBUTE_DESTRUCTOR 1
/* Type cast for the gethostbyname() argument */
#define GETHOSTBYNAME_ARG_CAST (char *)
/* Define to 1 if you have the <arpa/inet.h> header file. */
/* #undef HAVE_ARPA_INET_H */
/* Define to 1 if you have the <arpa/nameser.h> header file. */
/* #undef HAVE_ARPA_NAMESER_H */
/* Whether struct sockaddr::__ss_family exists */
/* #undef HAVE_BROKEN_SS_FAMILY */
/* Define to 1 if you have the <ctype.h> header file. */
#define HAVE_CTYPE_H 1
/* Define to 1 if you have the <dirent.h> header file. */
#define HAVE_DIRENT_H 1
/* Define to 1 if you have the <dlfcn.h> header file. */
/* #undef HAVE_DLFCN_H */
/* Have dlopen based dso */
/* #undef HAVE_DLOPEN */
/* Define to 1 if you have the <dl.h> header file. */
/* #undef HAVE_DL_H */
/* Define to 1 if you have the <errno.h> header file. */
#define HAVE_ERRNO_H 1
/* Define to 1 if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
/* Define to 1 if you have the <float.h> header file. */
#define HAVE_FLOAT_H 1
/* Define to 1 if you have the `fprintf' function. */
#define HAVE_FPRINTF 1
/* Define to 1 if you have the `ftime' function. */
#define HAVE_FTIME 1
/* Define if getaddrinfo is there */
/* #undef HAVE_GETADDRINFO */
/* Define to 1 if you have the `gettimeofday' function. */
#define HAVE_GETTIMEOFDAY 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the `isascii' function. */
#define HAVE_ISASCII 1
/* Define if isinf is there */
/* #undef HAVE_ISINF */
/* Define if isnan is there */
#define HAVE_ISNAN 1
/* Define if history library is there (-lhistory) */
/* #undef HAVE_LIBHISTORY */
/* Define if pthread library is there (-lpthread) */
#define HAVE_LIBPTHREAD 1
/* Define if readline library is there (-lreadline) */
/* #undef HAVE_LIBREADLINE */
/* Define to 1 if you have the <limits.h> header file. */
#define HAVE_LIMITS_H 1
/* Define to 1 if you have the `localtime' function. */
#define HAVE_LOCALTIME 1
/* Define to 1 if you have the <lzma.h> header file. */
/* #undef HAVE_LZMA_H */
/* Define to 1 if you have the <malloc.h> header file. */
#define HAVE_MALLOC_H 1
/* Define to 1 if you have the <math.h> header file. */
#define HAVE_MATH_H 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the `mmap' function. */
/* #undef HAVE_MMAP */
/* Define to 1 if you have the `munmap' function. */
/* #undef HAVE_MUNMAP */
/* mmap() is no good without munmap() */
#if defined(HAVE_MMAP) && !defined(HAVE_MUNMAP)
# undef /**/ HAVE_MMAP
#endif
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
/* #undef HAVE_NDIR_H */
/* Define to 1 if you have the <netdb.h> header file. */
/* #undef HAVE_NETDB_H */
/* Define to 1 if you have the <netinet/in.h> header file. */
/* #undef HAVE_NETINET_IN_H */
/* Define to 1 if you have the <poll.h> header file. */
/* #undef HAVE_POLL_H */
/* Define to 1 if you have the `printf' function. */
#define HAVE_PRINTF 1
/* Define if <pthread.h> is there */
#define HAVE_PTHREAD_H 1
/* Define to 1 if you have the `putenv' function. */
#define HAVE_PUTENV 1
/* Define to 1 if you have the `rand' function. */
#define HAVE_RAND 1
/* Define to 1 if you have the `rand_r' function. */
/* #undef HAVE_RAND_R */
/* Define to 1 if you have the <resolv.h> header file. */
/* #undef HAVE_RESOLV_H */
/* Have shl_load based dso */
/* #undef HAVE_SHLLOAD */
/* Define to 1 if you have the `signal' function. */
#define HAVE_SIGNAL 1
/* Define to 1 if you have the <signal.h> header file. */
#define HAVE_SIGNAL_H 1
/* Define to 1 if you have the `snprintf' function. */
#define HAVE_SNPRINTF 1
/* Define to 1 if you have the `sprintf' function. */
#define HAVE_SPRINTF 1
/* Define to 1 if you have the `srand' function. */
#define HAVE_SRAND 1
/* Define to 1 if you have the `sscanf' function. */
#define HAVE_SSCANF 1
/* Define to 1 if you have the `stat' function. */
#define HAVE_STAT 1
/* Define to 1 if you have the <stdarg.h> header file. */
#define HAVE_STDARG_H 1
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the `strftime' function. */
#define HAVE_STRFTIME 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
*/
/* #undef HAVE_SYS_DIR_H */
/* Define to 1 if you have the <sys/mman.h> header file. */
/* #undef HAVE_SYS_MMAN_H */
/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
*/
/* #undef HAVE_SYS_NDIR_H */
/* Define to 1 if you have the <sys/select.h> header file. */
/* #undef HAVE_SYS_SELECT_H */
/* Define to 1 if you have the <sys/socket.h> header file. */
/* #undef HAVE_SYS_SOCKET_H */
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/timeb.h> header file. */
#define HAVE_SYS_TIMEB_H 1
/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the `time' function. */
#define HAVE_TIME 1
/* Define to 1 if you have the <time.h> header file. */
#define HAVE_TIME_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Whether va_copy() is available */
/* #undef HAVE_VA_COPY */
/* Define to 1 if you have the `vfprintf' function. */
#define HAVE_VFPRINTF 1
/* Define to 1 if you have the `vsnprintf' function. */
#define HAVE_VSNPRINTF 1
/* Define to 1 if you have the `vsprintf' function. */
#define HAVE_VSPRINTF 1
/* Define to 1 if you have the <zlib.h> header file. */
/* #undef HAVE_ZLIB_H */
/* Whether __va_copy() is available */
/* #undef HAVE___VA_COPY */
/* Define as const if the declaration of iconv() needs const. */
#define ICONV_CONST const
/* Define to the sub-directory where libtool stores uninstalled libraries. */
#define LT_OBJDIR ".libs/"
/* Name of package */
#define PACKAGE ""
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""
/* Define to the full name of this package. */
#define PACKAGE_NAME ""
/* Define to the full name and version of this package. */
#define PACKAGE_STRING ""
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME ""
/* Define to the home page for this package. */
#define PACKAGE_URL ""
/* Define to the version of this package. */
#define PACKAGE_VERSION ""
/* Type cast for the send() function 2nd arg */
#define SEND_ARG2_CAST (char *)
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Support for IPv6 */
/* #undef SUPPORT_IP6 */
/* Define if va_list is an array type */
/* #undef VA_LIST_IS_ARRAY */
/* Version number of package */
#define VERSION "2.9.10"
/* Determine what socket length (socklen_t) data type is */
#define XML_SOCKLEN_T int
/* Define for Solaris 2.5.1 so the uint32_t typedef from <sys/synch.h>,
<pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
#define below would cause a syntax error. */
/* #undef _UINT32_T */
/* ss_family is not defined here, use __ss_family instead */
/* #undef ss_family */
/* Define to the type of an unsigned integer type of width exactly 32 bits if
such a type exists and the standard includes do not define it. */
/* #undef uint32_t */
@@ -0,0 +1,485 @@
/*
* Summary: compile-time version informations
* Description: compile-time version informations for the XML library
*
* Copy: See Copyright for the status of this software.
*
* Author: Daniel Veillard
*/
#ifndef __XML_VERSION_H__
#define __XML_VERSION_H__
#include <libxml/xmlexports.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* use those to be sure nothing nasty will happen if
* your library and includes mismatch
*/
#ifndef LIBXML2_COMPILING_MSCCDEF
XMLPUBFUN void XMLCALL xmlCheckVersion(int version);
#endif /* LIBXML2_COMPILING_MSCCDEF */
/**
* LIBXML_DOTTED_VERSION:
*
* the version string like "1.2.3"
*/
#define LIBXML_DOTTED_VERSION "2.9.10"
/**
* LIBXML_VERSION:
*
* the version number: 1.2.3 value is 10203
*/
#define LIBXML_VERSION 209010
/**
* LIBXML_VERSION_STRING:
*
* the version number string, 1.2.3 value is "10203"
*/
#define LIBXML_VERSION_STRING "209010"
/**
* LIBXML_VERSION_EXTRA:
*
* extra version information, used to show a CVS compilation
*/
#define LIBXML_VERSION_EXTRA ""
/**
* LIBXML_TEST_VERSION:
*
* Macro to check that the libxml version in use is compatible with
* the version the software has been compiled against
*/
#define LIBXML_TEST_VERSION xmlCheckVersion(209010);
#ifndef VMS
#if 0
/**
* WITH_TRIO:
*
* defined if the trio support need to be configured in
*/
#define WITH_TRIO
#else
/**
* WITHOUT_TRIO:
*
* defined if the trio support should not be configured in
*/
#define WITHOUT_TRIO
#endif
#else /* VMS */
/**
* WITH_TRIO:
*
* defined if the trio support need to be configured in
*/
#define WITH_TRIO 1
#endif /* VMS */
/**
* LIBXML_THREAD_ENABLED:
*
* Whether the thread support is configured in
*/
#if 1
#define LIBXML_THREAD_ENABLED
#endif
/**
* LIBXML_THREAD_ALLOC_ENABLED:
*
* Whether the allocation hooks are per-thread
*/
#if 0
#define LIBXML_THREAD_ALLOC_ENABLED
#endif
/**
* LIBXML_TREE_ENABLED:
*
* Whether the DOM like tree manipulation API support is configured in
*/
#if 1
#define LIBXML_TREE_ENABLED
#endif
/**
* LIBXML_OUTPUT_ENABLED:
*
* Whether the serialization/saving support is configured in
*/
#if 1
#define LIBXML_OUTPUT_ENABLED
#endif
/**
* LIBXML_PUSH_ENABLED:
*
* Whether the push parsing interfaces are configured in
*/
#if 1
#define LIBXML_PUSH_ENABLED
#endif
/**
* LIBXML_READER_ENABLED:
*
* Whether the xmlReader parsing interface is configured in
*/
#if 1
#define LIBXML_READER_ENABLED
#endif
/**
* LIBXML_PATTERN_ENABLED:
*
* Whether the xmlPattern node selection interface is configured in
*/
#if 1
#define LIBXML_PATTERN_ENABLED
#endif
/**
* LIBXML_WRITER_ENABLED:
*
* Whether the xmlWriter saving interface is configured in
*/
#if 1
#define LIBXML_WRITER_ENABLED
#endif
/**
* LIBXML_SAX1_ENABLED:
*
* Whether the older SAX1 interface is configured in
*/
#if 1
#define LIBXML_SAX1_ENABLED
#endif
/**
* LIBXML_FTP_ENABLED:
*
* Whether the FTP support is configured in
*/
#if 1
#define LIBXML_FTP_ENABLED
#endif
/**
* LIBXML_HTTP_ENABLED:
*
* Whether the HTTP support is configured in
*/
#if 1
#define LIBXML_HTTP_ENABLED
#endif
/**
* LIBXML_VALID_ENABLED:
*
* Whether the DTD validation support is configured in
*/
#if 1
#define LIBXML_VALID_ENABLED
#endif
/**
* LIBXML_HTML_ENABLED:
*
* Whether the HTML support is configured in
*/
#if 1
#define LIBXML_HTML_ENABLED
#endif
/**
* LIBXML_LEGACY_ENABLED:
*
* Whether the deprecated APIs are compiled in for compatibility
*/
#if 1
#define LIBXML_LEGACY_ENABLED
#endif
/**
* LIBXML_C14N_ENABLED:
*
* Whether the Canonicalization support is configured in
*/
#if 1
#define LIBXML_C14N_ENABLED
#endif
/**
* LIBXML_CATALOG_ENABLED:
*
* Whether the Catalog support is configured in
*/
#if 1
#define LIBXML_CATALOG_ENABLED
#endif
/**
* LIBXML_DOCB_ENABLED:
*
* Whether the SGML Docbook support is configured in
*/
#if 1
#define LIBXML_DOCB_ENABLED
#endif
/**
* LIBXML_XPATH_ENABLED:
*
* Whether XPath is configured in
*/
#if 1
#define LIBXML_XPATH_ENABLED
#endif
/**
* LIBXML_XPTR_ENABLED:
*
* Whether XPointer is configured in
*/
#if 1
#define LIBXML_XPTR_ENABLED
#endif
/**
* LIBXML_XINCLUDE_ENABLED:
*
* Whether XInclude is configured in
*/
#if 1
#define LIBXML_XINCLUDE_ENABLED
#endif
/**
* LIBXML_ICONV_ENABLED:
*
* Whether iconv support is available
*/
#if 0
#define LIBXML_ICONV_ENABLED
#endif
/**
* LIBXML_ICU_ENABLED:
*
* Whether icu support is available
*/
#if 0
#define LIBXML_ICU_ENABLED
#endif
/**
* LIBXML_ISO8859X_ENABLED:
*
* Whether ISO-8859-* support is made available in case iconv is not
*/
#if 1
#define LIBXML_ISO8859X_ENABLED
#endif
/**
* LIBXML_DEBUG_ENABLED:
*
* Whether Debugging module is configured in
*/
#if 1
#define LIBXML_DEBUG_ENABLED
#endif
/**
* DEBUG_MEMORY_LOCATION:
*
* Whether the memory debugging is configured in
*/
#if 0
#define DEBUG_MEMORY_LOCATION
#endif
/**
* LIBXML_DEBUG_RUNTIME:
*
* Whether the runtime debugging is configured in
*/
#if 0
#define LIBXML_DEBUG_RUNTIME
#endif
/**
* LIBXML_UNICODE_ENABLED:
*
* Whether the Unicode related interfaces are compiled in
*/
#if 1
#define LIBXML_UNICODE_ENABLED
#endif
/**
* LIBXML_REGEXP_ENABLED:
*
* Whether the regular expressions interfaces are compiled in
*/
#if 1
#define LIBXML_REGEXP_ENABLED
#endif
/**
* LIBXML_AUTOMATA_ENABLED:
*
* Whether the automata interfaces are compiled in
*/
#if 1
#define LIBXML_AUTOMATA_ENABLED
#endif
/**
* LIBXML_EXPR_ENABLED:
*
* Whether the formal expressions interfaces are compiled in
*
* This code is unused and disabled unconditionally for now.
*/
#if 0
#define LIBXML_EXPR_ENABLED
#endif
/**
* LIBXML_SCHEMAS_ENABLED:
*
* Whether the Schemas validation interfaces are compiled in
*/
#if 1
#define LIBXML_SCHEMAS_ENABLED
#endif
/**
* LIBXML_SCHEMATRON_ENABLED:
*
* Whether the Schematron validation interfaces are compiled in
*/
#if 1
#define LIBXML_SCHEMATRON_ENABLED
#endif
/**
* LIBXML_MODULES_ENABLED:
*
* Whether the module interfaces are compiled in
*/
#if 1
#define LIBXML_MODULES_ENABLED
/**
* LIBXML_MODULE_EXTENSION:
*
* the string suffix used by dynamic modules (usually shared libraries)
*/
#define LIBXML_MODULE_EXTENSION ""
#endif
/**
* LIBXML_ZLIB_ENABLED:
*
* Whether the Zlib support is compiled in
*/
#if 0
#define LIBXML_ZLIB_ENABLED
#endif
/**
* LIBXML_LZMA_ENABLED:
*
* Whether the Lzma support is compiled in
*/
#if 0
#define LIBXML_LZMA_ENABLED
#endif
#ifdef __GNUC__
/**
* ATTRIBUTE_UNUSED:
*
* Macro used to signal to GCC unused function parameters
*/
#ifndef ATTRIBUTE_UNUSED
# if ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 7)))
# define ATTRIBUTE_UNUSED __attribute__((unused))
# else
# define ATTRIBUTE_UNUSED
# endif
#endif
/**
* LIBXML_ATTR_ALLOC_SIZE:
*
* Macro used to indicate to GCC this is an allocator function
*/
#ifndef LIBXML_ATTR_ALLOC_SIZE
# if (!defined(__clang__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))))
# define LIBXML_ATTR_ALLOC_SIZE(x) __attribute__((alloc_size(x)))
# else
# define LIBXML_ATTR_ALLOC_SIZE(x)
# endif
#else
# define LIBXML_ATTR_ALLOC_SIZE(x)
#endif
/**
* LIBXML_ATTR_FORMAT:
*
* Macro used to indicate to GCC the parameter are printf like
*/
#ifndef LIBXML_ATTR_FORMAT
# if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)))
# define LIBXML_ATTR_FORMAT(fmt,args) __attribute__((__format__(__printf__,fmt,args)))
# else
# define LIBXML_ATTR_FORMAT(fmt,args)
# endif
#else
# define LIBXML_ATTR_FORMAT(fmt,args)
#endif
#else /* ! __GNUC__ */
/**
* ATTRIBUTE_UNUSED:
*
* Macro used to signal to GCC unused function parameters
*/
#define ATTRIBUTE_UNUSED
/**
* LIBXML_ATTR_ALLOC_SIZE:
*
* Macro used to indicate to GCC this is an allocator function
*/
#define LIBXML_ATTR_ALLOC_SIZE(x)
/**
* LIBXML_ATTR_FORMAT:
*
* Macro used to indicate to GCC the parameter are printf like
*/
#define LIBXML_ATTR_FORMAT(fmt,args)
#endif /* __GNUC__ */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+26
View File
@@ -0,0 +1,26 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# 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.
import("//build/ohos.gni")
ohos_static_library("restool_sqlite") {
sources = [
"//third_party/sqlite/src/sqlite3.c"
]
include_dirs = [
"//third_party/sqlite/include"
]
subsystem_name = "developtools"
part_name = "global_restool"
}
+34
View File
@@ -0,0 +1,34 @@
{
"name": "@ohos/restool",
"description": "OpenHarmony resource compile.",
"version": "3.1",
"license": "Apache License 2.0",
"pubiishAs": "code-segment",
"segment": {
"destPath": "developtools/global_resource_tool"
},
"dirs": {},
"scripts": {},
"component": {
"name": "restool",
"subsystem": "developtools",
"syscap": [],
"feature": [],
"adapted_system_type": ["mini", "small", "standard" ],
"deps": {
"components": [],
"third_party": [
"bounds_checking_function",
"libxml2",
"jsoncpp",
"sqlite"
]
},
"build": {
"sub_component": [ "//developtools/global_resource_tool:restool" ],
"inner_kits": [],
"test": []
}
}
}
+71
View File
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* 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 OHOS_RESTOOL_FILE_ENTRY_H
#define OHOS_RESTOOL_FILE_ENTRY_H
#include<memory>
#include<vector>
#include<string>
namespace OHOS {
namespace Global {
namespace Restool {
class FileEntry {
public:
class FilePath {
public:
FilePath(const std::string &path);
virtual ~FilePath();
FilePath Append(const std::string &path);
FilePath ReplaceExtension(const std::string &extension);
FilePath GetParent();
const std::string &GetPath() const;
const std::string &GetFilename() const;
const std::string &GetExtension() const;
const std::vector<std::string> GetSegments() const;
private:
void Init();
void Format();
std::string filePath_;
std::string filename_;
std::string parent_;
std::string extension_;
};
FileEntry(const std::string &path);
virtual ~FileEntry();
bool Init();
const std::vector<std::unique_ptr<FileEntry>> GetChilds() const;
bool IsFile() const;
const FilePath &GetFilePath() const;
static bool Exist(const std::string &path);
static bool RemoveAllDir(const std::string &path);
static bool CreateDirs(const std::string &path);
static bool CopyFile(const std::string &src, const std::string &dst);
static bool IsDirectory(const std::string &path);
private:
bool IsIgnore(const std::string &filename) const;
static bool RemoveAllDirInner(const FileEntry &entry);
static bool CreateDirsInner(const std::string &path, std::string::size_type offset);
FilePath filePath_;
bool isFile_;
static const std::string SEPARATE;
};
}
}
}
#endif
+1 -1
View File
@@ -35,7 +35,7 @@ public:
void SetLimitKey(const std::string &limitKey);
const int8_t *GetData() const;
const uint32_t GetDataLength() const;
uint32_t GetDataLength() const;
const std::string &GetName() const;
const ResType &GetResType() const;
const std::vector<KeyParam> &GetKeyParam() const;
+2 -2
View File
@@ -16,7 +16,6 @@
#ifndef OHOS_RESTOOL_RESOURCE_UTIL_H
#define OHOS_RESTOOL_RESOURCE_UTIL_H
#include<filesystem>
#include<vector>
#include "resource_data.h"
#include "json/json.h"
@@ -126,9 +125,10 @@ public:
/**
* @brief ignore file or directory
* @param filename: file or directory name
* @param isFile: ture if is file, other false
* @return true if ignore, other false
*/
static bool IsIgnoreFile(const std::string &filename, std::filesystem::file_type type);
static bool IsIgnoreFile(const std::string &filename, bool isFile);
/**
* @brief need convert to solid xml
-1
View File
@@ -153,7 +153,6 @@ uint32_t PackageParser::ForceWrite()
uint32_t PackageParser::PrintVersion()
{
cout << "Info: Restool version= " << RESTOOL_VERSION << endl;
cout << "time = (" << __DATE__ << " " << __TIME__ << ")" << endl;
exit(RESTOOL_SUCCESS);
return RESTOOL_SUCCESS;
}
+271
View File
@@ -0,0 +1,271 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* 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.
*/
#include "file_entry.h"
#include<fstream>
#include<iostream>
#include "dirent.h"
#include "sys/stat.h"
#include "unistd.h"
namespace OHOS {
namespace Global {
namespace Restool {
#ifdef _WIN32
const std::string FileEntry::SEPARATE = "\\";
#else
const std::string FileEntry::SEPARATE = "/";
#endif
using namespace std;
FileEntry::FileEntry(const string &path)
: filePath_(path), isFile_(false)
{
}
FileEntry::~FileEntry()
{
}
bool FileEntry::Init()
{
string filePath = filePath_.GetPath();
if (!Exist(filePath)) {
cerr << "Error: '" << filePath << "' not exists." << endl;
return false;
}
isFile_ = !IsDirectory(filePath);
return true;
}
const vector<unique_ptr<FileEntry>> FileEntry::GetChilds() const
{
vector<unique_ptr<FileEntry>> children;
struct dirent *entry;
string filePath = filePath_.GetPath();
DIR *handle = opendir(filePath.c_str());
while ((entry = readdir(handle)) != nullptr) {
string filename(entry->d_name);
if (IsIgnore(filename)) {
continue;
}
filePath = filePath_.GetPath() + SEPARATE + filename;
unique_ptr<FileEntry> f = make_unique<FileEntry>(filePath);
cout << filePath << endl;
f->Init();
children.push_back(move(f));
}
closedir(handle);
return children;
}
bool FileEntry::IsFile() const
{
return isFile_;
}
const FileEntry::FilePath &FileEntry::GetFilePath() const
{
return filePath_;
}
bool FileEntry::Exist(const string &path)
{
struct stat s;
if (stat(path.c_str(), &s) != 0) {
return false;
}
return true;
}
bool FileEntry::RemoveAllDir(const string &path)
{
FileEntry f(path);
if (!f.Init()) {
return false;
}
if (f.IsFile()) {
cerr << "Error: RemoveAllDir '" << path << "' not directory." << endl;
return false;
}
return RemoveAllDirInner(f);
}
bool FileEntry::CreateDirs(const string &path)
{
return CreateDirsInner(path, 0);
}
bool FileEntry::CopyFile(const string &src, const string &dst)
{
ifstream in(src, ios::binary);
ofstream out(dst, ios::binary);
if (!in || !out) {
cerr << "Error: CopyFile '" << src << "' or '" << dst << "' open fail." << endl;
return false;
}
out << in.rdbuf();
return true;
}
bool FileEntry::IsDirectory(const string &path)
{
struct stat s;
stat(path.c_str(), &s);
return S_ISDIR(s.st_mode);
}
FileEntry::FilePath::FilePath(const string &path) : filePath_(path)
{
Format();
Init();
}
FileEntry::FilePath::~FilePath()
{
}
FileEntry::FilePath FileEntry::FilePath::Append(const string &path)
{
Format();
string filePath = filePath_ + SEPARATE + path;
return FilePath(filePath);
}
FileEntry::FilePath FileEntry::FilePath::ReplaceExtension(const string &extension)
{
string filePath;
if (!parent_.empty()) {
filePath += parent_ + SEPARATE;
}
filePath += filename_.substr(0, filename_.length() - extension_.length()) + extension;
return FilePath(filePath);
}
FileEntry::FilePath FileEntry::FilePath::GetParent()
{
return FilePath(parent_);
}
const string &FileEntry::FilePath::GetPath() const
{
return filePath_;
}
const string &FileEntry::FilePath::GetFilename() const
{
return filename_;
}
const string &FileEntry::FilePath::GetExtension() const
{
return extension_;
}
const vector<string> FileEntry::FilePath::GetSegments() const
{
vector<string> segments;
string::size_type offset = 0;
string::size_type pos = filePath_.find_first_of(SEPARATE.front(), offset);
while (pos != string::npos) {
segments.push_back(filePath_.substr(offset, pos - offset));
offset = pos + 1;
pos = filePath_.find_first_of(SEPARATE.front(), offset);
}
if (offset < filePath_.length()) {
segments.push_back(filePath_.substr(offset));
}
return segments;
}
// below private
bool FileEntry::IsIgnore(const string &filename) const
{
if (filename == "." || filename == "..") {
return true;
}
return false;
}
bool FileEntry::RemoveAllDirInner(const FileEntry &entry)
{
if (entry.IsFile()) {
return remove(entry.GetFilePath().GetPath().c_str()) == 0;
}
for (const auto &iter : entry.GetChilds()) {
if (!RemoveAllDirInner(*iter)) {
return false;
}
}
return rmdir(entry.GetFilePath().GetPath().c_str()) == 0;
}
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());
#else
return mkdir(path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0;
#endif
}
string subPath = path.substr(0, pos);
if (!Exist(subPath)) {
#if _WIN32
if (mkdir(subPath.c_str()) != 0) {
#else
if (mkdir(subPath.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) {
#endif
return false;
}
}
return CreateDirsInner(path, pos + 1);
}
void FileEntry::FilePath::Format()
{
if (filePath_.back() != SEPARATE.front()) {
return;
}
filePath_.pop_back();
}
void FileEntry::FilePath::Init()
{
filename_ = filePath_;
string::size_type pos = filePath_.find_last_of(SEPARATE.front());
if (pos != string::npos) {
parent_ = filePath_.substr(0, pos);
if (pos + 1 < filePath_.length()) {
filename_ = filePath_.substr(pos + 1);
}
}
pos = filename_.find_last_of('.');
if (pos != string::npos && pos + 1 < filename_.length()) {
extension_ = filename_.substr(pos);
}
}
}
}
}
+3 -3
View File
@@ -15,9 +15,9 @@
#include "file_manager.h"
#include<algorithm>
#include<filesystem>
#include<iostream>
#include "factory_resource_compiler.h"
#include "file_entry.h"
#include "key_parser.h"
#include "reference_parser.h"
#include "resource_directory.h"
@@ -97,8 +97,8 @@ void FileManager::FilterRefSolidXml(const string &output, vector<string> &output
continue;
}
for (const auto &resourceDir : iter.second) {
string outputPath = filesystem::path(output).append(RESOURCES_DIR).append(resourceDir.limitKey)
.append(resourceDir.fileCluster).string();
string outputPath = FileEntry::FilePath(output).Append(RESOURCES_DIR).Append(resourceDir.limitKey)
.Append(resourceDir.fileCluster).GetPath();
if (find(outputPaths.begin(), outputPaths.end(), outputPath) == outputPaths.end()) {
outputPaths.push_back(outputPath);
}
+3 -3
View File
@@ -14,8 +14,8 @@
*/
#include "generic_compiler.h"
#include<filesystem>
#include<iostream>
#include "file_entry.h"
#include "resource_util.h"
#include "restool_errors.h"
@@ -55,7 +55,7 @@ bool GenericCompiler::PostFile(const FileInfo &fileInfo)
string data = fileInfo.filename;
if (IsConvertToSolidXml(fileInfo)) {
data = filesystem::path(data).replace_extension(".sxml").string();
data = FileEntry::FilePath(data).ReplaceExtension(".sxml").GetPath();
}
data = moduleName_ + SEPARATOR + RESOURCES_DIR + SEPARATOR + \
fileInfo.limitKey + SEPARATOR + fileInfo.fileCluster + SEPARATOR + data;
@@ -69,7 +69,7 @@ bool GenericCompiler::PostFile(const FileInfo &fileInfo)
string GenericCompiler::GetOutputFilePath(const FileInfo &fileInfo) const
{
string outputFolder = GetOutputFolder(fileInfo);
string outputFilePath = filesystem::path(outputFolder).append(fileInfo.filename).string();
string outputFilePath = FileEntry::FilePath(outputFolder).Append(fileInfo.filename).GetPath();
return outputFilePath;
}
+19 -13
View File
@@ -14,8 +14,9 @@
*/
#include "i_resource_compiler.h"
#include <filesystem>
#include <algorithm>
#include <iostream>
#include "file_entry.h"
#include "id_worker.h"
#include "resource_util.h"
#include "restool_errors.h"
@@ -43,17 +44,21 @@ uint32_t IResourceCompiler::Compile(const vector<DirectoryInfo> &directoryInfos)
map<string, vector<FileInfo>> setsByDirectory;
for (const auto &directoryInfo : directoryInfos) {
string outputFolder = GetOutputFolder(directoryInfo);
for (const auto &it : filesystem::directory_iterator(directoryInfo.dirPath)) {
if (ResourceUtil::IsIgnoreFile(it.path().filename().string(), it.status().type())) {
FileEntry f(directoryInfo.dirPath);
if (!f.Init()) {
return RESTOOL_ERROR;
}
for (const auto &it : f.GetChilds()) {
if (ResourceUtil::IsIgnoreFile(it->GetFilePath().GetFilename(), it->IsFile())) {
continue;
}
if (it.is_directory()) {
cout << "Error: '" << it.path().string() << "' not regular." << endl;
if (!it->IsFile()) {
cout << "Error: '" << it->GetFilePath().GetPath() << "' not regular." << endl;
return RESTOOL_ERROR;
}
FileInfo fileInfo = { directoryInfo, it.path().string(), it.path().filename().string() };
FileInfo fileInfo = { directoryInfo, it->GetFilePath().GetPath(), it->GetFilePath().GetFilename() };
fileInfos.push_back(fileInfo);
setsByDirectory[outputFolder].push_back(fileInfo);
}
@@ -63,6 +68,7 @@ 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;
}
@@ -93,8 +99,8 @@ uint32_t IResourceCompiler::Compile(const FileInfo &fileInfo)
}
map<string, vector<FileInfo>> setsByDirectory;
if (NeedIfConvertToSolidXml()) {
string outputFolder = filesystem::path(output_).append(RESOURCES_DIR)
.append(fileInfo.limitKey).append(fileInfo.fileCluster).string();
string outputFolder = FileEntry::FilePath(output_).Append(RESOURCES_DIR)
.Append(fileInfo.limitKey).Append(fileInfo.fileCluster).GetPath();
setsByDirectory[outputFolder].push_back(fileInfo);
}
@@ -201,7 +207,7 @@ void IResourceCompiler::ListXmlFile(const vector<FileInfo> &fileInfos, vector<st
bool IResourceCompiler::IsXmlFile(const FileInfo &fileInfo) const
{
if (filesystem::path(fileInfo.filePath).extension() != ".xml") {
if (FileEntry::FilePath(fileInfo.filePath).GetExtension() != ".xml") {
return false;
}
return true;
@@ -209,8 +215,8 @@ bool IResourceCompiler::IsXmlFile(const FileInfo &fileInfo) const
bool IResourceCompiler::HasConvertedToSolidXml(const FileInfo &fileInfo) const
{
string solidXmlPath = filesystem::path(output_).append(RESOURCES_DIR).append(fileInfo.limitKey)
.append(fileInfo.fileCluster).append(fileInfo.filename).replace_extension(".sxml").string();
string solidXmlPath = FileEntry::FilePath(output_).Append(RESOURCES_DIR).Append(fileInfo.limitKey)
.Append(fileInfo.fileCluster).Append(fileInfo.filename).ReplaceExtension(".sxml").GetPath();
if (ResourceUtil::FileExist(solidXmlPath)) {
return true;
}
@@ -224,8 +230,8 @@ bool IResourceCompiler::NeedIfConvertToSolidXml() const
string IResourceCompiler::GetOutputFolder(const DirectoryInfo &directoryInfo) const
{
string outputFolder = filesystem::path(output_).append(RESOURCES_DIR)
.append(directoryInfo.limitKey).append(directoryInfo.fileCluster).string();
string outputFolder = FileEntry::FilePath(output_).Append(RESOURCES_DIR)
.Append(directoryInfo.limitKey).Append(directoryInfo.fileCluster).GetPath();
return outputFolder;
}
}
+4 -4
View File
@@ -14,10 +14,10 @@
*/
#include "id_worker.h"
#include<filesystem>
#include<iostream>
#include<regex>
#include "cmd_parser.h"
#include "file_entry.h"
namespace OHOS {
namespace Global {
@@ -173,8 +173,8 @@ uint32_t IdWorker::InitIdDefined()
string idDefinedPath;
if (type_ == ResourceIdCluster::RES_ID_SYS) {
for (const auto &inputPath : packageParser.GetInputs()) {
idDefinedPath = filesystem::path(inputPath).append(RESOURCES_DIR)
.append("base").append("element").append(ID_DEFINED_FILE).string();
idDefinedPath = FileEntry::FilePath(inputPath).Append(RESOURCES_DIR)
.Append("base").Append("element").Append(ID_DEFINED_FILE).GetPath();
if (InitIdDefined(idDefinedPath) != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
@@ -182,7 +182,7 @@ uint32_t IdWorker::InitIdDefined()
return RESTOOL_SUCCESS;
}
idDefinedPath = filesystem::path(packageParser.GetRestoolPath()).parent_path().append(ID_DEFINED_FILE).string();
idDefinedPath = FileEntry::FilePath(packageParser.GetRestoolPath()).GetParent().Append(ID_DEFINED_FILE).GetPath();
if (InitIdDefined(idDefinedPath) != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
+6 -6
View File
@@ -15,8 +15,8 @@
#include "increment_list.h"
#include<algorithm>
#include<filesystem>
#include<iostream>
#include "file_entry.h"
#include "key_parser.h"
namespace OHOS {
@@ -52,14 +52,14 @@ bool IncrementList::GetFromPath(const string &filePath, FileIncrement &info) con
return false;
}
info.rootPath = folder_[priority];
string rootPath = filesystem::path(info.rootPath).append("").string();
string rootPath = FileEntry::FilePath(info.rootPath).Append("").GetPath();
info.relativePath = filePath.substr(rootPath.length());
vector<string> segments;
if (!ParseSegment(info.relativePath, segments)) {
return false;
}
info.dirPath = filesystem::path(filePath).parent_path().string();
info.dirPath = FileEntry::FilePath(filePath).GetParent().GetPath();
info.filePath = filePath;
info.limitKey = segments[SEG_LIMIT_KEY];
if (info.limitKey == RAW_FILE_DIR) {
@@ -84,7 +84,7 @@ bool IncrementList::GetFromPath(const string &filePath, FileIncrement &info) con
int32_t IncrementList::GetPriority(const string &filePath) const
{
auto result = find_if(folder_.begin(), folder_.end(), [&filePath](auto &iter) {
string rootPath = filesystem::path(iter).append("").string();
string rootPath = FileEntry::FilePath(iter).Append("").GetPath();
if (filePath.length() <= rootPath.length()) {
return false;
}
@@ -101,8 +101,8 @@ int32_t IncrementList::GetPriority(const string &filePath) const
bool IncrementList::ParseSegment(const string &filePath, vector<string> &segments) const
{
for (const auto &it : filesystem::path(filePath)) {
segments.push_back(it.string());
for (const auto &it : FileEntry::FilePath(filePath).GetSegments()) {
segments.push_back(it);
}
if (segments.size() >= (SEG_RESOURCE + 1) && segments[SEG_RESOURCE] != RESOURCES_DIR) {
+22 -50
View File
@@ -16,14 +16,14 @@
#include "increment_manager.h"
#include<algorithm>
#include<iostream>
#include "file_entry.h"
#include "id_worker.h"
#include "key_parser.h"
#include "module_combine.h"
#include "resource_module_inc.h"
#include "restool_errors.h"
#include "xml_key_node.h"
#include "resource_module_inc.h"
#include "module_combine.h"
namespace OHOS {
namespace Global {
namespace Restool {
@@ -65,7 +65,7 @@ uint32_t IncrementManager::Init(const string &cachePath, const vector<std::strin
// below private
bool IncrementManager::InitIdJson()
{
string idJsonPath = filesystem::path(cachePath_).append(ID_JSON_FILE).string();
string idJsonPath = FileEntry::FilePath(cachePath_).Append(ID_JSON_FILE).GetPath();
if (!ResourceUtil::FileExist(idJsonPath)) {
return true;
}
@@ -93,7 +93,7 @@ bool IncrementManager::ScanModules(const vector<IncrementList::FileIncrement> &d
for (auto &iter : moduleInfos) {
string pathHash = ResourceUtil::GenerateHash(iter.rootPath);
string moduleCachePath = filesystem::path(cachePath_).append(pathHash).string();
string moduleCachePath = FileEntry::FilePath(cachePath_).Append(pathHash).GetPath();
ResourceModuleInc resourceModuleInc(iter.rootPath, moduleCachePath, moduleName_, folder_);
if (FirstIncrement()) {
if (resourceModuleInc.ResourceModule::ScanResource() != RESTOOL_SUCCESS) {
@@ -125,7 +125,7 @@ bool IncrementManager::ScanModules(const vector<IncrementList::FileIncrement> &d
bool IncrementManager::InitList(vector<IncrementList::FileIncrement> &dels) const
{
string listPath = filesystem::path(cachePath_).append(IncrementList::RESTOOL_LIST_FILE).string();
string listPath = FileEntry::FilePath(cachePath_).Append(IncrementList::RESTOOL_LIST_FILE).GetPath();
if (!ResourceUtil::FileExist(listPath)) {
return true;
}
@@ -158,7 +158,7 @@ bool IncrementManager::SaveIdJson() const
root[to_string(iter.first)] = node;
}
string idJsonPath = filesystem::path(cachePath_).append(ID_JSON_FILE).string();
string idJsonPath = FileEntry::FilePath(cachePath_).Append(ID_JSON_FILE).GetPath();
if (!ResourceUtil::SaveToJsonFile(idJsonPath, root)) {
return false;
}
@@ -168,7 +168,7 @@ bool IncrementManager::SaveIdJson() const
bool IncrementManager::LoadIdJson()
{
Json::Value root;
string idJsonPath = filesystem::path(cachePath_).append(ID_JSON_FILE).string();
string idJsonPath = FileEntry::FilePath(cachePath_).Append(ID_JSON_FILE).GetPath();
if (!ResourceUtil::OpenJsonFile(idJsonPath, root)) {
return false;
}
@@ -229,15 +229,15 @@ void IncrementManager::DeleteRawFile(vector<IncrementList::FileIncrement> &dels)
it++;
continue;
}
string rawFilePath = filesystem::path(outputPath_).append(it->relativePath).string();
filesystem::remove(rawFilePath);
string rawFilePath = FileEntry::FilePath(outputPath_).Append(it->relativePath).GetPath();
remove(rawFilePath.c_str());
it = dels.erase(it);
}
}
bool IncrementManager::ClearSolidXml() const
{
string resourceDir = filesystem::path(outputPath_).append(RESOURCES_DIR).string();
string resourceDir = FileEntry::FilePath(outputPath_).Append(RESOURCES_DIR).GetPath();
if (!ResourceUtil::FileExist(resourceDir)) {
return true;
}
@@ -248,19 +248,24 @@ bool IncrementManager::ClearSolidXml() const
return true;
}
for (const auto &entry : filesystem::directory_iterator(info.dirPath)) {
if (entry.is_directory()) {
cerr << "Error: '" << entry.path().string() << "' is directroy." << endl;
FileEntry f(info.dirPath);
if (!f.Init()) {
return false;
}
for (const auto &entry : f.GetChilds()) {
if (!entry->IsFile()) {
cerr << "Error: '" << entry->GetFilePath().GetPath() << "' is directroy." << endl;
return false;
}
string extension = entry.path().extension().string();
string extension = entry->GetFilePath().GetExtension();
if (extension != ".sxml" && extension != ".key" && extension != ".json") {
continue;
}
if (!filesystem::remove(entry.path().string())) {
cerr << "Error: remove '" << entry.path().string() << "' fail." << endl;
if (remove(entry->GetFilePath().GetPath().c_str()) != 0) {
cerr << "Error: remove '" << entry->GetFilePath().GetPath() << "' fail." << endl;
return false;
}
}
@@ -270,39 +275,6 @@ bool IncrementManager::ClearSolidXml() const
}
return true;
}
/*
{
"0x01000000":
{
"name":"xxxxx",
"type":"string"
}
}
{
"header":{
"folder":["xxxx", "xxxx", "xxxx", "xxxx"]
},
"index":{
"0x01000000":{
"filepath":{
"data":"xxxx",
"name":"xxxx",
"type":"xxxx",
"limitkey":"xxxx"
}
},
}
}
{
"del":[
"xx/xx/xx/xxx"
],
"fix":[
"xxx/xxx/xx"
]
}
*/
}
}
}
+14 -10
View File
@@ -15,8 +15,8 @@
#include "module_combine.h"
#include<algorithm>
#include<filesystem>
#include<iostream>
#include "file_entry.h"
#include "key_manager.h"
#include "resource_util.h"
#include "solid_xml.h"
@@ -32,7 +32,7 @@ ModuleCombine::ModuleCombine(const string &modulePath, const string &outputPath)
bool ModuleCombine::Combine()
{
string resourceDir = filesystem::path(modulePath_).append(RESOURCES_DIR).string();
string resourceDir = FileEntry::FilePath(modulePath_).Append(RESOURCES_DIR).GetPath();
ResourceDirectory resourceDirectory;
if (!resourceDirectory.ScanResources(resourceDir, [this](const DirectoryInfo &info) -> bool {
return CombineDirectory(info);
@@ -45,27 +45,31 @@ bool ModuleCombine::Combine()
// below private
bool ModuleCombine::CombineDirectory(const DirectoryInfo &directoryInfo)
{
string outputFolder = filesystem::path(outputPath_).append(RESOURCES_DIR)
.append(directoryInfo.limitKey).append(directoryInfo.fileCluster).string();
string outputFolder = FileEntry::FilePath(outputPath_).Append(RESOURCES_DIR)
.Append(directoryInfo.limitKey).Append(directoryInfo.fileCluster).GetPath();
if (!ResourceUtil::CreateDirs(outputFolder)) {
return false;
}
map<string, string> sxmlPaths;
for (const auto &entry : filesystem::directory_iterator(directoryInfo.dirPath)) {
string src = entry.path().string();
if (entry.is_directory()) {
FileEntry f(directoryInfo.dirPath);
if (!f.Init()) {
return false;
}
for (const auto &entry : f.GetChilds()) {
string src = entry->GetFilePath().GetPath();
if (!entry->IsFile()) {
cerr << "Error: " << src << " is directory." << endl;
return false;
}
string filename = entry.path().filename().string();
string dst = filesystem::path(outputFolder).append(filename).string();
string filename = entry->GetFilePath().GetFilename();
string dst = FileEntry::FilePath(outputFolder).Append(filename).GetPath();
if (ResourceUtil::FileExist(dst)) {
continue;
}
if (entry.path().extension().string() == ".sxml") {
if (entry->GetFilePath().GetExtension() == ".sxml") {
sxmlPaths.emplace(src, dst);
continue;
}
+7 -7
View File
@@ -14,9 +14,9 @@
*/
#include "preview_manager.h"
#include<filesystem>
#include<iostream>
#include "factory_resource_compiler.h"
#include "file_entry.h"
#include "key_parser.h"
#include "resource_module.h"
#include "resource_util.h"
@@ -36,7 +36,7 @@ uint32_t PreviewManager::ScanModules(const vector<string> &modulePaths, const st
{
SqliteDatabase &database = SqliteDatabase::GetInstance();
string dbPath = filesystem::path(output).append("resources.db").string();
string dbPath = FileEntry::FilePath(output).Append("resources.db").GetPath();
database.Init(dbPath);
if(!database.OpenDatabase()) {
return RESTOOL_ERROR;
@@ -48,7 +48,7 @@ uint32_t PreviewManager::ScanModules(const vector<string> &modulePaths, const st
}
for (const auto &iter : modulePaths) {
if (filesystem::is_directory(iter)) {
if (FileEntry::IsDirectory(iter)) {
ResourceModule resourceMoudle(iter, output, "");
resourceMoudle.SetPreviewMode(true);
database.SetPriority(priority);
@@ -74,10 +74,10 @@ bool PreviewManager::ScanFile(const string &filePath, int32_t priority)
}
FileInfo fileInfo;
fileInfo.filePath = filePath;
fileInfo.filename = filesystem::path(filePath).filename().string();
fileInfo.dirPath = filesystem::path(filePath).parent_path().string();
fileInfo.fileCluster = filesystem::path(fileInfo.dirPath).filename().string();
fileInfo.limitKey = filesystem::path(fileInfo.dirPath).parent_path().filename().string();
fileInfo.filename = FileEntry::FilePath(filePath).GetFilename();
fileInfo.dirPath = FileEntry::FilePath(filePath).GetParent().GetPath();
fileInfo.fileCluster = FileEntry::FilePath(fileInfo.dirPath).GetFilename();
fileInfo.limitKey = FileEntry::FilePath(fileInfo.dirPath).GetParent().GetFilename();
fileInfo.dirType = ResourceUtil::GetResTypeByDir(fileInfo.fileCluster);
if (fileInfo.dirType == ResType::INVALID_RES_TYPE) {
+10 -8
View File
@@ -16,6 +16,7 @@
#include "reference_parser.h"
#include<iostream>
#include<regex>
#include "file_entry.h"
#include "restool_errors.h"
#include "xml_key_node.h"
@@ -66,8 +67,8 @@ ReferenceParser::~ReferenceParser()
uint32_t ReferenceParser::ParseRefInSolidXml(const vector<string> &solidXmlFolders) const
{
for (const auto &solidXmlFolder : solidXmlFolders) {
string filePath = filesystem::path(solidXmlFolder)
.append(XmlKeyNode::KEY_TO_FILE_NAME.at(XmlKeyNode::KeyType::CONSTANT)).string();
string filePath = FileEntry::FilePath(solidXmlFolder)
.Append(XmlKeyNode::KEY_TO_FILE_NAME.at(XmlKeyNode::KeyType::CONSTANT)).GetPath();
if (!ResourceUtil::FileExist(filePath)) {
continue;
}
@@ -111,22 +112,23 @@ uint32_t ReferenceParser::ParseRefInString(string &value, bool &update) const
uint32_t ReferenceParser::ParseRefInProfile(const string &output) const
{
string profileFolder = filesystem::path(output).append(RESOURCES_DIR).append("base").append("profile").string();
string profileFolder = FileEntry::FilePath(output).Append(RESOURCES_DIR).Append("base").Append("profile").GetPath();
if (!ResourceUtil::FileExist(profileFolder)) {
return RESTOOL_SUCCESS;
}
for (const auto &entry : filesystem::directory_iterator(profileFolder)) {
if (entry.is_directory()) {
cerr << "Error: '" << entry.path().string() << "' is directory." << endl;
FileEntry f(profileFolder);
for (const auto &entry : f.GetChilds()) {
if (!entry->IsFile()) {
cerr << "Error: '" << entry->GetFilePath().GetPath() << "' is directory." << endl;
return false;
}
if (entry.path().extension() != ".json" ) {
if (entry->GetFilePath().GetExtension() != ".json" ) {
continue;
}
if (ParseRefInJson(entry.path().string()) != RESTOOL_SUCCESS) {
if (ParseRefInJson(entry->GetFilePath().GetPath()) != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
}
+21 -11
View File
@@ -15,6 +15,7 @@
#include "resource_directory.h"
#include<iostream>
#include "file_entry.h"
#include "resource_util.h"
namespace OHOS {
@@ -23,14 +24,19 @@ namespace Restool {
using namespace std;
bool ResourceDirectory::ScanResources(const string &resourcesDir, function<bool(const DirectoryInfo&)> callback) const
{
for (auto &it : filesystem::directory_iterator(resourcesDir)) {
string limitKey = it.path().filename().string();
if (ResourceUtil::IsIgnoreFile(limitKey, it.status().type())) {
FileEntry f(resourcesDir);
if (!f.Init()) {
return false;
}
for (const auto &it : f.GetChilds()) {
string limitKey = it->GetFilePath().GetFilename();
if (ResourceUtil::IsIgnoreFile(limitKey, it->IsFile())) {
continue;
}
if (!it.is_directory()) {
cerr << "Error: '" << it.path().string() << "' not directory." << endl;
if (it->IsFile()) {
cerr << "Error: '" << it->GetFilePath().GetPath() << "' not directory." << endl;
return false;
}
@@ -38,7 +44,7 @@ bool ResourceDirectory::ScanResources(const string &resourcesDir, function<bool(
continue;
}
if (!ScanResourceLimitKeyDir(it.path().string(), limitKey, callback)) {
if (!ScanResourceLimitKeyDir(it->GetFilePath().GetPath(), limitKey, callback)) {
return false;
}
}
@@ -55,14 +61,18 @@ bool ResourceDirectory::ScanResourceLimitKeyDir(const string &resourceTypeDir, c
return false;
}
for (auto &it : filesystem::directory_iterator(resourceTypeDir)) {
string dirPath = it.path().string();
string fileCluster = it.path().filename().string();
if (ResourceUtil::IsIgnoreFile(fileCluster, it.status().type())) {
FileEntry f(resourceTypeDir);
if (!f.Init()) {
return false;
}
for (const auto &it : f.GetChilds()) {
string dirPath = it->GetFilePath().GetPath();
string fileCluster = it->GetFilePath().GetFilename();
if (ResourceUtil::IsIgnoreFile(fileCluster, it->IsFile())) {
continue;
}
if (!it.is_directory()) {
if (it->IsFile()) {
cerr << "Error: '" << dirPath << "' not directory." << endl;
return false;
}
+1 -1
View File
@@ -79,7 +79,7 @@ const int8_t *ResourceItem::GetData() const
return data_;
}
const uint32_t ResourceItem::GetDataLength() const
uint32_t ResourceItem::GetDataLength() const
{
return dataLen_;
}
+3 -2
View File
@@ -15,6 +15,7 @@
#include "resource_merge.h"
#include "cmd_parser.h"
#include "file_entry.h"
namespace OHOS {
namespace Global {
@@ -46,8 +47,8 @@ uint32_t ResourceMerge::Init()
map<ConfigParser::ModuleType, vector<string>> inputTypes;
for (auto it = inputs.crbegin(); it != inputs.crend(); it++) {
string filePath = filesystem::path(*it).append(ConfigParser::GetConfigName()).string();
string resourceDir = filesystem::path(*it).append(RESOURCES_DIR).string();
string filePath = FileEntry::FilePath(*it).Append(ConfigParser::GetConfigName()).GetPath();
string resourceDir = FileEntry::FilePath(*it).Append(RESOURCES_DIR).GetPath();
ConfigParser::ModuleType moduleType = ConfigParser::ModuleType::NONE;
if (!ResourceUtil::FileExist(filePath)) {
inputTypes[moduleType].push_back(resourceDir);
+1 -1
View File
@@ -14,7 +14,7 @@
*/
#include "resource_module.h"
#include<filesystem>
#include<algorithm>
#include<iostream>
#include "factory_resource_compiler.h"
#include "restool_errors.h"
+8 -8
View File
@@ -14,9 +14,9 @@
*/
#include "resource_module_inc.h"
#include<filesystem>
#include<iostream>
#include "factory_resource_compiler.h"
#include "file_entry.h"
#include "increment_index.h"
#include "restool_errors.h"
@@ -38,19 +38,19 @@ uint32_t ResourceModuleInc::ScanResource(const vector<IncrementList::FileIncreme
if (fileIncrement.dirType == ResType::ELEMENT) {
continue;
}
string filePathDel = filesystem::path(moduleOutput_).append(RESOURCES_DIR)
.append(fileIncrement.limitKey).append(fileIncrement.fileCluster).append(fileIncrement.filename).string();
string filePathDel = FileEntry::FilePath(moduleOutput_).Append(RESOURCES_DIR)
.Append(fileIncrement.limitKey).Append(fileIncrement.fileCluster).Append(fileIncrement.filename).GetPath();
if (ResourceUtil::NeedConverToSolidXml(fileIncrement.dirType) &&
filesystem::path(filePathDel).extension().string() == ".xml") {
filePathDel = filesystem::path(filePathDel).replace_extension(".sxml").string();
FileEntry::FilePath(filePathDel).GetExtension() == ".xml") {
filePathDel = FileEntry::FilePath(filePathDel).ReplaceExtension(".sxml").GetPath();
}
if (!filesystem::remove(filePathDel)) {
if (remove(filePathDel.c_str()) != 0) {
cerr << "Error: delete '" << filePathDel << "' fail" << endl;
return RESTOOL_ERROR;
}
}
string indexPath = filesystem::path(moduleOutput_).append(IncrementIndex::INDEX_FILE).string();
string indexPath = FileEntry::FilePath(moduleOutput_).Append(IncrementIndex::INDEX_FILE).GetPath();
IncrementIndex moduleIndex(indexPath, folder_);
moduleIndex.SetSkipPaths(skips);
if (!moduleIndex.Load(owner_)) {
@@ -74,7 +74,7 @@ uint32_t ResourceModuleInc::ScanResource(const vector<IncrementList::FileIncreme
uint32_t ResourceModuleInc::SaveIndex() const
{
string indexPath = filesystem::path(moduleOutput_).append(IncrementIndex::INDEX_FILE).string();
string indexPath = FileEntry::FilePath(moduleOutput_).Append(IncrementIndex::INDEX_FILE).GetPath();
IncrementIndex moduleIndex(indexPath, folder_);
if (!moduleIndex.Save(owner_)) {
return RESTOOL_ERROR;
+27 -19
View File
@@ -15,7 +15,8 @@
#include "resource_pack.h"
#include<algorithm>
#include<filesystem>
#include<iomanip>
#include "file_entry.h"
#include "file_manager.h"
#include "header.h"
#include "increment_manager.h"
@@ -141,14 +142,14 @@ void ResourcePack::InitHeaderCreater()
uint32_t ResourcePack::InitOutput() const
{
string cachePath = packageParser_.GetCachePath();
string indexPath = filesystem::path(cachePath).append(IncrementManager::ID_JSON_FILE).string();
string indexPath = FileEntry::FilePath(cachePath).Append(IncrementManager::ID_JSON_FILE).GetPath();
if (!cachePath.empty() && ResourceUtil::FileExist(indexPath)) {
return RESTOOL_SUCCESS;
}
bool forceWrite = packageParser_.GetForceWrite();
string output = packageParser_.GetOutput();
string resourcesPath = filesystem::path(output).append(RESOURCES_DIR).string();
string resourcesPath = FileEntry::FilePath(output).Append(RESOURCES_DIR).GetPath();
if (ResourceUtil::FileExist(resourcesPath)) {
if (!forceWrite) {
cerr << "Error: output path '" << resourcesPath << "' exists." << endl;
@@ -165,10 +166,10 @@ uint32_t ResourcePack::InitOutput() const
uint32_t ResourcePack::GenerateHeader() const
{
auto headerPaths = packageParser_.GetResourceHeaders();
string textPath = filesystem::path(packageParser_.GetOutput()).append("ResourceTable.txt").string();
string textPath = FileEntry::FilePath(packageParser_.GetOutput()).Append("ResourceTable.txt").GetPath();
headerPaths.push_back(textPath);
for (const auto &headerPath : headerPaths) {
string extension = filesystem::path(headerPath).extension().string();
string extension = FileEntry::FilePath(headerPath).GetExtension();
auto it = headerCreaters_.find(extension);
if (it == headerCreaters_.end()) {
cout << "Warning: don't support header file format '" << headerPath << "'" << endl;
@@ -189,13 +190,13 @@ uint32_t ResourcePack::InitConfigJson()
cerr << "Error: more input path, -j config.json empty" << endl;
return RESTOOL_ERROR;
}
config = filesystem::path(packageParser_.GetInputs()[0]).append(CONFIG_JSON).string();
config = FileEntry::FilePath(packageParser_.GetInputs()[0]).Append(CONFIG_JSON).GetPath();
if (!ResourceUtil::FileExist(config)) {
config = filesystem::path(packageParser_.GetInputs()[0]).append(MODULE_JSON).string();
config = FileEntry::FilePath(packageParser_.GetInputs()[0]).Append(MODULE_JSON).GetPath();
}
}
if (filesystem::path(config).filename().string() == MODULE_JSON) {
if (FileEntry::FilePath(config).GetFilename() == MODULE_JSON) {
ConfigParser::SetUseModule();
}
configJson_ = ConfigParser(config);
@@ -274,17 +275,18 @@ uint32_t ResourcePack::GenerateJsHeader(const std::string &headerPath) const
uint32_t ResourcePack::CopyRawFile(const vector<string> &inputs) const
{
for (const auto &input : inputs) {
string rawfilePath = filesystem::path(input).append(RAW_FILE_DIR).string();
string rawfilePath = FileEntry::FilePath(input).Append(RAW_FILE_DIR).GetPath();
if (!ResourceUtil::FileExist(rawfilePath)) {
continue;
}
if (!filesystem::is_directory(rawfilePath)) {
if (!FileEntry::IsDirectory(rawfilePath)) {
cerr << "Error: '" << rawfilePath << "' not directory." << endl;
return RESTOOL_ERROR;
}
string dst = filesystem::path(packageParser_.GetOutput()).append(RESOURCES_DIR).append(RAW_FILE_DIR).string();
string dst = FileEntry::FilePath(packageParser_.GetOutput())
.Append(RESOURCES_DIR).Append(RAW_FILE_DIR).GetPath();
if (CopyRawFileImpl(rawfilePath, dst) != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
@@ -297,22 +299,27 @@ uint32_t ResourcePack::CopyRawFileImpl(const string &src, const string &dst) con
if (!ResourceUtil::CreateDirs(dst)) {
return RESTOOL_ERROR;
}
for (const auto &entry : filesystem::directory_iterator(src)) {
string filename = entry.path().filename().string();
if (ResourceUtil::IsIgnoreFile(filename, entry.status().type())) {
FileEntry f(src);
if (!f.Init()) {
return RESTOOL_ERROR;
}
for (const auto &entry : f.GetChilds()) {
string filename = entry->GetFilePath().GetFilename();
if (ResourceUtil::IsIgnoreFile(filename, entry->IsFile())) {
continue;
}
string subPath = filesystem::path(dst).append(filename).string();
if (entry.is_directory()) {
if (CopyRawFileImpl(entry.path().string(), subPath) != RESTOOL_SUCCESS) {
string subPath = FileEntry::FilePath(dst).Append(filename).GetPath();
if (!entry->IsFile()) {
if (CopyRawFileImpl(entry->GetFilePath().GetPath(), subPath) != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
} else {
if (ResourceUtil::FileExist(subPath)) {
continue;
}
if (!ResourceUtil::CopyFleInner(entry.path().string(), subPath)) {
if (!ResourceUtil::CopyFleInner(entry->GetFilePath().GetPath(), subPath)) {
return RESTOOL_ERROR;
}
}
@@ -325,7 +332,8 @@ uint32_t ResourcePack::GenerateConfigJson()
if (configJson_.ParseRefence() != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
string outputPath = filesystem::path(packageParser_.GetOutput()).append(ConfigParser::GetConfigName()).string();
string outputPath = FileEntry::FilePath(packageParser_.GetOutput())
.Append(ConfigParser::GetConfigName()).GetPath();
return configJson_.Save(outputPath);
}
+2 -2
View File
@@ -14,8 +14,8 @@
*/
#include "resource_table.h"
#include <filesystem>
#include "cmd_parser.h"
#include "file_entry.h"
#include "file_manager.h"
#include "resource_util.h"
#include "securec.h"
@@ -28,7 +28,7 @@ ResourceTable::ResourceTable()
{
auto &parser =CmdParser<PackageParser>::GetInstance();
auto &packageParser = parser.GetCmdParser();
indexFilePath_ = filesystem::path(packageParser.GetOutput()).append(RESOURCE_INDEX_FILE).string();
indexFilePath_ = FileEntry::FilePath(packageParser.GetOutput()).Append(RESOURCE_INDEX_FILE).GetPath();
}
ResourceTable::~ResourceTable()
+10 -21
View File
@@ -18,6 +18,7 @@
#include<fstream>
#include<iostream>
#include<regex>
#include "file_entry.h"
#ifdef __WIN32
#include "windows.h"
#endif
@@ -62,18 +63,12 @@ void ResourceUtil::Split(const string &str, vector<string> &out, const string &s
bool ResourceUtil::FileExist(const string &path)
{
return filesystem::exists(path);
return FileEntry::Exist(path);
}
bool ResourceUtil::RmoveAllDir(const string &path)
{
error_code err;
filesystem::remove_all(path, err);
if (err) {
cerr << "Error: remove all " << path << " failed, msg :=" << err.message() << endl;
return false;
}
return true;
return FileEntry::RemoveAllDir(path);
}
bool ResourceUtil::OpenJsonFile(const string &path, Json::Value &root)
@@ -225,12 +220,8 @@ bool ResourceUtil::CopyFleInner(const string &src, const string &dst)
return false;
}
#else
error_code err;
filesystem::path from(src);
filesystem::path to(dst);
if (!filesystem::copy_file(from, to, filesystem::copy_options::overwrite_existing, err)) {
if (!FileEntry::CopyFile(src, dst)) {
cerr << "Error: copy file fail from '" << src << "' to '" << dst << "'" << endl;
cerr << err.message() << endl;
return false;
}
#endif
@@ -242,22 +233,20 @@ bool ResourceUtil::CreateDirs(const string &filePath)
if (FileExist(filePath)) {
return true;
}
error_code err;
if (!filesystem::create_directories(filePath, err)) {
cerr << "Error: create directory fail '" << filePath << "'" << endl;
return false;
if (!FileEntry::CreateDirs(filePath)) {
cerr << "Error: create dir fail '" << filePath << "'" << endl;
}
return true;
}
bool ResourceUtil::IsIgnoreFile(const string &filename, filesystem::file_type type)
bool ResourceUtil::IsIgnoreFile(const string &filename, bool isFile)
{
string key = filename;
transform(key.begin(), key.end(), key.begin(), ::tolower);
for (const auto &iter : IGNORE_FILE_REGEX) {
if ((iter.second == IgnoreType::IGNORE_FILE && type != filesystem::file_type::regular) ||
(iter.second == IgnoreType::IGNORE_DIR && type != filesystem::file_type::directory)) {
if ((iter.second == IgnoreType::IGNORE_FILE && !isFile) ||
(iter.second == IgnoreType::IGNORE_DIR && isFile)) {
continue;
}
if (regex_match(key, regex(iter.first))) {
-1
View File
@@ -14,7 +14,6 @@
*/
#include "solid_xml_compiler.h"
#include<filesystem>
#include<iostream>
#include<regex>
#include "resource_util.h"
+3 -3
View File
@@ -14,7 +14,7 @@
*/
#include "key_manager.h"
#include<filesystem>
#include "file_entry.h"
#include "resource_util.h"
namespace OHOS {
@@ -32,7 +32,7 @@ KeyManager::KeyManager()
bool KeyManager::LoadKey(const string &keysPath)
{
for (auto &key : keys_) {
string keyPath = filesystem::path(keysPath).append(XmlKeyNode::KEY_TO_FILE_NAME.at(key.first)).string();
string keyPath = FileEntry::FilePath(keysPath).Append(XmlKeyNode::KEY_TO_FILE_NAME.at(key.first)).GetPath();
if (!ResourceUtil::FileExist(keyPath)) {
continue;
}
@@ -46,7 +46,7 @@ bool KeyManager::LoadKey(const string &keysPath)
bool KeyManager::SaveKey(const string &keysPath)
{
for (const auto &iter : keys_) {
string keyPath = filesystem::path(keysPath).append(XmlKeyNode::KEY_TO_FILE_NAME.at(iter.first)).string();
string keyPath = FileEntry::FilePath(keysPath).Append(XmlKeyNode::KEY_TO_FILE_NAME.at(iter.first)).GetPath();
if (!iter.second->SaveToFile(keyPath)) {
return false;
}
+3 -3
View File
@@ -14,7 +14,7 @@
*/
#include "xml_converter.h"
#include<filesystem>
#include "file_entry.h"
#include "resource_util.h"
#include "solid_xml.h"
@@ -38,8 +38,8 @@ bool XmlConverter::GenerateSolidXml()
}
for (const auto &xmlPath : xmlPaths_) {
SolidXml solidXml(xmlPath, keyManager.GetKeys());
string filename = filesystem::path(xmlPath).filename().string();
string filePath = filesystem::path(outputPath_).append(filename).replace_extension(".sxml").string();
string filename = FileEntry::FilePath(xmlPath).GetFilename();
string filePath = FileEntry::FilePath(outputPath_).Append(filename).ReplaceExtension(".sxml").GetPath();
if (!solidXml.GenerateSolidXml(filePath)) {
return false;
}
+60
View File
@@ -0,0 +1,60 @@
{
"app": {
"bundleName": "com.example.myapplication",
"vendor": "example",
"version": {
"code": 1,
"name": "1.0"
},
"apiVersion": {
"compatible": 4,
"target": 5
}
},
"deviceConfig": {},
"module": {
"package": "com.example.myapplication",
"name": ".MyApplication",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry"
},
"abilities": [
{
"visible": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"name": "com.example.myapplication.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "MyApplication",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}
+5
View File
@@ -0,0 +1,5 @@
{
"string":[
{ "name":"mainability_description", "value":"my testing application"}
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 Huawei Device Co., Ltd.
# 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.
import os
import sys
restool_cmd = sys.argv[1]
output_path = sys.argv[2]
run_cmd = restool_cmd
run_cmd = run_cmd + " -i " + os.path.join(".")
run_cmd = run_cmd + " -o " + output_path
run_cmd = run_cmd + " -r " + os.path.join(output_path, "ResourceTable.h")
run_cmd = run_cmd + " -p com.example.myapplication"
os.system(run_cmd)