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

find boot files relative to executable by default #755

Merged
merged 1 commit into from
Nov 16, 2023
Merged
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
11 changes: 7 additions & 4 deletions BUILDING
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,17 @@ The makefile supports several targets:

Runs the build Chez Scheme without installing.

Alternatively, you can run the executable directly and tell it
where to find boot files, either by setting `SCHEMEHEAPDIRS` as
Alternatively, you can run the executable directly as

<workarea>/bin/<machine type>/scheme

If you have configured with `--installabsolute`, running without
installing requires either `SCHEMEHEAPDIRS` as

env SCHEMEHEAPDIRS=<workarea>/boot/<machine type> \
<workarea>/bin/<machine type>/scheme

or through the `-B` command-line flag, which requires absolute
paths:
or using the `-B` command-line flag:

<workarea>/bin/<machine type>/scheme \
-B <workarea>/boot/<machine type>/petite.boot \
Expand Down
3 changes: 2 additions & 1 deletion boot/pb/scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ EXPORT const char * Skernel_version(void);
EXPORT void Sretain_static_relocation(void);
EXPORT void Sset_verbose(int);
EXPORT void Sscheme_init(void (*)(void));
EXPORT void Sregister_boot_executable_relative_file(const char *, const char *);
EXPORT void Sregister_boot_file(const char *);
EXPORT void Sregister_boot_direct_file(const char *);
EXPORT void Sregister_boot_relative_file(const char *);
EXPORT void Sregister_boot_file_fd(const char *, int fd);
EXPORT void Sregister_boot_file_fd_region(const char *, int fd, iptr offset, iptr len, int close_after);
EXPORT void Sregister_heap_file(const char *);
Expand Down
20 changes: 16 additions & 4 deletions c/build.zuo
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
(define c-config-file
(at-dir "config.h"))
(define c-config-keys
'(disablecurses disablex11 enablelibffi alwaysUseBootFile preloadBootFiles))
'(disablecurses disablex11 enablelibffi alwaysUseBootFile preloadBootFiles relativeBootFiles
InstallBin InstallLib))

