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

Update install process to fix class ucode link directives #255

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Top Level Makefile for Unicon
#
# Changes made 8 October 2021 include
# 1). addition of additional directories for Unicon class ucode file to the
# variable Udirs
# 2). addition of the compilation and execution of the program fixalllinks
# after the installation of the Unicon system into the current system
#
# There is an undefined variable DESTDIR which can be passed in from the
# surrounding environment. This is used in the build process for the Debian
# package build system
#

TOPDIR=.

Expand Down Expand Up @@ -234,7 +244,7 @@ Tbins=unicon icont iconx iconc unicont uniconx uniconc udb uprof unidep unidoc \
ui ivib patchstr iyacc rt.a rt.h

Tdirs=$(DESTDIR)$(ULB) $(DESTDIR)$(UIPL) $(DESTDIR)$(UPLUGINS)
Udirs=lib 3d gui unidoc unidep xml parser
Udirs=lib 3d gui ide unidoc unidep xml parser udb udb/dta udb/lib unicon
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we installing these extra directories? Are they being used as libraries similar to the existing dirs ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra directories contain useful ucode files. In addition, they also have updateable link directives. I added them for completeness. If you do not want to include them that is your prerogative.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason those are not included as the other ones is that they don't contain library files intended to be used by end users. ide, unicon, udb, etc, are meant to be used in their binary forms. They are also not on the IPATH/LPATH like the other ones, and that is why they are not included by default.

IPLdirs=lib incl gincl mincl procs
RTdirs=lib include include/uri

Expand Down Expand Up @@ -300,6 +310,9 @@ install Install:
echo "Installing uni/$$d to $(DESTDIR)$(ULB)/$$d ..."; \
$(INST) -m 644 uni/$$d/*.* $(DESTDIR)$(ULB)/$$d; \
done
# update the link directives in the Unicon class ucode files
./bin/unicon fixalllinks
./fixalllinks $(DESTDIR)$(ULB)
# plugins
@$(INST) -m 644 plugins/lib/*.* $(DESTDIR)$(UPLUGINS)/ || true
# docs and man
Expand Down
15 changes: 14 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Top Level Makefile for Unicon
#
# Changes made 8 October 2021 include
# 1). addition of additional directories for Unicon class ucode file to the
# variable Udirs
# 2). addition of the compilation and execution of the program fixalllinks
# after the installation of the Unicon system into the current system
#
# There is an undefined variable DESTDIR which can be passed in from the
# surrounding environment. This is used in the build process for the Debian
# package build system
#

TOPDIR=.

Expand Down Expand Up @@ -234,7 +244,7 @@ Tbins=unicon icont iconx iconc unicont uniconx uniconc udb uprof unidep unidoc \
ui ivib patchstr iyacc rt.a rt.h

Tdirs=$(DESTDIR)$(ULB) $(DESTDIR)$(UIPL) $(DESTDIR)$(UPLUGINS)
Udirs=lib 3d gui unidoc unidep xml parser
Udirs=lib 3d gui ide unidoc unidep xml parser udb udb/dta udb/lib unicon
IPLdirs=lib incl gincl mincl procs
RTdirs=lib include include/uri

Expand Down Expand Up @@ -300,6 +310,9 @@ install Install:
echo "Installing uni/$$d to $(DESTDIR)$(ULB)/$$d ..."; \
$(INST) -m 644 uni/$$d/*.* $(DESTDIR)$(ULB)/$$d; \
done
# update the link directives in the Unicon class ucode files
./bin/unicon fixalllinks
./fixalllinks $(DESTDIR)$(ULB)
# plugins
@$(INST) -m 644 plugins/lib/*.* $(DESTDIR)$(UPLUGINS)/ || true
# docs and man
Expand Down
130 changes: 130 additions & 0 deletions fixalllinks.icn
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
############################################################################
#
# File: fixalllinks.icn
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let us give the a more descriptive name in this context, maybe fixucodelinks.icn ?

Also, let us move the file down to a subdirectory. I suggest to uni/progs since we already have utilities there such as idxGen.icn that we use with docs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any required name changes or location placement changes that you require are a "go" as far as I am concerned. Let me know exactly want you want here and I'll make the appropriate changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @brucerennie

#
# Subject: Program to correct link directives in the ucode files.
#
# Author: Bruce Rennie
#
# Date: August 12, 2020
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# This program corrects the link directives in ucode files for all
# references to class ucode files. On installation of the system into the
# install directories, the ucode files will have the link directives for class
# ucode files pointing to the original compilation directories. When copied
# to the install directories these need to be changed to reflect the actual
# locations. This will normally be run from the Makefile when make Install
# is executed.
#
# fixalllinks install.dir
#
# Within the Makefile, the install.dir is $(ULB)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The install location for "unicon library files" is $(ULB)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a problem, I will update the comments shortly.

#
#
#
############################################################################
#
# Links: io, basename, ximage
#
############################################################################
#
#
link io, basename, ximage

procedure main(args)
local srcdir,
destdir,
destdirfs,
infilename,
outfilename,
infs,
outfs,
fname,
bname,
line,
subdirectories := ["3d", "gui", "ide", "lib", "parser", "udb",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better if these subdirectories re passed in from the command line. Actually, we don't even have to do them all it was, but we could. Since the Makefile already does the follopwing:

	@for d in $(Udirs); do \
	  echo "Installing uni/$$d to $(DESTDIR)$(ULB)/$$d ..."; \
	  $(INST) -m 644 uni/$$d/*.* $(DESTDIR)$(ULB)/$$d; \
	done

we can just add a call to fix links as we go one directory at a time.

The reason for this is that we don't have change the file itself if we add/remove new subdirectory or if installing some of them became conditionals. Also, by generalizing it, a user can use it to patch ucode files for any reason when they are moved around.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check first that we can run it in this position and make sure that the code doesn't break.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better if these subdirectories re passed in from the command line. Actually, we don't even have to do them all it was, but we could. Since the Makefile already does the follopwing:

	@for d in $(Udirs); do \
	  echo "Installing uni/$$d to $(DESTDIR)$(ULB)/$$d ..."; \
	  $(INST) -m 644 uni/$$d/*.* $(DESTDIR)$(ULB)/$$d; \
	done

we can just add a call to fix links as we go one directory at a time.

The reason for this is that we don't have change the file itself if we add/remove new subdirectory or if installing some of them became conditionals. Also, by generalizing it, a user can use it to patch ucode files for any reason when they are moved around.

If we change to command line parameters, Bruce will have to change the present treatment of the log file. Currently, it is opened with "w" (which will erase the previous log file). We will need a way of starting again at the beginning of a fresh install.

"udb/lib", "udb/dta", "unicon", "unidep",
"unidoc", "xml"],
sd,
logfile,
outline

#
# If no parameter is given print message and exit
#
destdir := \args[1] | (write("no changes to be done to ucode files") & exit(0))
#
# we will have a logfile of all changes made to each of the ucode files.
# Useful for review if needed
#
logfile := open("fixucode.log", "w")
#
# if the last charcater of the destination (install) directory is the directory
# specifier, then remove as we will add it as required in the following code
#
if destdir[-1] == ("/" | "\\") then {
destdir[-1] := ""
}
write(logfile, "destination directory:", destdir)
#
# we want to be cautious in running this program and make sure that we are
# actually dealing with a directory that exists. If the parameter is not a
# valid directory, we simply abort.
#
if chdir(destdir) then {
#
# within the unicon class directory, there are (at present) 10
# sub-directories that need to have the relevant ucode files checked
# for fully specified "link" directives. These "link" directives will
# be altered to use the specified destination directory as the prefix.
#
# A new ucode file is written with the updated "link" directives and this
# new file will replace the old ucode file. The old ucode file will be
# kept with a new suffix.
#
every sd := !subdirectories do {
writes(logfile, "sub-directory:")
destdirfs := open(write(logfile, destdir || "/" || sd), "r")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's worth computing prefix := destdir || "/" || sd || "/" and then replacing the multiple instances of destdir || "/" || sd // "/" || ... with prefix || ...

It might not make all that much difference to the run time, but it might make the code slightly easier to read.

No worries if you disagree.

while infilename := read(destdirfs) do {
if infilename[-2:0] == ".u" then {
writes(logfile, " ucode file:")
infs := open(write(logfile, destdir || "/" || sd || "/" || infilename), "r")
outfs := open(outfilename := destdir || "/" || sd || "/" || infilename || ".upd", "w")
while line := read(infs) do {
if match("link", line) then {
write(logfile, " line:", line)
if find("/", line) then {
line ? {
outline := move(5)
fname := tail(tab(0))
bname := basename(fname[1])
outline ||:= destdir || "/" || (\bname | "") || "/" || (\fname[2] | "")
}
line := outline
write(logfile, " line:", line)
}
}
write(outfs, line)
}
close(infs)
close(outfs)
if exists(destdir || "/" || sd || "/" || infilename || ".old") then {
remove(destdir || "/" || sd || "/" || infilename || ".old")
}
rename(destdir || "/" || sd || "/" || infilename, destdir || "/" || sd || "/" || infilename || ".old")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename can fail. Is it worth checking for that?

rename(outfilename, destdir || "/" || sd || "/" || infilename)
}
}
close(destdirfs)
}
} else {
stop("cannot change to directory \"", destdir, "\"")
}
end