set the fallback value of "FRICAS" as the parent directory of FRICASsys

8 views
Skip to first unread message

Qian Yun

unread,
Mar 16, 2021, 8:55:14 AM3/16/21
to fricas-devel
The patch is here, discussions are welcome. If my idea is accepted,
I can refine the patch a bit more.

It uses "argv[0]" to determine the path of "FRICASsys" binary,
not very reliable, but portable.

So the logic is to use env var "FRICAS" first if it exists,
then use "newroot" if it is passed as function argument,
then use "$spadroot" which is build time value, use if it still exists,
then use the parent directory of "FRICASsys", if it contains
"algebra/compress.daase".

- Qian

diff --git a/src/interp/util.lisp b/src/interp/util.lisp
index e0466835..a2133e31 100644
--- a/src/interp/util.lisp
+++ b/src/interp/util.lisp
@@ -108,8 +108,16 @@ where the [[${FRICAS}]] variable points to
installed tree.
;;; and default to the {\bf \$spadroot} variable (which was the value
;;; of the {\bf FRICAS} shell variable at build time) if we can't.
(defun initroot (&optional (newroot nil))
- (reroot (or (|getEnv| "FRICAS") newroot $spadroot
- (error "setenv FRICAS or (setq $spadroot)"))))
+ (reroot (or (|getEnv| "FRICAS") newroot
+ (cond
+ ((|fricas_probe_file| $spadroot) $spadroot)
+ ((|fricas_probe_file|
+ (concatenate 'string (directory-namestring (car
(|getCLArgs|)))
+ "/../algebra/compress.daase"))
+ (concatenate 'string (directory-namestring (car
(|getCLArgs|)))
+ "/../"))
+ (t (error "setenv FRICAS or (setq $spadroot)")))
+ )))

;;; Gnu Common Lisp (GCL) (at least 2.6.[78]) requires some changes
;;; to the default memory setup to run FriCAS efficiently.

Qian Yun

unread,
Mar 17, 2021, 10:12:56 AM3/17/21
to fricas-devel
Similar problems occurs on macOS as well.

Passing environment variables can be tricky, for example in current
contrib/macos/FriCAS.c, when we use "open -a Terminal.app", the
"FRICAS_PREFIX" environment variable is not passed.

In the end, we have to rely on the parent directory of FRICASsys.

setenv("FRICAS_PREFIX", CFStringGetCStringPtr(path, encoding), 1);

- system("/usr/X11/bin/xterm"
- " -e \"${FRICAS_PREFIX}/bin/fricas\"");
+ system("open -a Terminal.app "
+ "\"${FRICAS_PREFIX}/usr/local/bin/fricas\"");

Waldek Hebisch

unread,
Mar 17, 2021, 10:15:39 AM3/17/21
to fricas...@googlegroups.com
On Tue, Mar 16, 2021 at 08:55:02PM +0800, Qian Yun wrote:
> The patch is here, discussions are welcome. If my idea is accepted,
> I can refine the patch a bit more.
>
> It uses "argv[0]" to determine the path of "FRICASsys" binary,
> not very reliable, but portable.
>
> So the logic is to use env var "FRICAS" first if it exists,
> then use "newroot" if it is passed as function argument,
> then use "$spadroot" which is build time value, use if it still exists,
> then use the parent directory of "FRICASsys", if it contains
> "algebra/compress.daase".

In general that is very reasonable. I would probably look
at "algebra/interp.daase" as it is more fundamental. I am
not sure if we always have "argv[0]" (more precisely, if
setting argv[0] to null is merely perverse or illegal).
> --
> You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/23d5ab5e-c663-9b6c-91b4-d834c10736ac%40gmail.com.

--
Waldek Hebisch

Qian Yun

unread,
Mar 17, 2021, 10:46:03 AM3/17/21
to fricas...@googlegroups.com


On 3/17/21 10:15 PM, Waldek Hebisch wrote:
> On Tue, Mar 16, 2021 at 08:55:02PM +0800, Qian Yun wrote:
>> The patch is here, discussions are welcome. If my idea is accepted,
>> I can refine the patch a bit more.
>>
>> It uses "argv[0]" to determine the path of "FRICASsys" binary,
>> not very reliable, but portable.
>>
>> So the logic is to use env var "FRICAS" first if it exists,
>> then use "newroot" if it is passed as function argument,
>> then use "$spadroot" which is build time value, use if it still exists,
>> then use the parent directory of "FRICASsys", if it contains
>> "algebra/compress.daase".
>
> In general that is very reasonable. I would probably look
> at "algebra/interp.daase" as it is more fundamental. I am
> not sure if we always have "argv[0]" (more precisely, if
> setting argv[0] to null is merely perverse or illegal).

OK, I'll try to generate a proper patch utilizing this idea.
argv[0] can be modified, that is unfortunate, but it is most
portable, because it is from C, unlike "$0" from shell.
Anyway, I'll check existence of "algebra/interp.daase" before use,
for both "$FRICAS", "$spadroot", and "argv[0]".

- Qian

Waldek Hebisch

unread,
Mar 17, 2021, 9:51:12 PM3/17/21
to fricas...@googlegroups.com
IMO, if FRICAS variable is set we should respect it, that is
do not try any fallback.

--
Waldek Hebisch

Qian Yun

unread,
Mar 18, 2021, 12:05:11 AM3/18/21
to fricas...@googlegroups.com


On 3/18/21 9:51 AM, Waldek Hebisch wrote:
>
> IMO, if FRICAS variable is set we should respect it, that is
> do not try any fallback.
>

I was thinking about this lately as well. I'll respect "$FRICAS"
at FRICASsys level.

The problem is that $FRICAS is always set by "bin/fricas", I think
in this script we can improve the logic a bit more, to help the
installation on macOS, which essentially, can be run from
arbitrary position. Current logic is to set an absolute path.
I wonder if this should be changed at "bin/fricas" or "install"
target of Makefile. (e.g. using path like "`dirname $0`").

- Qian

Qian Yun

unread,
Mar 18, 2021, 8:47:24 AM3/18/21
to fricas...@googlegroups.com
OK, not that different from previous version, but a bit cleaner.
May I commit?

- Qian

--- a/src/interp/util.lisp
+++ b/src/interp/util.lisp
@@ -107,8 +107,17 @@
;;; Sets up the system to use the {\bf FRICAS} shell variable if we can
;;; and default to the {\bf \$spadroot} variable (which was the value
;;; of the {\bf FRICAS} shell variable at build time) if we can't.
+;;; Use the parent directory of FRICASsys binary as fallback.
(defun initroot (&optional (newroot nil))
- (reroot (or (|getEnv| "FRICAS") newroot $spadroot
+ (reroot (or (|getEnv| "FRICAS") newroot
+ (if (|fricas_probe_file| $spadroot) $spadroot)
+ (let ((bin-parent-dir
+ (concatenate 'string
+ (directory-namestring (car
(|getCLArgs|)))
+ "/../")))
+ (if (|fricas_probe_file| (concatenate 'string
bin-parent-dir
+
"algebra/interp.daase"))
+ bin-parent-dir))
(error "setenv FRICAS or (setq $spadroot)"))))

;;; Gnu Common Lisp (GCL) (at least 2.6.[78]) requires some changes

On 3/18/21 9:51 AM, Waldek Hebisch wrote:

Waldek Hebisch

unread,
Mar 18, 2021, 2:38:45 PM3/18/21
to fricas...@googlegroups.com
On Thu, Mar 18, 2021 at 08:47:08PM +0800, Qian Yun wrote:
> OK, not that different from previous version, but a bit cleaner.
> May I commit?

Yes, pleas go on.

--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages