Skip to content

ohos: Use custom domain when logging with hilog #583

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

Open
wants to merge 2 commits into
base: main
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
2 changes: 1 addition & 1 deletion mozjs-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "mozjs_sys"
description = "System crate for the Mozilla SpiderMonkey JavaScript engine."
repository.workspace = true
version = "0.128.9-2"
version = "0.128.9-3"
authors = ["Mozilla"]
links = "mozjs"
build = "build.rs"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
diff --git a/build/moz.configure/init.configure b/build/moz.configure/init.configure
--- a/build/moz.configure/init.configure (revision dbffebd0937c14d3c73ce9be4798da15cb2f369d)
+++ b/build/moz.configure/init.configure (revision 8a1dbb7da45148151dbb0d05d969118103cfa8d0)
@@ -950,6 +950,14 @@
@@ -950,6 +950,16 @@
set_define("ANDROID", target_is_android)


+@depends(target)
+def target_is_ohos(target):
+ return target.raw_os.endswith("-ohos")
+ if target.raw_os.endswith("-ohos"):
+ return True
+ return None
+
+
+set_define("XP_OHOS", target_is_ohos)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ diff --git a/build/moz.configure/init.configure b/build/moz.configure/init.confi
index e0e14bf60..179de2592 100644
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -956,6 +956,7 @@ def target_is_ohos(target):
@@ -956,7 +956,9 @@ def target_is_ohos(target):


set_define("XP_OHOS", target_is_ohos)
+set_config("OHOS", target_is_ohos)
+set_define("OHOS_LOG_DOMAIN", "0xE0C4", when=target_is_ohos)


@depends(target)
def target_is_openbsd(target):
diff --git a/config/system-headers.mozbuild b/config/system-headers.mozbuild
index 471599f17..a89f0ca7a 100644
--- a/config/system-headers.mozbuild
Expand All @@ -34,7 +36,7 @@ index 3cfc92533..9c487ac45 100644

#ifdef ANDROID
# include <android/log.h>
+#elif defined(OHOS)
+#elif defined(XP_OHOS)
+# include <hilog/log.h>
#endif
#ifdef MOZ_WIDGET_ANDROID
Expand All @@ -46,8 +48,8 @@ index 3cfc92533..9c487ac45 100644
-#ifndef ANDROID
+#ifdef ANDROID
+ __android_log_print(ANDROID_LOG_ERROR, "Gecko", "mozalloc_abort: %s", msg);
+#elif defined(OHOS)
+ (void) OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "Gecko",
+#elif defined(XP_OHOS)
+ (void) OH_LOG_Print(LOG_APP, LOG_ERROR, OHOS_LOG_DOMAIN, "Gecko",
+ "mozalloc_abort: %{public}s\n", msg);
+#else
fputs(msg, stderr);
Expand All @@ -65,7 +67,7 @@ index 0b7395177..e84d76aba 100644
#endif
#ifdef ANDROID
# include <android/log.h>
+#elif defined(OHOS)
+#elif defined(XP_OHOS)
+# include <hilog/log.h>
#endif

