1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-02-01 20:06:00 +00:00

Update emacsbug and version.el for the Android port

* java/Makefile.in (install_temp/assets/version): New generated
file.
* lisp/loadup.el: Set emacs versions appropriately prior to
dumping on Android.
* lisp/mail/emacsbug.el (emacs-build-description): Insert
Android build fingerprint.
* lisp/version.el (emacs-repository-version-android)
(emacs-repository-get-version, emacs-repository-get-branch):
Implement for Android.
* src/androidterm.c (android_set_build_fingerprint): New
function.
(syms_of_androidterm): New variable `android-build-fingerprint'.
This commit is contained in:
Po Lu 2023-02-17 21:09:00 +08:00
parent 1f81186d67
commit d70bb47aeb
5 changed files with 145 additions and 4 deletions

View File

@ -192,12 +192,18 @@ ifneq ($(NDK_BUILD_SHARED),)
install_temp/lib/$(ANDROID_ABI)
endif
install_temp/assets/directory-tree: $(libsrc)/asset-directory-tool install_temp
install_temp/assets/directory-tree: $(libsrc)/asset-directory-tool \
install_temp install_temp/assets/version
$(AM_V_GEN) $(libsrc)/asset-directory-tool install_temp/assets \
install_temp/assets/directory-tree
install_temp/assets/version: install_temp
$(AM_V_GEN) { (git rev-parse HEAD || echo "Unknown") \
&& (git rev-parse --abbrev-ref HEAD \
|| echo "Unknown") } 2> /dev/null > $@
emacs.apk-in: install_temp install_temp/assets/directory-tree \
AndroidManifest.xml
install_temp/assets/version AndroidManifest.xml
# Package everything. Specifying the assets on this command line is
# necessary for AAssetManager_getNextFileName to work on old versions
# of Android. Make sure not to generate R.java, as it's already been

View File

@ -439,6 +439,13 @@ lost after dumping")))
(defconst emacs-build-number
(if versions (1+ (apply #'max versions)) 1))))
;; Just set the repository branch during initial dumping on Android.
(if (and (eq system-type 'android)
(not (pdumper-stats)))
(setq emacs-repository-version
(ignore-errors (emacs-repository-get-version))
emacs-repository-branch
(ignore-errors (emacs-repository-get-branch))))
(message "Finding pointers to doc strings...")
(if (and (or (and (fboundp 'dump-emacs)

View File

@ -408,6 +408,12 @@ copy text to your preferred mail program.\n"
"', version "
(mapconcat #'number-to-string (x-server-version) ".") "\n")
(error t)))
(when (and (boundp 'android-build-fingerprint)
(symbol-value 'android-build-fingerprint))
;; This is used on Android.
(insert "Android version and manufacturer: "
(symbol-value 'android-build-fingerprint)
"\n"))
(let ((os (ignore-errors (report-emacs-bug--os-description))))
(if (stringp os)
(insert "System Description: " os "\n\n")))

View File

@ -130,9 +130,22 @@ or if we could not determine the revision.")
(looking-at "[[:xdigit:]]\\{40\\}"))
(match-string 0)))))
(defun emacs-repository-version-android ()
"Return the Emacs repository revision Emacs was built from.
Value is nil if Emacs was not built from a repository checkout.
Use information from the `/assets/version' special file."
(with-temp-buffer
(insert-file-contents "/assets/version")
(let ((string (buffer-substring 1 (line-end-position))))
(and (not (equal string "Unknown")) string))))
(defun emacs-repository-get-version (&optional dir _external)
"Try to return as a string the repository revision of the Emacs sources.
The format of the returned string is dependent on the VCS in use.
If Emacs is built for Android, use the version information
embedded in the Emacs installation package.
Value is nil if the sources do not seem to be under version
control, or if we could not determine the revision. Note that
this reports on the current state of the sources, which may not
@ -140,13 +153,27 @@ correspond to the running Emacs.
Optional argument DIR is a directory to use instead of `source-directory'.
Optional argument EXTERNAL is ignored."
(emacs-repository-version-git (or dir source-directory)))
(cond ((eq system-type 'android)
(emacs-repository-version-android))
(t (emacs-repository-version-git
(or dir source-directory)))))
(defvar emacs-repository-branch nil
"String giving the repository branch from which this Emacs was built.
Value is nil if Emacs was not built from a repository checkout,
or if we could not determine the branch.")
(defun emacs-repository-branch-android ()
"Return the Emacs repository branch Emacs was built from.
Value is nil if Emacs was not built from a repository checkout.
Use information from the `/assets/version' special file."
(with-temp-buffer
(insert-file-contents "/assets/version")
(end-of-line)
(forward-char)
(let ((string (buffer-substring (point) (line-end-position))))
(and (not (equal string "Unknown")) string))))
(defun emacs-repository-branch-git (dir)
"Ask git itself for the branch information for directory DIR."
(message "Waiting for git...")
@ -162,12 +189,19 @@ or if we could not determine the branch.")
(defun emacs-repository-get-branch (&optional dir)
"Try to return as a string the repository branch of the Emacs sources.
The format of the returned string is dependent on the VCS in use.
If Emacs is built for Android, use the version information
embedded in the Emacs installation package.
Value is nil if the sources do not seem to be under version
control, or if we could not determine the branch. Note that
this reports on the current state of the sources, which may not
correspond to the running Emacs.
Optional argument DIR is a directory to use instead of `source-directory'."
(emacs-repository-branch-git (or dir source-directory)))
(cond ((eq system-type 'android)
(emacs-repository-branch-android))
(t (emacs-repository-branch-git
(or dir source-directory)))))
;;; version.el ends here

View File

@ -33,6 +33,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#include "window.h"
#include "textconv.h"
#include "coding.h"
#include "pdumper.h"
/* This is a chain of structures for all the X displays currently in
use. */
@ -5413,6 +5414,84 @@ android_term_init (void)
/* Set Vandroid_build_fingerprint to a reasonable value. */
static void
android_set_build_fingerprint (void)
{
#ifdef ANDROID_STUBIFY
Vandroid_build_fingerprint = Qnil;
#else
jclass class;
jfieldID field;
jobject string;
const char *data;
/* Set class to NULL so freeing an uninitialized local ref can be
avoided. */
class = NULL;
/* Likewise for string. */
string = NULL;
if (!android_init_gui)
goto fail;
else
{
/* Obtain Build.FINGERPRINT. Clear exceptions after each query;
JNI can't find Build.FINGERPRIN on some systems. */
class = (*android_java_env)->FindClass (android_java_env,
"android/os/Build");
(*android_java_env)->ExceptionClear (android_java_env);
if (!class)
goto fail;
field = (*android_java_env)->GetStaticFieldID (android_java_env,
class,
"FINGERPRINT",
"Ljava/lang/String;");
(*android_java_env)->ExceptionClear (android_java_env);
if (!field)
goto fail;
string
= (*android_java_env)->GetStaticObjectField (android_java_env,
class, field);
(*android_java_env)->ExceptionClear (android_java_env);
if (!string)
goto fail;
data = (*android_java_env)->GetStringUTFChars (android_java_env,
string, NULL);
(*android_java_env)->ExceptionClear (android_java_env);
if (!data)
goto fail;
Vandroid_build_fingerprint = build_string_from_utf8 (data);
(*android_java_env)->ReleaseStringUTFChars (android_java_env,
string, data);
}
if (string)
ANDROID_DELETE_LOCAL_REF (string);
ANDROID_DELETE_LOCAL_REF (class);
return;
fail:
if (class)
ANDROID_DELETE_LOCAL_REF (class);
Vandroid_build_fingerprint = Qnil;
#endif
}
void
syms_of_androidterm (void)
{
@ -5441,6 +5520,15 @@ If set to a non-float value, there will be no wait at all. */);
x_underline_at_descent_line,
doc: /* SKIP: real doc in xterm.c. */);
x_underline_at_descent_line = false;
DEFVAR_LISP ("android-build-fingerprint", Vandroid_build_fingerprint,
doc: /* String identifying the device's OS version.
This is a string that uniquely identifies the version of Android
Emacs is running on. */);
/* Avoid dumping Vandroid_build_fingerprint. */
pdumper_do_now_and_after_load (android_set_build_fingerprint);
DEFSYM (Qx_underline_at_descent_line, "x-underline-at-descent-line");
}