;; sources for "kernel.o":
(define kernel-src-files
Expand Down Expand Up @@ -420,9 +421,20 @@
(line (and (equal? (hash-ref config 'enablelibffi #f) "yes")
"#define ENABLE_LIBFFI"))
(line (and (not (for-windows? config))
(let ([s (hash-ref config 'InstallLib #f)])
(and s
(~a "#define DEFAULT_HEAP_PATH \"" s "/csv%v/%m\"")))))
(or (and (equal? (hash-ref config 'relativeBootFiles #f) "yes")
(let* ([bin (hash-ref config 'InstallBin #f)]
[lib (hash-ref config 'InstallLib #f)]
[rel (or (and bin lib (find-relative-path bin lib))
".")]
[x-rel (if (relative-path? rel)
(build-raw-path "%x" rel)
rel)])
(~a "#define DEFAULT_HEAP_PATH \"%x:"
(build-raw-path x-rel "csv%v/%m")
":%x/../../boot/%m\"")))
(let ([s (hash-ref config 'InstallLib #f)])
(and s
(~a "#define DEFAULT_HEAP_PATH \"" s "/csv%v/%m\""))))))
(line (let ([alwaysUseBootFile
(or (and (not (equal? (hash-ref config 'alwaysUseBootFile "") "")))
(infer-always-use-boot-file preload-files))])
Expand Down
4 changes: 2 additions & 2 deletions c/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ int main(int argc, const char *argv[]) {
(void) fprintf(stderr,"%s requires argument\n", arg);
exit(1);
}
Sregister_boot_file(argv[n]);
Sregister_boot_executable_relative_file(execpath, argv[n]);
} else if (strcmp(arg,"-B") == 0 || strcmp(arg,"--Boot") == 0) {
if (++n == argc) {
(void) fprintf(stderr,"%s requires argument\n", arg);
exit(1);
}
Sregister_boot_direct_file(argv[n]);
Sregister_boot_relative_file(argv[n]);
} else if (strcmp(arg,"--eedisable") == 0) {
#ifdef FEATURE_EXPEDITOR
expeditor_enable = 0;
Expand Down
18 changes: 12 additions & 6 deletions c/scheme.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ static char *get_defaultheapdirs() {
#else /* not WIN32: */
#define SEARCHPATHSEP ':'
#define PATHSEP '/'
/* `DEFAULT_HEAP_PATH` is normally defined in the generated "config.h" */
#ifndef DEFAULT_HEAP_PATH
#define DEFAULT_HEAP_PATH "/usr/lib/csv%v/%m:/usr/local/lib/csv%v/%m"
#endif
Expand Down Expand Up @@ -1083,25 +1084,30 @@ static void check_boot_file_state(const char *who) {

extern void Sregister_boot_file(const char *name) {
check_boot_file_state("Sregister_boot_file");
find_boot("", name, "", 0, -1, 1);
find_boot("scheme", name, "", 0, -1, 1);
}

extern void Sregister_boot_direct_file(const char *name) {
check_boot_file_state("Sregister_boot_direct_file");
find_boot("", name, "", 1, -1, 1);
extern void Sregister_boot_executable_relative_file(const char* execpath, const char *name) {
check_boot_file_state("Sregister_executable_relative_boot_file");
find_boot(execpath, name, "", 0, -1, 1);
}

extern void Sregister_boot_relative_file(const char *name) {
check_boot_file_state("Sregister_boot_relative_file");
find_boot(NULL, name, "", 1, -1, 1);
}

extern void Sregister_boot_file_fd(const char *name, int fd) {
check_boot_file_state("Sregister_boot_file_fd");
find_boot("", name, "", 1, fd, 1);
find_boot(NULL, name, "", 1, fd, 1);
}

extern void Sregister_boot_file_fd_region(const char *name,
int fd,
iptr offset,
iptr len,
int close_after) {
check_boot_file_state("Sregister_boot_file_fd");
check_boot_file_state("Sregister_boot_file_fd_region");

if (strlen(name) >= BOOT_PATH_MAX) {
fprintf(stderr, "boot-file path is too long %s\n", name);
Expand Down
10 changes: 10 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ installreleasenotes=""
installschemename="scheme"
installpetitename="petite"
installscriptname="scheme-script"
relativeBootFiles=yes
cflagsset=no
disablex11=no
disablecurses=no
Expand Down Expand Up @@ -263,6 +264,9 @@ while [ $# != 0 ] ; do
--installprefix=*)
installprefix=`echo $1 | sed -e 's/^--installprefix=//'`
;;
--prefix=*)
installprefix=`echo $1 | sed -e 's/^--prefix=//'`
;;
--installlib=*)
installlib=`echo $1 | sed -e 's/^--installlib=//'`
;;
Expand Down Expand Up @@ -296,6 +300,9 @@ while [ $# != 0 ] ; do
--installscriptname=*)
installscriptname=`echo $1 | sed -e 's/^--installscriptname=//'`
;;
--installabsolute)
relativeBootFiles=no
;;
--toolprefix=*)
toolprefix=`echo $1 | sed -e 's/^--toolprefix=//'`
CC="${toolprefix}${CC}"
Expand Down Expand Up @@ -562,6 +569,7 @@ if [ "$help" = "yes" ]; then
echo " --libkernel build libkernel.a (the default)"
echo " --kernelobj build kernel.o instead of libkernel.a"
echo " --installprefix=<pathname> final installation root ($installprefix)"
echo " --prefix=<pathname> alias for --installprefix"
echo " --installbin=<pathname> bin directory ($installbin)"
echo " --installlib=<pathname> lib directory ($installlib)"
echo " --installman=<pathname> manpage directory ($installman)"
Expand All @@ -575,6 +583,7 @@ if [ "$help" = "yes" ]; then
echo " --installschemename=<schemename> install scheme as ($installschemename)"
echo " --installpetitename=<petitename> install petite as ($installpetitename)"
echo " --installscriptname=<scriptname> install scheme-script as ($installscriptname)"
echo " --installabsolute disable relative boot-file search"
echo " --toolprefix=<prefix> prefix tool (compiler, linker, ...) names"
echo " --boot=<machine type>-<tag> build from prepared variant (e.g., pbchunk)"
echo " --emboot=\"<file> ...\" additional boot <file>s with emscripten"
Expand Down Expand Up @@ -1047,6 +1056,7 @@ disablex11=$disablex11
enablelibffi=$libffi
preloadBootFiles=$preloadBootFiles
alwaysUseBootFile=$alwaysUseBootFile
relativeBootFiles=$relativeBootFiles

InstallBin=$installbin
InstallLib=$installlib
Expand Down
32 changes: 23 additions & 9 deletions csug/foreign.stex
Original file line number Diff line number Diff line change
Expand Up @@ -3093,8 +3093,10 @@ program.
\cfunction{void}{Sscheme_init}{void (*\var{abnormal}_\var{exit})(void)}
\cfunction{void}{Sset_verbose}{int \var{v}}
\cfunction{void}{Sregister_boot_file}{const char *\var{name}}
\cfunctTwo{void}{Sregister_boot_executable_relative_file}{const char *\var{execpath},}{const char *\var{name}}
\cfunction{void}{Sregister_boot_relative_file}{const char *\var{name}}
\cfunction{void}{Sregister_boot_file_fd}{const char *\var{name}, int \var{fd}}
\cfunctTwo{void}{Sregister_boot_file_fd_segment}{const char *\var{name}, int \var{fd},}{iptr \var{offset}, iptr \var{len}, int \var{close}_\var{after}}
\cfunctTwo{void}{Sregister_boot_file_fd_region}{const char *\var{name}, int \var{fd},}{iptr \var{offset}, iptr \var{len}, int \var{close}_\var{after}}
\cfunction{void}{Sbuild_heap}{const char *\var{exec}, void (*\var{custom}_\var{init})(void)}
\cfunction{void}{Senable_expeditor}{const char *\var{history}_\var{file}}
\cfunction{void}{Sretain_static_relocation}{void}
Expand Down Expand Up @@ -3125,13 +3127,24 @@ values of \var{v} and off when \var{v} is zero.
In verbose mode, the system displays a trace of the search process
for subsequently registered boot files.

\scheme{Sregister_boot_file} searches for
the named boot file and
register it for loading, while \scheme{Sregister_boot_file_fd}
provides a specific boot file as a file descriptor.
When only a boot file name is provided, the file is opened but not loaded until the heap is built via
\scheme{Sbuild_heap}. When a file descriptor is provided, the given file name
is used only for error reporting.
\scheme{Sregister_boot_file} searches for a boot file and registers it
for loading. If the given boot file path is absolute or starts with
a \scheme{.} or \scheme{..} path element, then the path is
used relative to the current directory; otherwise, the boot file is
found through a search as described in
Section~\ref{SECTUSECOMMANDLINE}, and \scheme{"scheme"} is assumed as
the executable name for resolving a \scheme{"%x"} escape when the
executable path is not otherwise available from the operating system.
\scheme{Sregister_boot_executable_relative_file} is similar, but
accepts a path to the executable instead of assuming
\scheme{"scheme"}, so it should be preferred when using a boot file
path that may be resolved relative to the executable.
\scheme{Sregister_boot_relative_file} always treats a relative path
as relative to the current directory, so the executable path is not needed.
In all of those cases, the boot file is opened but not loaded until the heap is built via
\scheme{Sbuild_heap}. \scheme{Sregister_boot_file_fd} provides a specific boot file as a file descriptor,
the given file name is used only for error reporting, and the file descriptor
is not read until until the heap is built via \scheme{Sbuild_heap}.
For the first boot file registered only, the system also
searches for the boot files upon which the named file
depends, either directly or indirectly.
Expand All @@ -3153,7 +3166,8 @@ called.
files.
\var{exec} is assumed to be the name of or path to the executable
image and is used when no boot files have been registered as
the base name for the boot-file search process.
both the base name for the boot-file search process and the executable
name for finding boot files relative to the executable.
\var{exec} may be null only if one or more boot files have
been registered.
\scheme{\var{custom}_\var{init}} must be a (possibly null) pointer to
Expand Down
2 changes: 1 addition & 1 deletion csug/use.stex
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,7 @@ arguments for which search tracing is desired.

Ordinarily, the search for
boot files is limited to a set of
installation directories, but this may be overridden by setting
installation directories relative to the executable, but this may be overridden by setting
the environment variable \index{\scheme{SCHEMEHEAPDIRS}}\scheme{SCHEMEHEAPDIRS}.
\scheme{SCHEMEHEAPDIRS} should be a colon-separated list of directories, listed in
the order in which they should be searched.
Expand Down
6 changes: 4 additions & 2 deletions release_notes/release_notes.stex
Original file line number Diff line number Diff line change
Expand Up @@ -768,10 +768,12 @@ The \scheme{enable-error-source-expression} parameter determines
whether error messages that become embedded in code can refer to the
original source file's path.

\subsection{Portable boot files (9.9.9)}
\subsection{Executable-relative boot files (9.9.9)}

When searching for boot files, the two-character escape sequence
``\scheme{%x}'' is now supported on more platforms.
``\scheme{%x}'' is now supported on more platforms. By default, Chez
Scheme is configured to use this facility to find boot files relative
to the executable, even when installed.

\subsection{New conversions from Scheme to C signed and unsigned integers (9.6.4)}

Expand Down
3 changes: 2 additions & 1 deletion s/mkheader.ss
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@
(export "void" "Sset_verbose" "(int)")
(export "void" "Sscheme_init" "(void (*)(void))")
(export "void" "Sregister_boot_file" "(const char *)")
(export "void" "Sregister_boot_direct_file" "(const char *)")
(export "void" "Sregister_boot_executable_relative_file" "(const char *, const char *)")
(export "void" "Sregister_boot_relative_file" "(const char *)")
(export "void" "Sregister_boot_file_fd" "(const char *, int fd)")
(export "void" "Sregister_boot_file_fd_region" "(const char *, int fd, iptr offset, iptr len, int close_after)")
(export "void" "Sregister_heap_file" "(const char *)")
Expand Down