Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adapter to harmonyos for xlog #1224

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions mars/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,31 @@ if(ANDROID)
libzstd_static
${SSL_LIB}
${CRYPT_LIB})

elseif(OHOS)
message("start build ohos")
add_definitions(-DOHOS)
if(NATIVE_CALLBACK)
message("common native callback")
add_definitions(-DNATIVE_CALLBACK)
endif()

link_directories(app baseevent xlog sdt stn comm boost zstd)

# marsxlog
set(SELF_LIB_NAME marsxlog)
file(GLOB SELF_SRC_FILES ohoslibraries/mars_xlog_sdk/import.cc)
add_library(${SELF_LIB_NAME} SHARED ${SELF_SRC_FILES})
install(TARGETS ${SELF_LIB_NAME} LIBRARY DESTINATION ${SELF_LIBS_OUT} ARCHIVE DESTINATION ${SELF_LIBS_OUT})
get_filename_component(EXPORT_XLOG_EXP_FILE ohoslibraries/export.exp ABSOLUTE)
set(SELF_XLOG_LINKER_FLAG "-Wl,--gc-sections -Wl,--version-script='${EXPORT_XLOG_EXP_FILE}'")
target_link_libraries(${SELF_LIB_NAME} "-Wl,--gc-sections"
xlog
mars-boost
comm
libzstd_static
libace_napi.z.so
libhilog_ndk.z.so
libz.so
)
endif()
4 changes: 3 additions & 1 deletion mars/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ project (app)

include(../comm/CMakeUtils.txt)
include(../comm/CMakeExtraFlags.txt)

if(OHOS)
add_definitions(-DOHOS)
endif()
include_directories(.)
include_directories(src)
include_directories(..)
Expand Down
4 changes: 3 additions & 1 deletion mars/baseevent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ project (baseevent)
include(../comm/CMakeUtils.txt)
include(../comm/CMakeExtraFlags.txt)


if(OHOS)
add_definitions(-DOHOS)
endif()
include_directories(.)
include_directories(src)
include_directories(..)
Expand Down
4 changes: 3 additions & 1 deletion mars/boot/CMakeLists.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得add_definitions(-DOHOS)放到编译脚本中更好,不要每个CMakeLists.txt都加一遍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好建议

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ project(boot)

include(../comm/CMakeUtils.txt)
include(../comm/CMakeExtraFlags.txt)

if(OHOS)
add_definitions(-DOHOS)
endif()
include_directories(.)
include_directories(src)
include_directories(..)
Expand Down
153 changes: 153 additions & 0 deletions mars/build_ohos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#!/usr/bin/env python3
import os
import sys
import glob
import time
import shutil
import platform

from mars_utils import *


SCRIPT_PATH = os.path.split(os.path.realpath(__file__))[0]

def system_is_windows():
return platform.system() == 'Windows'

def system_architecture_is64():
return platform.machine().endswith('64')


if system_is_windows():
OHOS_GENERATOR = '-G "Unix Makefiles"'
else:
OHOS_GENERATOR = ''

try:
OHOS_SDK_ROOT = os.environ['OHOS_SDK_ROOT']
except KeyError as identifier:
OHOS_SDK_ROOT = ''


BUILD_OUT_PATH = 'cmake_build/ohos'
OHOS_LIBS_INSTALL_PATH = BUILD_OUT_PATH + '/'
OHOS_BUILD_CMD = 'cmake %s -DOHOS_ARCH="%s" ' \
'-DOHOS_PLATFORM=OHOS -DCMAKE_TOOLCHAIN_FILE=%s/openharmony/11/native/build/cmake/ohos.toolchain.cmake ' \
'-DOHOS_STL="c++_shared" ' \
'&& cmake --build . '
OHOS_SYMBOL_PATH = 'ohoslibraries/mars_ohos_sdk/obj/local/'
OHOS_LIBS_PATH = 'ohoslibraries/mars_ohos_sdk/libs/'
OHOS_XLOG_SYMBOL_PATH = 'ohoslibraries/mars_xlog_sdk/obj/local/'
OHOS_XLOG_LIBS_PATH = 'ohoslibraries/mars_xlog_sdk/libs/'


OHOS_STL_FILE = {
'armeabi-v7a': OHOS_SDK_ROOT + '/openharmony/11/native/llvm/lib/arm-linux-ohos/libc++_shared.so',
'x86': OHOS_SDK_ROOT + '/sources/cxx-stl/llvm-libc++/libs/x86_64-linux-ohos/libc++_shared.so',
'arm64-v8a': OHOS_SDK_ROOT + '/openharmony/11/native/llvm/lib/aarch64-linux-ohos/libc++_shared.so',
'x86_64': OHOS_SDK_ROOT + '/sources/cxx-stl/llvm-libc++/libs/x86_64-linux-ohos/libc++_shared.so',
}



