Skip to content

Commit

Permalink
Merge pull request #10 from sisong/dev
Browse files Browse the repository at this point in the history
add hpatchi  NDK demo & fix bug
  • Loading branch information
sisong authored Aug 19, 2022
2 parents aacb163 + d295351 commit 4bd866b
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 13 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ jobs:
xcodebuild -workspace builds/xcode/HPatchLite.xcworkspace -scheme hpatchi -configuration Release OBJROOT=$PWD/bin SYMROOT=$PWD/bin
xcodebuild -workspace builds/xcode/HPatchLite.xcworkspace -scheme hdiffi -configuration Release OBJROOT=$PWD/bin SYMROOT=$PWD/bin
ndk-build:
strategy:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- uses: nttld/[email protected]
with:
ndk-version: r16b
- name: buildByAndroidNDK
run: |
git submodule update --init --recursive
cd ./builds/android_ndk_jni_mk
ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk NDK_APPLICATION_MK=./Application.mk
vc-build:
runs-on: windows-latest
steps:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# [HPatchLite](https://github.com/sisong/HPatchLite)
[![release](https://img.shields.io/badge/release-v0.4.1-blue.svg)](https://github.com/sisong/HPatchLite/releases)
[![release](https://img.shields.io/badge/release-v0.4.2-blue.svg)](https://github.com/sisong/HPatchLite/releases)
[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/sisong/HPatchLite/blob/main/LICENSE)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg)](https://github.com/sisong/HPatchLite/pulls)
[![+issue Welcome](https://img.shields.io/github/issues-raw/sisong/HPatchLite?color=green&label=%2Bissue%20welcome)](https://github.com/sisong/HPatchLite/issues)
Expand All @@ -10,9 +10,9 @@

HPatchLite is a lite version of [HDiffPatch](https://github.com/sisong/HDiffPatch), tiny code & ram requirements when patch on MCU,NB-IoT,...

The patch code(ROM occupancy) very small, compiled by Mbed Studio is 664 bytes.
Tip: if define _IS_RUN_MEM_SAFE_CHECK=0 can reduce 74 bytes;
if used tinyuz & define _IS_USED_SHARE_hpatch_lite_types=1, can reduce 52 bytes.
The patch code(ROM occupancy) very small, compiled by Mbed Studio is 670 bytes.
Tip: if used tinyuz & define _IS_USED_SHARE_hpatch_lite_types=1, can reduce 52 bytes;
if define _IS_RUN_MEM_SAFE_CHECK=0, can reduce 74 bytes.

At the same time, the patch memory(RAM occupancy) can also be very small,
RAM size = one decompress memory size + input cache size(>=3Byte) when patch.
Expand Down
8 changes: 4 additions & 4 deletions README_cn.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# [HPatchLite](https://github.com/sisong/HPatchLite)
[![release](https://img.shields.io/badge/release-v0.4.1-blue.svg)](https://github.com/sisong/HPatchLite/releases)
[![release](https://img.shields.io/badge/release-v0.4.2-blue.svg)](https://github.com/sisong/HPatchLite/releases)
[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/sisong/HPatchLite/blob/main/LICENSE)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg)](https://github.com/sisong/HPatchLite/pulls)
[![+issue Welcome](https://img.shields.io/github/issues-raw/sisong/HPatchLite?color=green&label=%2Bissue%20welcome)](https://github.com/sisong/HPatchLite/issues)
Expand All @@ -10,9 +10,9 @@

HPatchLite 是 [HDiffPatch](https://github.com/sisong/HDiffPatch) 的一个精简(Lite)版,为在MCU、NB-IoT等小型设备上执行打补丁(patch)功能而优化。

编译后的patch代码(ROM 占用)非常的小,用 Mbed Studio 编译后为 664 字节。
提示:设置宏_IS_RUN_MEM_SAFE_CHECK=0可以节省74字节
如果使用了tinyuz并且设置宏_IS_USED_SHARE_hpatch_lite_types=1,可以节省52字节
编译后的patch代码(ROM 占用)非常的小,用 Mbed Studio 编译后为 670 字节。
提示:如果使用了tinyuz并且设置宏_IS_USED_SHARE_hpatch_lite_types=1,可以节省52字节
设置宏_IS_RUN_MEM_SAFE_CHECK=0,可以节省74字节

同时,patch时内存(RAM 占用)也可以非常的小,
大小为 一个解压缩流需要的内存大小 + patch时输入的缓存区大小(>=3Byte)。
Expand Down
67 changes: 67 additions & 0 deletions builds/android_ndk_jni_mk/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := hpatchi

# args
LZMA := 0
TUZ := 1
ZLIB := 1 # -lz dynamic link unsafe for inflate_state

ifeq ($(LZMA),0)
Lzma_Files :=
else
# https://github.com/sisong/lzma
LZMA_PATH := $(LOCAL_PATH)/../../lzma/C/
Lzma_Files := $(LZMA_PATH)/LzmaDec.c \
$(LZMA_PATH)/Lzma2Dec.c
ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
Lzma_Files += $(LZMA_PATH)/../Asm/arm64/LzmaDecOpt.S
endif
endif
ifeq ($(TUZ),0)
Tuz_Files :=
else
# https://github.com/sisong/tinyuz
TUZ_PATH := $(LOCAL_PATH)/../../tinyuz/decompress/
Tuz_Files := $(TUZ_PATH)/tuz_dec.c
endif
ifeq ($(ZLIB),0)
else
# http://zlib.net/ https://github.com/madler/zlib
ZLIB_PATH := $(LOCAL_PATH)/../../zlib/
endif

HDP_PATH := $(LOCAL_PATH)/../../HDiffPatch
Hdp_Files := $(HDP_PATH)/file_for_patch.c \
$(HDP_PATH)/libHDiffPatch/HPatchLite/hpatch_lite.c

Src_Files := $(LOCAL_PATH)/hpatchi_jni.c \
$(LOCAL_PATH)/hpatchi.c

DEF_FLAGS := -Os -D_IS_NEED_DEFAULT_CompressPlugin=0
ifeq ($(LZMA),0)
else
DEF_FLAGS += -D_CompressPlugin_lzma -D_CompressPlugin_lzma2 -D_7ZIP_ST -I$(LZMA_PATH)
ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
DEF_FLAGS += -D_LZMA_DEC_OPT
endif
endif
ifeq ($(TUZ),0)
else
DEF_FLAGS += -D_CompressPlugin_tuz -I$(TUZ_PATH)
endif
ifeq ($(ZLIB),0)
else
DEF_FLAGS += -D_CompressPlugin_zlib -I$(ZLIB_PATH)
endif

LOCAL_SRC_FILES := $(Src_Files) $(Lzma_Files) $(Tuz_Files) $(Hdp_Files)
LOCAL_LDLIBS := -llog
ifeq ($(ZLIB),0)
else
LOCAL_LDLIBS += -lz
endif
LOCAL_CFLAGS := -DANDROID_NDK -DNDEBUG $(DEF_FLAGS)
include $(BUILD_SHARED_LIBRARY)

7 changes: 7 additions & 0 deletions builds/android_ndk_jni_mk/Application.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
APP_PLATFORM := android-14
APP_CFLAGS += -Wno-error=format-security
APP_CFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden
APP_CFLAGS += -ffunction-sections -fdata-sections
APP_LDFLAGS += -Wl,--gc-sections
APP_BUILD_SCRIPT := Android.mk
APP_ABI := armeabi armeabi-v7a arm64-v8a x86 x86_64
1 change: 1 addition & 0 deletions builds/android_ndk_jni_mk/build_libs.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk NDK_APPLICATION_MK=Application.mk
1 change: 1 addition & 0 deletions builds/android_ndk_jni_mk/build_libs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk NDK_APPLICATION_MK=Application.mk
10 changes: 10 additions & 0 deletions builds/android_ndk_jni_mk/hpatchi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// hpatchi.c
// Created by sisong on 2022-08-19.
#include "hpatchi.h"

#ifndef _IS_USED_MULTITHREAD
#define _IS_USED_MULTITHREAD 0
#endif
#define _IS_NEED_MAIN 0
#define _IS_NEED_ALL_CompressPlugin 0
#include "../../hpatchi.c"
20 changes: 20 additions & 0 deletions builds/android_ndk_jni_mk/hpatchi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// hpatchi.h
// Created by sisong on 2022-08-19.
#ifndef hpatchi_h
#define hpatchi_h
#include <assert.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
#define H_PATCH_EXPORT __attribute__((visibility("default")))

// return THPatchiResult, 0 is ok
// 'diffFileName' file is create by hdiffi app,or by create_lite_diff()
int hpatchi(const char *oldFileName,const char *diffFileName,
const char *outNewFileName, size_t cacheMemory) H_PATCH_EXPORT;

#ifdef __cplusplus
}
#endif
#endif // hpatchi_h
28 changes: 28 additions & 0 deletions builds/android_ndk_jni_mk/hpatchi_jni.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// hpatch_jni.c
// Created by sisong on 2022-08-19.
#include <jni.h>
#include "hpatchi.h"
#ifdef __cplusplus
extern "C" {
#endif

JNIEXPORT int
Java_com_github_sisong_hpatchi_patch(JNIEnv* jenv,jobject jobj,
jstring oldFileName,jstring diffFileName,
jstring outNewFileName,jlong cacheMemory){
const char* cOldFileName = (*jenv)->GetStringUTFChars(jenv,oldFileName, NULL);
const char* cDiffFileName = (*jenv)->GetStringUTFChars(jenv,diffFileName, NULL);
const char* cOutNewFileName = (*jenv)->GetStringUTFChars(jenv,outNewFileName, NULL);
size_t cCacheMemory=(size_t)cacheMemory;
assert((jlong)cCacheMemory==cacheMemory);
int result=hpatchi(cOldFileName,cDiffFileName,cOutNewFileName,cCacheMemory);
(*jenv)->ReleaseStringUTFChars(jenv,outNewFileName,cOutNewFileName);
(*jenv)->ReleaseStringUTFChars(jenv,diffFileName,cDiffFileName);
(*jenv)->ReleaseStringUTFChars(jenv,oldFileName,cOldFileName);
return result;
}

#ifdef __cplusplus
}
#endif

9 changes: 9 additions & 0 deletions builds/android_ndk_jni_mk/java/com/github/sisong/hpatchi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.github.sisong;

public class hpatchi{
// return THPatchiResult, 0 is ok
// 'diffFileName' file is create by hdiffi app,or by create_lite_diff()
// cacheMemory recommended 32*2024 256*1024 ...
public static native int patch(String oldFileName,String diffFileName,
String outNewFileName,long cacheMemory);
}
4 changes: 2 additions & 2 deletions decompresser_demo.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
# include "zlib.h" // http://zlib.net/ https://github.com/madler/zlib
#undef Byte
#define ZLIB_INTERNAL
# include "inftrees.h" //for code
# include "inftrees.h" //for inflate_state::code
#undef ZLIB_INTERNAL
# include "inflate.h" //for inflate_state
# include "inflate.h" //for inflate_state
#endif
typedef struct zlib_TStream{
hpi_TInputStreamHandle codeStream;
Expand Down
2 changes: 1 addition & 1 deletion hdiffi_import_patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extern "C" {
#endif
#define HPATCHLITE_VERSION_MAJOR 0
#define HPATCHLITE_VERSION_MINOR 4
#define HPATCHLITE_VERSION_RELEASE 1
#define HPATCHLITE_VERSION_RELEASE 2

#define _HPATCHLITE_VERSION HPATCHLITE_VERSION_MAJOR.HPATCHLITE_VERSION_MINOR.HPATCHLITE_VERSION_RELEASE
#define _HDIFFPATCH_QUOTE(str) #str
Expand Down

0 comments on commit 4bd866b

Please sign in to comment.