已开启
feat: 新增 community/libcsv 三方库适配 #2281
STF-Zero创建于 20 天前
feat: 新增 community/libcsv 三方库适配 #2281
已开启
共 11 个文件变更+452-0
| @@ -0,0 +1,235 @@ | |||
| 1 | +# Copyright (c) 2026 STF-Zero | ||
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +# you may not use this file except in compliance with the License. | ||
| 4 | +# You may obtain a copy of the License at | ||
| 5 | +# | ||
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +# | ||
| 8 | +# Unless required by applicable law or agreed to in writing, software | ||
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +# See the License for the specific language governing permissions and | ||
| 12 | +# limitations under the License. | ||
| 13 | +# | ||
| 14 | +# Contributor: STF-Zero <caoningxu@gmail.com> | ||
| 15 | +# Maintainer: STF-Zero <caoningxu@gmail.com> | ||
| 16 | +# buildtools=configure(Autotools)HPKBUILD 骨架 | ||
| 17 | +pkgname=libcsv | ||
| 18 | +pkgver=3.0.3 | ||
| 19 | +pkgrel=0 | ||
| 20 | +pkgdesc="libcsv is a small, simple and fast CSV library written in pure ANSI C89 that reads and writes CSV data" | ||
| 21 | +url="https://sourceforge.net/projects/libcsv/" | ||
| 22 | +license=("LGPL-2.1-or-later") | ||
| 23 | +makedepends=() | ||
| 24 | +source="https://downloads.sourceforge.net/project/libcsv/libcsv/libcsv-3.0.3/libcsv-3.0.3.tar.gz" | ||
| 25 | +archs=("armeabi-v7a" "arm64-v8a" "x86_64") | ||
| 26 | +builddir=${pkgname}-${pkgver} | ||
| 27 | +buildtools="configure" | ||
| 28 | +downloadpackage=true | ||
| 29 | +autounpack=false | ||
| 30 | +packagename=${pkgname}-${pkgver}.tar.gz | ||
| 31 | +patchflag=false | ||
| 32 | +depends=() | ||
| 33 | + | ||
| 34 | +prepare() { | ||
| 35 | + cd ${PKGBUILD_ROOT} | ||
| 36 | + # 统一解压函数(zip 用 -o 覆盖防交互卡死;tar 解压到确定目录) | ||
| 37 | + extract_archive() { | ||
| 38 | + local _arc="$1" _dst="$2" | ||
| 39 | + cd "$_dst" || return 1 | ||
| 40 | + case "$_arc" in | ||
| 41 | + *.tar.gz|*.tgz) tar -xzf "$_arc" ;; | ||
| 42 | + *.tar.bz2) tar -xjf "$_arc" ;; | ||
| 43 | + *.tar.xz) tar -xJf "$_arc" ;; | ||
| 44 | + *.zip) unzip -qo "$_arc" ;; | ||
| 45 | + *) echo "unsupported archive: $_arc"; return 1 ;; | ||
| 46 | + esac | ||
| 47 | + } | ||
| 48 | + if [ ! -d "$builddir" ]; then | ||
| 49 | + extract_archive "${packagename}" "${PKGBUILD_ROOT}" || return 1 | ||
| 50 | + fi | ||
| 51 | + if [ ! -d "$builddir" ]; then | ||
| 52 | + for _d in *; do | ||
| 53 | + if [ -d "$_d" ] && [ "$_d" != "logs" ] && [ "$_d" != "hpkbuild_history" ] && ! echo "$_d" | grep -q -- '-build$'; then | ||
| 54 | + # 只 mv 包含构建标志文件的目录(防止误 mv hpkbuild_history 等) | ||
| 55 | + if [ -f "$_d/Configure" ] || [ -f "$_d/configure" ] || [ -f "$_d/CMakeLists.txt" ] || [ -f "$_d/Makefile" ]; then | ||
| 56 | + mv "$_d" "$builddir" 2>/dev/null && break | ||
| 57 | + fi | ||
| 58 | + fi | ||
| 59 | + done | ||
| 60 | + fi | ||
| 61 | + # 唯一目录兜底:H+P 项目可能由 patch 创建构建系统(poly1305 真实案例), | ||
| 62 | + # 源码目录在打补丁前没有 CMakeLists.txt/configure/Makefile,不能依赖 | ||
| 63 | + # 构建标记识别。排除 logs/hpkbuild_history/隐藏目录/*-build 后若只剩一个 | ||
| 64 | + # 普通目录,则规范化为 $builddir;多个候选时 fail closed。 | ||
| 65 | + if [ ! -d "$builddir" ]; then | ||
| 66 | + _candidates=() | ||
| 67 | + for _d in *; do | ||
| 68 | + if [ -d "$_d" ] && [ "$_d" != "logs" ] && [ "$_d" != "hpkbuild_history" ] && [ "${_d:0:1}" != "." ] && ! echo "$_d" | grep -q -- '-build$'; then | ||
| 69 | + _candidates+=("$_d") | ||
| 70 | + fi | ||
| 71 | + done | ||
| 72 | + if [ "${#_candidates[@]}" -eq 1 ]; then | ||
| 73 | + mv "${_candidates[0]}" "$builddir" 2>/dev/null || return 1 | ||
| 74 | + fi | ||
| 75 | + fi | ||
| 76 | + [ -d "$builddir" ] || return 1 | ||
| 77 | + # 双层嵌套规范化(nspr 实证):归档根 builddir/ 内含唯一源码目录 | ||
| 78 | + # (如 builddir/nspr/ 有 configure)时提升到 builddir,否则 build() 在 | ||
| 79 | + # 错误目录触发 autoreconf -> "configure.ac is required"。 | ||
| 80 | + if [ ! -f "$builddir/configure" ] && [ ! -f "$builddir/configure.ac" ] && [ ! -f "$builddir/CMakeLists.txt" ]; then | ||
| 81 | + _inner="" | ||
| 82 | + for _d in "$builddir"/*/; do | ||
| 83 | + [ -d "${_d%/}" ] || continue | ||
| 84 | + case "${_d%/}" in *-build|*logs*|*hpkbuild_history*) continue;; esac | ||
| 85 | + if [ -f "${_d}configure" ] || [ -f "${_d}configure.ac" ] || [ -f "${_d}configure.in" ] || [ -f "${_d}CMakeLists.txt" ] || [ -f "${_d}Makefile" ] || [ -f "${_d}meson.build" ]; then | ||
| 86 | + if [ -z "$_inner" ]; then _inner="${_d%/}"; else _inner=""; break; fi | ||
| 87 | + fi | ||
| 88 | + done | ||
| 89 | + if [ -n "$_inner" ]; then | ||
| 90 | + mv "$_inner" "${builddir}-__inner" | ||
| 91 | + rm -rf "$builddir" | ||
| 92 | + mv "${builddir}-__inner" "$builddir" | ||
| 93 | + echo "[nest] 双层嵌套源码已提升: $builddir" >> $buildlog | ||
| 94 | + fi | ||
| 95 | + fi | ||
| 96 | + # patch 应用:H+P 项目在 clean rebuild 中必须重放补丁(poly1305 真实案例 | ||
| 97 | + # ——patch 创建 CMakeLists.txt,不打补丁则源码目录无构建入口) | ||
| 98 | + if $patchflag; then | ||
| 99 | + cd "$builddir" || return 1 | ||
| 100 | + if [ ! -f .oh_patch_applied ]; then | ||
| 101 | + _PATCHED=0 | ||
| 102 | + for _pl in 1 0 2; do | ||
| 103 | + patch -N -p${_pl} --batch --forward < "../${pkgname}_oh_pkg.patch" >/dev/null 2>&1 | ||
| 104 | + _rc=$? | ||
| 105 | + if [ $_rc -eq 0 ]; then _PATCHED=1; break; fi | ||
| 106 | + # rc=1 可能是"已应用/反转"(-N 下常见):补丁首个目标文件存在即视为已就位 | ||
| 107 | + _first=$(grep -m1 '^+++' "../${pkgname}_oh_pkg.patch" | sed 's/^+++ //; s/ .*//; s/^[ab]\///') | ||
| 108 | + if [ -n "$_first" ] && [ -f "$_first" ]; then _PATCHED=1; break; fi | ||
| 109 | + done | ||
| 110 | + [ "$_PATCHED" -eq 1 ] || { echo "patch 应用失败(-p1/-p0/-p2 均无效)" >> $buildlog; return 1; } | ||
| 111 | + touch .oh_patch_applied | ||
| 112 | + fi | ||
| 113 | + cd ${PKGBUILD_ROOT} | ||
| 114 | + fi | ||
| 115 | + source envset.sh | ||
| 116 | + rm -rf ${builddir}-${ARCH}-build | ||
| 117 | + cp -r ${builddir} ${builddir}-${ARCH}-build | ||
| 118 | + return 0 | ||
| 119 | +} | ||
| 120 | + | ||
| 121 | +build() { | ||
| 122 | + cd ${PKGBUILD_ROOT}/${builddir}-${ARCH}-build || return 1 | ||
| 123 | + # 按 ARCH 加载交叉编译环境(source envset.sh 只定义函数,必须调用 | ||
| 124 | + # setarm32ENV/setarm64ENV/setx86_64ENV 才会设置 CC/AR/RANLIB/CFLAGS—— | ||
| 125 | + # 否则 configure 会回退宿主 gcc,产物混入宿主架构) | ||
| 126 | + source envset.sh 2>/dev/null | ||
| 127 | + case "${ARCH}" in | ||
| 128 | + armeabi-v7a) setarm32ENV ;; | ||
| 129 | + arm64-v8a) setarm64ENV ;; | ||
| 130 | + x86_64) setx86_64ENV ;; | ||
| 131 | + *) echo "unsupported ARCH: ${ARCH}" >&2; return 1 ;; | ||
| 132 | + esac | ||
| 133 | + export CC AR RANLIB CFLAGS CXXFLAGS | ||
| 134 | + # 依赖按 ARCH 注入 -I/-L + pkgconfig 路径(configure 需要 CPPFLAGS/ | ||
| 135 | + # LDFLAGS 才能找到 lycium 依赖头文件/库)。 | ||
| 136 | + # 【传递依赖铁律】必须包含直接 depends 之外的传递依赖:freetype2.pc | ||
| 137 | + # 的 Requires: zlib/libpng/libbrotlidec 不在 fontconfig 的 depends 里, | ||
| 138 | + # 而 lycium configuredependpath 只注入直接依赖 → pkg-config 报 | ||
| 139 | + # "Package 'zlib', required by 'freetype2', not found"(fontconfig 实证)。 | ||
| 140 | + # 做法:扫描 usr 下所有已安装包的同架构目录(跳过自身),合并 | ||
| 141 | + # pkgconfig/include/lib 进 PKG_CONFIG_LIBDIR/CPPFLAGS/LDFLAGS。 | ||
| 142 | + for _dep_dir in ${LYCIUM_ROOT}/usr/*/${ARCH}; do | ||
| 143 | + _dep_pkg=$(basename "$(dirname "${_dep_dir}")") | ||
| 144 | + [ "${_dep_pkg}" = "${pkgname}" ] && continue | ||
| 145 | + [ -d "${_dep_dir}/lib/pkgconfig" ] && PKG_CONFIG_LIBDIR="${PKG_CONFIG_LIBDIR:+${PKG_CONFIG_LIBDIR}:}${_dep_dir}/lib/pkgconfig" | ||
| 146 | + [ -d "${_dep_dir}/include" ] && CPPFLAGS="${CPPFLAGS} -I${_dep_dir}/include" | ||
| 147 | + [ -d "${_dep_dir}/lib" ] && LDFLAGS="${LDFLAGS} -L${_dep_dir}/lib" | ||
| 148 | + done | ||
| 149 | + export CPPFLAGS LDFLAGS PKG_CONFIG_LIBDIR | ||
| 150 | + # configure-family 确定性分支:按构建入口文件存在性选择,禁止硬编码包名 | ||
| 151 | + if [ "${ARCH}" == "armeabi-v7a" ]; then | ||
| 152 | + _HOST_TRIPLE=arm-linux | ||
| 153 | + _CFG_TARGET=linux-armv4 | ||
| 154 | + elif [ "${ARCH}" == "x86_64" ]; then | ||
| 155 | + _HOST_TRIPLE=x86_64-linux | ||
| 156 | + _CFG_TARGET=linux-x86_64 | ||
| 157 | + else | ||
| 158 | + _HOST_TRIPLE=aarch64-linux | ||
| 159 | + _CFG_TARGET=linux-aarch64 | ||
| 160 | + fi | ||
| 161 | + # configure.ac-only 源码(github 归档不含生成的 configure)须先 | ||
| 162 | + # autogen.sh / autoreconf -fi(libiscsi 实证:最终 HPKBUILD 缺此步, | ||
| 163 | + # verifier 清源重建后 ./configure 不存在 → No such file or directory) | ||
| 164 | + if [ ! -x ./configure ]; then | ||
| 165 | + if [ -x ./autogen.sh ]; then | ||
| 166 | + chmod +x autogen.sh 2>/dev/null | ||
| 167 | + ./autogen.sh >> $buildlog 2>&1 || return 1 | ||
| 168 | + elif [ -f configure.ac ]; then | ||
| 169 | + autoreconf -fi >> $buildlog 2>&1 || return 1 | ||
| 170 | + fi | ||
| 171 | + fi | ||
| 172 | + if [ -x ./configure ]; then | ||
| 173 | + # Autotools:必须 --host 进入 cross-compiling 模式(config.sub 不 | ||
| 174 | + # 识别 ohos triple,用 arm-linux/aarch64-linux 近似) | ||
| 175 | + if ./configure "$@" --host=${_HOST_TRIPLE} \ | ||
| 176 | + --prefix=${LYCIUM_ROOT}/usr/${pkgname}/${ARCH} > $buildlog 2>&1; then | ||
| 177 | + : | ||
| 178 | + elif grep -qiE "config\.sub|config\.guess" $buildlog; then | ||
| 179 | + # 上游 autotools 元数据过旧:libcsv 3.0.3 的 config.sub 是 2007 年 | ||
| 180 | + # 版本,完全不认识 aarch64,--host 在 config.sub 处直接失败 | ||
| 181 | + # (`./config.sub aarch64-linux failed`)。确定性修复:autoreconf -fi | ||
| 182 | + # 重建 config.sub/config.guess 后用同一 --host 重试。绝不能退化成 | ||
| 183 | + # "去掉 --host"——那会让 autotools 走本机编译并报 | ||
| 184 | + # "cannot run C compiled programs"(libcsv 实证两次都失败)。 | ||
| 185 | + echo "WARN: config.sub/config.guess 过旧,autoreconf -fi 重建后重试" >> $buildlog | ||
| 186 | + autoreconf -fi >> $buildlog 2>&1 || true | ||
| 187 | + ./configure "$@" --host=${_HOST_TRIPLE} \ | ||
| 188 | + --prefix=${LYCIUM_ROOT}/usr/${pkgname}/${ARCH} >> $buildlog 2>&1 || return 1 | ||
| 189 | + elif grep -qiE "invalid host type|--host|unrecognized option" $buildlog; then | ||
| 190 | + # zlib 等自研 configure 不接受 autotools --host(zlib 实证): | ||
| 191 | + # 去掉 --host 重试,交叉编译经 CC/AR/RANLIB 环境变量完成。 | ||
| 192 | + ./configure "$@" \ | ||
| 193 | + --prefix=${LYCIUM_ROOT}/usr/${pkgname}/${ARCH} >> $buildlog 2>&1 || return 1 | ||
| 194 | + else | ||
| 195 | + return 1 | ||
| 196 | + fi | ||
| 197 | + elif [ -x ./Configure ]; then | ||
| 198 | + # Configure-family(如 OpenSSL 自带 Perl Configure):不接受 --host, | ||
| 199 | + # 需目标三元组 + 绝对 --prefix;工具链环境由 prepare 的 | ||
| 200 | + # setarm32ENV/setarm64ENV 提供;包特异参数(--openssldir/install_sw | ||
| 201 | + # 等)按需在此补充 | ||
| 202 | + ./Configure ${_CFG_TARGET} \ | ||
| 203 | + --prefix=${LYCIUM_ROOT}/usr/${pkgname}/${ARCH} > $buildlog 2>&1 || return 1 | ||
| 204 | + else | ||
| 205 | + echo "No supported configure entrypoint (./configure or ./Configure)" >> $buildlog | ||
| 206 | + return 1 | ||
| 207 | + fi | ||
| 208 | + make -j2 >> $buildlog 2>&1 || return 1 | ||
| 209 | + # 上游测试二进制可能不在默认(交叉)构建目标内:显式构建 test/check 规则 | ||
| 210 | + # 里的真实目标依赖,保证设备侧 HPKCHECK 有上游测试产物。只构建、不执行。 | ||
| 211 | + if [ -f Makefile ]; then | ||
| 212 | + for _t in $(awk -F: '/^(test|check):/ {print $2}' Makefile | tr ' ' '\n'); do | ||
| 213 | + case "${_t}" in ''|*'$'*|*'('*|*')'*|all|install|clean|test|check) continue;; esac | ||
| 214 | + grep -q "^${_t}[[:space:]]*:" Makefile || continue | ||
| 215 | + make -j${JOB:-4} "${_t}" >> $buildlog 2>&1 || true | ||
| 216 | + done | ||
| 217 | + fi | ||
| 218 | + return 0 | ||
| 219 | +} | ||
| 220 | + | ||
| 221 | +package() { | ||
| 222 | + cd ${PKGBUILD_ROOT}/${builddir}-${ARCH}-build || return 1 | ||
| 223 | + make install >> $buildlog 2>&1 || return 1 | ||
| 224 | + return 0 | ||
| 225 | +} | ||
| 226 | + | ||
| 227 | +cleanbuild() { | ||
| 228 | + cd ${PKGBUILD_ROOT} | ||
| 229 | + rm -rf ${PWD}/${builddir} ${PWD}/${builddir}-*-build | ||
| 230 | + return 0 | ||
| 231 | +} | ||
| 232 | + | ||
| 233 | +check() { | ||
| 234 | + echo "The test must be on an OpenHarmony device!" | ||
| 235 | +} | ||
| @@ -0,0 +1,57 @@ | |||
| 1 | +#!/bin/sh | ||
| 2 | +# Copyright (c) 2026 STF-Zero | ||
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | +# you may not use this file except in compliance with the License. | ||
| 5 | +# You may obtain a copy of the License at | ||
| 6 | +# | ||
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | +# | ||
| 9 | +# Unless required by applicable law or agreed to in writing, software | ||
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | +# See the License for the specific language governing permissions and | ||
| 13 | +# limitations under the License. | ||
| 14 | +# | ||
| 15 | +# Contributor: STF-Zero <caoningxu@gmail.com> | ||
| 16 | +# Maintainer: STF-Zero <caoningxu@gmail.com> | ||
| 17 | +# HARNESS_EXPECTED_CASES = 1 | ||
| 18 | +# HARNESS_TEST_ORIGIN = harness_authored | ||
| 19 | +# HARNESS_HPKCHECK_AUTOGENERATED = 1 | ||
| 20 | +# HARNESS_SMOKE_SOURCE = consumer_smoke(csv.h + libcsv.a) | ||
| 21 | +# HARNESS_RUNTIME_FILES = harness_smoke/libcsv_smoke | ||
| 22 | +# HARNESS_RUNTIME_INSTALL = full | ||
| 23 | +. ./HPKBUILD >/dev/null 2>&1 | ||
| 24 | +logfile=${LYCIUM_THIRDPARTY_ROOT}/${pkgname}/${pkgname}_${ARCH}_harness_test.log | ||
| 25 | +build_root=${LYCIUM_THIRDPARTY_ROOT}/${pkgname}/${builddir}-${ARCH}-build | ||
| 26 | +checkprepare() { | ||
| 27 | + for _d in "${LYCIUM_ROOT}"/usr/*/"${ARCH}"/lib; do | ||
| 28 | + [ -d "$_d" ] && LD_LIBRARY_PATH="${_d}:${LD_LIBRARY_PATH}" | ||
| 29 | + done | ||
| 30 | + export LD_LIBRARY_PATH | ||
| 31 | +} | ||
| 32 | +run_case() { | ||
| 33 | + case_name=$1 | ||
| 34 | + binary=$2 | ||
| 35 | + shift 2 | ||
| 36 | + case_log=${logfile}.${case_name} | ||
| 37 | + if [ ! -x "${binary}" ]; then | ||
| 38 | + echo "missing harness smoke executable: ${binary}" > "${case_log}" | ||
| 39 | + result=1 | ||
| 40 | + else | ||
| 41 | + (cd "${build_root}" && "${binary}" "$@") > "${case_log}" 2>&1 | ||
| 42 | + result=$? | ||
| 43 | + fi | ||
| 44 | + cat "${case_log}" >> "${logfile}" | ||
| 45 | + if [ ${result} -eq 0 ]; then | ||
| 46 | + echo "HARNESS_CASE ${case_name} PASS" | tee -a "${logfile}" | ||
| 47 | + else | ||
| 48 | + echo "HARNESS_CASE ${case_name} FAIL" | tee -a "${logfile}" | ||
| 49 | + fi | ||
| 50 | + return ${result} | ||
| 51 | +} | ||
| 52 | +openharmonycheck() { | ||
| 53 | + : > "${logfile}" | ||
| 54 | + status=0 | ||
| 55 | + run_case harness-smoke "${build_root}/harness_smoke/libcsv_smoke" || status=1 | ||
| 56 | + return ${status} | ||
| 57 | +} | ||
| @@ -0,0 +1,16 @@ | |||
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<configuration> | ||
| 3 | + <oatconfig> | ||
| 4 | + <filefilterlist> | ||
| 5 | + <filefilter name="copyrightPolicyFilter" desc="Filters for compatibility,license header policies"> | ||
| 6 | + <filteritem type="filename" name="SHA512SUM" desc="SHA512SUM文件,不添加版权头"/> | ||
| 7 | + </filefilter> | ||
| 8 | + <filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies"> | ||
| 9 | + <filteritem type="filename" name="SHA512SUM" desc="SHA512SUM文件,不添加版权头"/> | ||
| 10 | + </filefilter> | ||
| 11 | + <filefilter name="binaryFileTypePolicyFilter" desc="Filters for resources files policies"> | ||
| 12 | + <filteritem type="filename" name="*.png" desc="指导文档需要的png图片"/> | ||
| 13 | + </filefilter> | ||
| 14 | + </filefilterlist> | ||
| 15 | + </oatconfig> | ||
| 16 | +</configuration> | ||
| @@ -0,0 +1,11 @@ | |||
| 1 | +[ | ||
| 2 | + { | ||
| 3 | + "Name": "libcsv", | ||
| 4 | + "License": "LGPL-2.1-or-later", | ||
| 5 | + "License File": "COPYING", | ||
| 6 | + "Version Number": "3.0.3", | ||
| 7 | + "Owner": "caoningxu@gmail.com", | ||
| 8 | + "Upstream URL": "https://sourceforge.net/projects/libcsv/", | ||
| 9 | + "Description": "libcsv is a small, simple and fast CSV library written in pure ANSI C89 that reads and writes CSV data" | ||
| 10 | + } | ||
| 11 | +] | ||
| @@ -0,0 +1,27 @@ | |||
| 1 | +# libcsv三方库说明 | ||
| 2 | + | ||
| 3 | +## 功能简介 | ||
| 4 | + | ||
| 5 | +libcsv is a small, simple and fast CSV library written in pure ANSI C89 that reads and writes CSV data | ||
| 6 | + | ||
| 7 | +- 上游地址:https://sourceforge.net/projects/libcsv/ | ||
| 8 | +- 版本:3.0.3 | ||
| 9 | +- 开源协议:LGPL-2.1-or-later | ||
| 10 | +- 支持的架构:armeabi-v7a, arm64-v8a, x86_64 | ||
| 11 | +- 构建方式:configure | ||
| 12 | + | ||
| 13 | +## 三方库版本 | ||
| 14 | + | ||
| 15 | +- 3.0.3 | ||
| 16 | + | ||
| 17 | +## 已适配功能 | ||
| 18 | + | ||
| 19 | +- Installation ------------ installation usually consists of: ./configure && make && make check && make install | ||
| 20 | + | ||
| 21 | +## 使用约束 | ||
| 22 | + | ||
| 23 | +- [IDE和SDK版本](../../docs/constraint.md) | ||
| 24 | + | ||
| 25 | +## 集成方式 | ||
| 26 | + | ||
| 27 | +[应用包hap集成](docs/hap_integrate.md) | ||
| @@ -0,0 +1 @@ | |||
| 1 | +e657b166ce9e0159aab14edda9b5513922ee1a307065ba264342457629b13e8380f96b3ebabc690fd868dad23efc624362272ffe7c8b2acba8ad9e920dde7172 libcsv-3.0.3.tar.gz | ||
| @@ -0,0 +1,105 @@ | |||
| 1 | +# libcsv如何集成到应用hap | ||
| 2 | + | ||
| 3 | +本库已基于 OpenHarmony 镜像完成交叉编译与设备端加载验证(版本 3.0.3)。 | ||
| 4 | + | ||
| 5 | +实测环境:`arm64-v8a`(QEMU 裁剪镜像(模拟),目标 `127.0.0.1:5855`,`uname -m=aarch64`);`armeabi-v7a`(QEMU 裁剪镜像(模拟),目标 `127.0.0.1:5755`,`uname -m=armv7l`)。 | ||
| 6 | + | ||
| 7 | +以上均为**模拟运行环境,不是物理真机**;真机(开发板/手机/平板)验证:**未做**(上方均为模拟环境)。 | ||
| 8 | +社区标准验证环境为 [润和 RK3568 开发板](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)(OpenHarmony 3.2 Release 镜像),本库未使用该开发板;验证过程与结果见 `docs/pic/` 截图。 | ||
| 9 | + | ||
| 10 | +## 准备应用工程 | ||
| 11 | + | ||
| 12 | +### 准备应用开发环境 | ||
| 13 | + | ||
| 14 | +- [开发环境准备](../../../docs/hap_integrate_environment.md) | ||
| 15 | + | ||
| 16 | +### 增加构建脚本及配置文件 | ||
| 17 | + | ||
| 18 | +本库的构建脚本与配置文件:`HPKBUILD`(交叉编译脚本)、`HPKCHECK`(设备端测试入口)、`OAT.xml`(版权头豁免),详见 [HPKBUILD](../HPKBUILD) 与 [HPKCHECK](../HPKCHECK)。 | ||
| 19 | + | ||
| 20 | +应用工程侧,在最外层(cpp 目录下)`CMakeLists.txt` 中添加如下语句: | ||
| 21 | + | ||
| 22 | +```shell | ||
| 23 | + #将三方库加入工程中 | ||
| 24 | + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libcsv/${OHOS_ARCH}/lib/libcsv.so) | ||
| 25 | + | ||
| 26 | + #将三方库的头文件加入工程中 | ||
| 27 | + target_include_directories(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libcsv/${OHOS_ARCH}/include) | ||
| 28 | +``` | ||
| 29 | + | ||
| 30 | +### 准备三方库源码 | ||
| 31 | + | ||
| 32 | +- 下载本仓库 | ||
| 33 | + | ||
| 34 | + ```shell | ||
| 35 | + git clone https://gitcode.com/CPF-ApplicationTPC/tpc_c_cplusplus.git --depth=1 | ||
| 36 | + ``` | ||
| 37 | + | ||
| 38 | +- 三方库目录结构 | ||
| 39 | + | ||
| 40 | + ```shell | ||
| 41 | + tpc_c_cplusplus/community/libcsv #三方库libcsv的目录结构如下 | ||
| 42 | + ├── docs #三方库相关文档的文件夹 | ||
| 43 | + ├── HPKBUILD #构建脚本 | ||
| 44 | + ├── HPKCHECK #测试脚本 | ||
| 45 | + ├── SHA512SUM #三方库校验文件 | ||
| 46 | + ├── OAT.xml #OAT开源审查文本文件 | ||
| 47 | + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 | ||
| 48 | + ├── README_zh.md #三方库简介 | ||
| 49 | + ``` | ||
| 50 | + | ||
| 51 | +## 应用中使用三方库 | ||
| 52 | + | ||
| 53 | +- 在IDE的cpp目录下新增thirdparty目录,将编译产物 `lycium/usr/libcsv/<abi>/` 下的 `include/` 与 `lib/` 拷贝进去,形成 `cpp/thirdparty/libcsv/<abi>/{include,lib}`(动态库名字带版本号和不带版本号的都需要;`share/`、`cmake/` 等非头文件/库内容可以不拷),如下图所示: | ||
| 54 | + | ||
| 55 | + | ||
| 56 | + | ||
| 57 | +  | ||
| 58 | + | ||
| 59 | +## 编译工程 | ||
| 60 | + | ||
| 61 | +- 在lycium目录下编译三方库 | ||
| 62 | + | ||
| 63 | + 编译环境的搭建参考[准备三方库构建环境](../../../lycium/README.md#1编译环境准备) | ||
| 64 | + | ||
| 65 | + ```shell | ||
| 66 | + cd lycium | ||
| 67 | + ./build.sh libcsv | ||
| 68 | + ``` | ||
| 69 | + | ||
| 70 | +- 三方库头文件及生成的库 | ||
| 71 | + | ||
| 72 | + 在lycium目录下会生成usr目录,该目录下存在已编译完成的32位和64位三方库 | ||
| 73 | + | ||
| 74 | + ```shell | ||
| 75 | + libcsv/armeabi-v7a libcsv/arm64-v8a libcsv/x86_64 | ||
| 76 | + ``` | ||
| 77 | + | ||
| 78 | +- [测试三方库](#测试三方库) | ||
| 79 | + | ||
| 80 | +## 测试三方库 | ||
| 81 | + | ||
| 82 | +- 上游未提供可独立交叉编译的测试套件,本库交付的是自撰的消费者冒烟用例与符号级探针,已随 `HPKCHECK` 下发设备执行。 | ||
| 83 | + | ||
| 84 | +- 进入构建目录运行冒烟用例(`arm64-v8a` 为构建64位的目录,`armeabi-v7a` 为构建32位的目录),执行结果如图所示: | ||
| 85 | + | ||
| 86 | +```shell | ||
| 87 | + cd /data/tpc_c_cplusplus/thirdparty/libcsv/libcsv-3.0.3-arm64-v8a-build/ | ||
| 88 | + ./harness_smoke/libcsv_smoke | ||
| 89 | +``` | ||
| 90 | + | ||
| 91 | +  | ||
| 92 | +  | ||
| 93 | +  | ||
| 94 | + | ||
| 95 | +## 运行效果 | ||
| 96 | + | ||
| 97 | +本库已完成设备端加载与用例验证(设备端执行记录见 `docs/pic/` 截图);应用侧(HAP)集成后的运行效果截图后续补充。 | ||
| 98 | + | ||
| 99 | +## 参考资料 | ||
| 100 | + | ||
| 101 | +- [润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) | ||
| 102 | +- [OpenHarmony三方库地址](https://gitee.com/openharmony-tpc) | ||
| 103 | +- [OpenHarmony知识体系](https://gitee.com/openharmony-sig/knowledge) | ||
| 104 | +- [通过DevEco Studio开发一个NAPI工程](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md) | ||
| 105 | +- 上游源码:https://downloads.sourceforge.net/project/libcsv/libcsv/libcsv-3.0.3/libcsv-3.0.3.tar.gz | ||