Expand All @@ -74,8 +76,8 @@ index 0b7395177..e84d76aba 100644
MozWalkTheStackWithWriter(MOZ_ReportAssertionFailurePrintFrame, CallerPC(),
/* aMaxFrames */ 0);
# endif
+#elif defined(OHOS)
+ (void) OH_LOG_Print(LOG_APP, LOG_FATAL, 0, "MOZ_Assert",
+#elif defined(XP_OHOS)
+ (void) OH_LOG_Print(LOG_APP, LOG_FATAL, OHOS_LOG_DOMAIN, "MOZ_Assert",
+ "Assertion failure: %{public}s, at %{public}s:%{public}d\n",
+ aStr, aFilename, aLine);
#else
Expand All @@ -85,8 +87,8 @@ index 0b7395177..e84d76aba 100644
__android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH",
"[%d] Hit MOZ_CRASH(%s) at %s:%d\n", MOZ_GET_PID(), aStr,
aFilename, aLine);
+#elif defined(OHOS)
+ (void) OH_LOG_Print(LOG_APP, LOG_FATAL, 0, "MOZ_CRASH",
+#elif defined(XP_OHOS)
+ (void) OH_LOG_Print(LOG_APP, LOG_FATAL, OHOS_LOG_DOMAIN, "MOZ_CRASH",
+ "Hit MOZ_CRASH(%{public}s), at %{public}s:%{public}d\n",
+ aStr, aFilename, aLine);
#else
Expand All @@ -103,7 +105,7 @@ index 3247b993c..c7039d5f8 100644
-#ifdef ANDROID
+#if defined(ANDROID)
# include <android/log.h>
+#elif defined(OHOS)
+#elif defined(XP_OHOS)
+# include <hilog/log.h>
#endif

Expand All @@ -115,8 +117,8 @@ index 3247b993c..c7039d5f8 100644
-#ifdef ANDROID
+#if defined(ANDROID)
__android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", s.str().c_str());
+#elif defined(OHOS)
+ (void) OH_LOG_Print(LOG_APP, LOG_INFO, 0, "Gecko", "%{public}s\n", s.str().c_str());
+#elif defined(XP_OHOS)
+ (void) OH_LOG_Print(LOG_APP, LOG_INFO, OHOS_LOG_DOMAIN, "Gecko", "%{public}s\n", s.str().c_str());
#else
fputs(s.str().c_str(), stderr);
#endif
Expand All @@ -128,22 +130,22 @@ index c3a2ca89e..3fea33f4b 100644

#ifdef ANDROID
# include <android/log.h>
+#elif defined(OHOS)
+#elif defined(XP_OHOS)
+# include <hilog/log.h>
#endif

-#ifndef ANDROID
+#if ! (defined(ANDROID) || defined(OHOS))
+#if ! (defined(ANDROID) || defined(XP_OHOS))
static void vprintf_stderr_buffered(const char* aFmt, va_list aArgs) {
// Avoid interleaving by writing to an on-stack buffer and then writing in one
// go with fputs, as long as the output fits into the buffer.
@@ -66,6 +68,10 @@ MFBT_API void vprintf_stderr(const char* aFmt, va_list aArgs) {
MFBT_API void vprintf_stderr(const char* aFmt, va_list aArgs) {
__android_log_vprint(ANDROID_LOG_INFO, "Gecko", aFmt, aArgs);
}
+#elif defined(OHOS)
+#elif defined(XP_OHOS)
+MFBT_API void vprintf_stderr(const char* aFmt, va_list aArgs) {
+ (void) OH_LOG_Print(LOG_APP, LOG_INFO, 0, "Gecko", aFmt, aArgs);
+ (void) OH_LOG_Print(LOG_APP, LOG_INFO, OHOS_LOG_DOMAIN, "Gecko", aFmt, aArgs);
+}
#elif defined(FUZZING_SNAPSHOT)
MFBT_API void vprintf_stderr(const char* aFmt, va_list aArgs) {
Expand All @@ -153,7 +155,7 @@ index c3a2ca89e..3fea33f4b 100644

MFBT_API void print_stderr(std::stringstream& aStr) {
-#if defined(ANDROID)
+#if defined(ANDROID) || defined(OHOS)
+#if defined(ANDROID) || defined(XP_OHOS)
// On Android logcat output is truncated to 1024 chars per line, and
// we usually use std::stringstream to build up giant multi-line gobs
// of output. So to avoid the truncation we find the newlines and
Expand All @@ -179,7 +181,7 @@ index 52bd6abc5..781402d56 100644
-#ifdef ANDROID
+#if defined(ANDROID)
#include <android/log.h>
+#elif defined(OHOS)
+#elif defined(XP_OHOS)
+# include <hilog/log.h>
#endif

Expand All @@ -188,13 +190,13 @@ index 52bd6abc5..781402d56 100644
PR_Write(fd, buf, nb); \
} \
PR_END_MACRO
+#elif defined(OHOS)
+#elif defined(XP_OHOS)
+#define _PUT_LOG(fd, buf, nb) \
+ PR_BEGIN_MACRO \
+ if (fd == _pr_stderr) { \
+ char savebyte = buf[nb]; \
+ buf[nb] = '\0'; \
+ (void) OH_LOG_Print(LOG_APP, LOG_INFO, 0, "PRLog", \
+ (void) OH_LOG_Print(LOG_APP, LOG_INFO, OHOS_LOG_DOMAIN, "PRLog", \
+ "%{public}s\n", buf); \
+ buf[nb] = savebyte; \
+ } else { \
Expand All @@ -208,21 +210,20 @@ index 52bd6abc5..781402d56 100644
PR_LogPrint("Aborting");
#ifdef ANDROID
__android_log_write(ANDROID_LOG_ERROR, "PRLog", "Aborting");
+#elif defined(OHOS)
+ (void) OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "PRLog", "Aborting\n");
+#elif defined(XP_OHOS)
+ (void) OH_LOG_Print(LOG_APP, LOG_ERROR, OHOS_LOG_DOMAIN, "PRLog", "Aborting\n");
#endif
abort();
}
@@ -567,6 +584,9 @@ PR_IMPLEMENT(void) PR_Assert(const char *s, const char *file, PRIntn ln)
#elif defined(ANDROID)
__android_log_assert(NULL, "PRLog", "Assertion failure: %s, at %s:%d\n",
s, file, ln);
+#elif defined(OHOS)
+ (void) OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "PRLog",
+#elif defined(XP_OHOS)
+ (void) OH_LOG_Print(LOG_APP, LOG_ERROR, OHOS_LOG_DOMAIN, "PRLog",
+ "Assertion failure: %{public}s, at %{public}s:%{public}d\n",s, file, ln);
#endif
abort();
}
--
2.45.2

5 changes: 4 additions & 1 deletion mozjs-sys/mozjs/build/moz.configure/init.configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions mozjs-sys/mozjs/memory/mozalloc/mozalloc_abort.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions mozjs-sys/mozjs/mfbt/Assertions.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions mozjs-sys/mozjs/mfbt/DbgMacro.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions mozjs-sys/mozjs/mozglue/misc/Debug.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions mozjs-sys/mozjs/nsprpub/pr/src/io/prlog.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading