From: Eli Zaretskii Date: Thu, 15 Feb 2018 16:12:14 +0000 (+0200) Subject: Restore the ability to have several numbered builds X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=9484bb3ab8e39add474400e5982802b61c56eb3a;p=emacs.git Restore the ability to have several numbered builds This allows to have several emacs-XX.YY executables and the corresponding .pdmp files in the same directory, and also makes the PATH_EXEC last resort work on MS-Windows. --- diff --git a/lisp/loadup.el b/lisp/loadup.el index 13c1c501bfd..e166755e036 100644 --- a/lisp/loadup.el +++ b/lisp/loadup.el @@ -380,8 +380,11 @@ lost after dumping"))) ;; Determine which build number to use ;; based on the executables that now exist. -(if (and (equal (last command-line-args) '("dump")) - (fboundp 'dump-emacs) +(if (and (or + (and (equal (last command-line-args) '("dump")) + (fboundp 'dump-emacs)) + (and (equal (last command-line-args) '("pdump")) + (fboundp 'dump-emacs-portable))) (not (eq system-type 'ms-dos))) (let* ((base (concat "emacs-" emacs-version ".")) (exelen (if (eq system-type 'windows-nt) -4)) @@ -392,15 +395,17 @@ lost after dumping"))) (substring name (length base) exelen)))) files))) (setq emacs-repository-version (condition-case nil (emacs-repository-get-version) - (error nil))) + (error nil))) ;; A constant, so we shouldn't change it with `setq'. (defconst emacs-build-number (if versions (1+ (apply 'max versions)) 1)))) (message "Finding pointers to doc strings...") -(if (and (fboundp 'dump-emacs) - (equal (last command-line-args) '("dump"))) +(if (and (or (and (fboundp 'dump-emacs) + (equal (last command-line-args) '("dump"))) + (and (fboundp 'dump-emacs-portable) + (equal (last command-line-args) '("pdump"))))) (Snarf-documentation "DOC") (condition-case nil (Snarf-documentation "DOC") @@ -484,25 +489,32 @@ lost after dumping"))) (if (member dump-mode '("pdump" "pbootstrap")) (dump-emacs-portable (expand-file-name output invocation-directory)) (dump-emacs output "temacs") - (message "%d pure bytes used" pure-bytes-used) - ;; Recompute NAME now, so that it isn't set when we dump. - (if (not (or (eq system-type 'ms-dos) - ;; Don't bother adding another name if we're just - ;; building bootstrap-emacs. - (equal dump-mode "bootstrap"))) - (let ((name (concat "emacs-" emacs-version)) - (exe (if (eq system-type 'windows-nt) ".exe" ""))) - (while (string-match "[^-+_.a-zA-Z0-9]+" name) - (setq name (concat (downcase (substring name 0 (match-beginning 0))) - "-" - (substring name (match-end 0))))) - (setq name (concat name exe)) - (message "Adding name %s" name) - ;; When this runs on Windows, invocation-directory is not - ;; necessarily the current directory. - (add-name-to-file (expand-file-name (concat "emacs" exe) + (message "%d pure bytes used" pure-bytes-used)) + ;; Recompute NAME now, so that it isn't set when we dump. + (if (not (or (eq system-type 'ms-dos) + ;; Don't bother adding another name if we're just + ;; building bootstrap-emacs. + (member dump-mode '("pbootstrap" "bootstrap")))) + (let ((name (format "emacs-%s.%d" emacs-version emacs-build-number)) + (exe (if (eq system-type 'windows-nt) ".exe" ""))) + (while (string-match "[^-+_.a-zA-Z0-9]+" name) + (setq name (concat (downcase (substring name 0 (match-beginning 0))) + "-" + (substring name (match-end 0))))) + (message "Adding name %s" (concat name exe)) + ;; When this runs on Windows, invocation-directory is not + ;; necessarily the current directory. + (add-name-to-file (expand-file-name (concat "emacs" exe) + invocation-directory) + (expand-file-name (concat name exe) + invocation-directory) + t) + (when (equal dump-mode "pdump") + (message "Adding name %s" (concat name ".pdmp")) + (add-name-to-file (expand-file-name "emacs.pdmp" + invocation-directory) + (expand-file-name (concat name ".pdmp") invocation-directory) - (expand-file-name name invocation-directory) t)))) (kill-emacs))) diff --git a/src/Makefile.in b/src/Makefile.in index 5fad672bf8a..32f9cdf1f8f 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -543,8 +543,8 @@ emacs$(EXEEXT): temacs$(EXEEXT) \ lisp.mk $(etc)/DOC $(lisp) \ $(lispsource)/international/charprop.el ${charsets} ifeq ($(DUMPING),pdumper) - LC_ALL=C $(RUN_TEMACS) -batch $(BUILD_DETAILS) -l loadup pdump cp -f temacs$(EXEEXT) $@ + LC_ALL=C $(RUN_TEMACS) -batch $(BUILD_DETAILS) -l loadup pdump else ifeq ($(DUMPING),unexec) LC_ALL=C $(RUN_TEMACS) -batch $(BUILD_DETAILS) -l loadup dump ifneq ($(PAXCTL_dumped),) diff --git a/src/emacs.c b/src/emacs.c index c4c5e3fd74a..1e8416d06e3 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -790,17 +790,23 @@ load_dump (int *inout_argc, char ***inout_argv, const char *argv0_base) /* Finally, look for "emacs.pdmp" in PATH_EXEC. We hardcode "emacs" in "emacs.pdmp" so that the Emacs binary still works - if the user copies and renames it. */ + if the user copies and renames it. + + FIXME: this doesn't work with emacs-XX.YY.ZZ.pdmp versioned files. */ argv0_base = "emacs"; - /* FIXME: On MS-Windows, PATH_EXEC starts with a literal + const char *path_exec = PATH_EXEC; +#ifdef WINDOWSNT + /* On MS-Windows, PATH_EXEC normally starts with a literal "%emacs_dir%", so it will never work without some tweaking. */ - dump_file = alloca (strlen (PATH_EXEC) + path_exec = w32_relocate (path_exec); +#endif + dump_file = alloca (strlen (path_exec) + 1 + strlen (argv0_base) + strlen (suffix) + 1); sprintf (dump_file, "%s%c%s%s", - PATH_EXEC, DIRECTORY_SEP, argv0_base, suffix); + path_exec, DIRECTORY_SEP, argv0_base, suffix); result = pdumper_load (dump_file); if (result != PDUMPER_LOAD_SUCCESS) dump_file = NULL; @@ -908,7 +914,8 @@ main (int argc, char **argv) double tdif = 1000.0 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1.0e3; - fprintf (stderr, "load_dump completed in %g milliseconds\n", tdif); + fprintf (stderr, "load_dump %s %g milliseconds\n", + loaded_dump ? "completed in" : "failed after", tdif); #endif } diff --git a/src/w32.c b/src/w32.c index 5ac66181403..4a4e7f9ea44 100644 --- a/src/w32.c +++ b/src/w32.c @@ -9646,6 +9646,40 @@ maybe_load_unicows_dll (void) } } +/* Relocate a directory specified by epaths.h, using the location of + our binary as an anchor. Note: this runs early during startup, so + we cannot rely on the usual file-related facilities, and in + particular the argument is assumed to be a unibyte string in system + codepage encoding. */ +const char * +w32_relocate (const char *epath_dir) +{ + if (strncmp (epath_dir, "%emacs_dir%/", 12) == 0) + { + static char relocated_dir[MAX_PATH]; + + /* Replace "%emacs_dir%" with the parent of the directory where + our binary lives. Note that init_environment was not yet + called, so we cannot rely on emacs_dir being set in the + environment. */ + if (GetModuleFileNameA (NULL, relocated_dir, MAX_PATH)) + { + char *p = _mbsrchr (relocated_dir, '\\'); + + if (p) + { + *p = '\0'; + if ((p = _mbsrchr (relocated_dir, '\\')) != NULL) + { + strcpy (p, epath_dir + 11); + epath_dir = relocated_dir; + } + } + } + } + return epath_dir; +} + /* globals_of_w32 is used to initialize those global variables that must always be initialized on startup even when the global variable diff --git a/src/w32.h b/src/w32.h index 1e416ceead7..54bf2bb5aaa 100644 --- a/src/w32.h +++ b/src/w32.h @@ -185,6 +185,8 @@ extern MultiByteToWideChar_Proc pMultiByteToWideChar; extern WideCharToMultiByte_Proc pWideCharToMultiByte; extern DWORD multiByteToWideCharFlags; +extern const char *w32_relocate (const char *); + extern void init_environment (char **); extern void check_windows_init_file (void); extern void syms_of_ntproc (void);