def build_ohos(incremental, arch, target_option=''):

before_time = time.time()

clean(BUILD_OUT_PATH, incremental)
os.chdir(BUILD_OUT_PATH)

build_cmd = OHOS_BUILD_CMD %(SCRIPT_PATH, arch, OHOS_SDK_ROOT)
print("build cmd:" + build_cmd)
ret = os.system(build_cmd)
os.chdir(SCRIPT_PATH)

if 0 != ret:
print('!!!!!!!!!!!!!!!!!!build fail!!!!!!!!!!!!!!!!!!!!')
return False

if len(target_option) > 0:
symbol_path = OHOS_XLOG_SYMBOL_PATH
lib_path = OHOS_XLOG_LIBS_PATH
else:
symbol_path = OHOS_SYMBOL_PATH
lib_path = OHOS_LIBS_PATH

if not os.path.exists(symbol_path):
os.makedirs(symbol_path)

symbol_path = symbol_path + arch
if os.path.exists(symbol_path):
shutil.rmtree(symbol_path)

os.mkdir(symbol_path)


if not os.path.exists(lib_path):
os.makedirs(lib_path)

lib_path = lib_path + arch
if os.path.exists(lib_path):
shutil.rmtree(lib_path)

os.mkdir(lib_path)


for f in glob.glob(OHOS_LIBS_INSTALL_PATH + "*.so"):
shutil.copy(f, symbol_path)
shutil.copy(f, lib_path)

# copy stl
shutil.copy(OHOS_STL_FILE[arch], symbol_path)
shutil.copy(OHOS_STL_FILE[arch], lib_path)


print('==================Output========================')
print('libs(release): %s' %(lib_path))
print('symbols(must store permanently): %s' %(symbol_path))


after_time = time.time()

print("use time:%d s" % (int(after_time - before_time)))
return True

def main(incremental, archs, target_option='', tag=''):
gen_mars_revision_file(SCRIPT_PATH + '/comm', tag)

# if os.path.exists(OHOS_LIBS_PATH):
# shutil.rmtree(OHOS_LIBS_PATH)

# if os.path.exists(OHOS_SYMBOL_PATH):
# shutil.rmtree(OHOS_SYMBOL_PATH)

for arch in archs:
if not build_ohos(incremental, arch, target_option):
return

if __name__ == '__main__':

while True:
if len(sys.argv) >= 3:
archs = sys.argv[2:]
main(False, archs, tag=sys.argv[1])
break
else:
archs = {'armeabi-v7a', 'arm64-v8a'}
num = input('Enter menu:\n1. Clean && build mars.\n2. Build incrementally mars.\n3. Clean && build xlog.\n4. Exit\n')
if num == '1':
main(False, archs)
break
elif num == '2':
main(True, archs)
break
elif num == '3':
main(False, archs, '--target libzstd_static marsxlog')
break
elif num == '4':
break
else:
main(False, archs)
break


5 changes: 4 additions & 1 deletion mars/comm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ project (comm)

include(CMakeUtils.txt)
include(CMakeExtraFlags.txt)

if(OHOS)
message("common ohos...")
add_definitions(-DOHOS)
endif()
include_directories(.)
include_directories(..)
include_directories(../..)
Expand Down
9 changes: 8 additions & 1 deletion mars/comm/assert/__assert.h
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__BEGIN_EXTERN_C/__END_EXTERN_C应该是定义在sys/cdefs.h中的,如果目前鸿蒙没有提供相应的头文件的话,我认为应该在项目中新加一个sys/cdefs.h,而不是把__BEGIN_EXTERN_C定义到现有的项目文件中。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在鸿蒙还不稳定,稳定版本里面有sys/cdefs.h

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
#define ASSERT2(e, fmt, ...) ((e) ? (void)0 : __ASSERT2(__FILE__, __LINE__, __func__, #e, fmt, ##__VA_ARGS__))
#define ASSERTV2(e, fmt, valist) ((e) ? (void)0 : __ASSERTV2(__FILE__, __LINE__, __func__, #e, fmt, valist))

#ifdef OHOS
__BEGIN_EXTERN_C
#else
__BEGIN_DECLS
#endif
void ENABLE_ASSERT();
void DISABLE_ASSERT();
int IS_ASSERT_ENABLE();
Expand All @@ -49,6 +53,9 @@ __attribute__((__nonnull__(1, 3, 4, 5))) __attribute__((__format__(printf, 5, 0)
const char*,
const char*,
va_list);
#ifdef OHOS
__END_EXTERN_C
#else
__END_DECLS

#endif
#endif /* COMM_COMM_ASSERT_H_ */
2 changes: 2 additions & 0 deletions mars/comm/unique_resource_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ std::wstring string2wstring(const std::string& input) {
#else

#include <fcntl.h>
#ifndef OHOS
#include <sys/stat.h>
#endif
#include <sys/types.h>

#define READFLAG (O_RDONLY)
Expand Down
2 changes: 1 addition & 1 deletion mars/comm/unix/thread/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ class Thread {
ASSERT2(false, "In Android, use SIGUSR2(handler call pthread_exit) to pthread_cancel");
return kill(SIGUSR2);
#else
return pthread_cancel(tid());
//return pthread_cancel(tid());
#endif
}

Expand Down
8 changes: 4 additions & 4 deletions mars/comm/verinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#ifndef Mars_verinfo_h
#define Mars_verinfo_h

#define MARS_REVISION "${mars_rev}"
#define MARS_PATH "${mars_branch}"
#define MARS_REVISION "a7e9d522"
#define MARS_PATH "harmony-xlog"
#define MARS_URL ""
#define MARS_BUILD_TIME "20231114"
#define MARS_TAG "1.0.0-SNAPSHOT"
#define MARS_BUILD_TIME "2024-02-18 14:13:41"
#define MARS_TAG ""

#endif
51 changes: 51 additions & 0 deletions mars/ohoslibraries/export.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
global:
xlogger_Write;
xlogger_dump;
xlogger_memory_dump;
xlogger_IsEnabledFor;
xlogger_Assert;
xlogger_AssertP;
xlogger_pid;
xlogger_tid;
xlogger_maintid;
xlogger_SetLevel;
xlogger_SetAppender;
xlogger_VPrint;
xlogger_Level;

__xlogger_Level_impl;
__xlogger_SetLevel_impl;
__xlogger_IsEnabledFor_impl;
__xlogger_SetAppender_impl;
__xlogger_AssertP_impl;
__xlogger_Assert_impl;
__xlogger_VPrint_impl;
__xlogger_Print_impl;
__xlogger_Write_impl;


*appender_*;
*LogLogic*;
*LogBuffer*;


*mars*xlog*NewXloggerInstance*;
*mars*xlog*GetXloggerInstance*;
*mars*xlog*ReleaseXloggerInstance*;
*mars*xlog*XloggerWrite*;
*mars*xlog*IsEnabledFor*;
*mars*xlog*GetLevel*;
*mars*xlog*SetLevel*;
*mars*xlog*SetAppenderMode*;
*mars*xlog*Flush*;
*mars*xlog*FlushAll*;
*mars*xlog*SetConsoleLogOpen*;
*mars*xlog*SetMaxFileSize*;
*mars*xlog*SetMaxAliveTime*;

local:
_Z22appender_set_console_logb;
_Z24appender_set_console_logb;
*;
};
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
9 changes: 9 additions & 0 deletions mars/ohoslibraries/mars_xlog_sdk/import.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* created on : 2012-07-19
* author : yanguoyue
*/

void ImportLibs() {
extern void ExportXlog();
ExportXlog();
}
Binary file not shown.
Binary file added mars/openssl/openssl_lib_ohos/arm64-v8a/libssl.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 10 additions & 2 deletions mars/xlog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ set(SELF_LIBS_OUT ${CMAKE_SYSTEM_NAME}.out)

include(../comm/CMakeUtils.txt)
include(../comm/CMakeExtraFlags.txt)

if(OHOS)
add_definitions(-DOHOS)
endif()
include_directories(.)
include_directories(src)
include_directories(..)
Expand Down Expand Up @@ -59,7 +61,13 @@ elseif(ANDROID)

get_filename_component(EXPORT_EXP_FILE jni/export.exp ABSOLUTE)
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--version-script=${EXPORT_EXP_FILE}")

elseif(OHOS)
include_directories(../comm/ohos)
file(GLOB SELF_OHOS_SRC_FILES RELATIVE ${PROJECT_SOURCE_DIR}
../comm/xlogger/xloggerbase.c
../comm/xlogger/xlogger.cc
ohos/*.cc)
list(APPEND SELF_SRC_FILES ${SELF_OHOS_SRC_FILES})
endif()

# add_library(${PROJECT_NAME} STATIC ${SELF_SRC_FILES})
Expand Down
Loading