Skip to content

Commit

Permalink
moved git state from version.dd to version.m2
Browse files Browse the repository at this point in the history
  • Loading branch information
mahrud committed Aug 12, 2024
1 parent cad066e commit 14c4182
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 58 deletions.
5 changes: 0 additions & 5 deletions M2/Macaulay2/d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ foreach(_d_source IN LISTS DLIST)
list(APPEND CLIST ${_c_source})
endforeach()

# To avoid unnecessary recompiling, only version.dd is given GIT_DESCRIPTION
set_property(SOURCE version-tmp.cc APPEND PROPERTY COMPILE_DEFINITIONS
GIT_DESCRIPTION="${GIT_DESCRIPTION}"
GIT_BRANCH="${GIT_BRANCH}")

###############################################################################
## Compile the interpreter

Expand Down
6 changes: 3 additions & 3 deletions M2/Macaulay2/d/version.dd
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ setupconst("version", Expr(toHashTable(Sequence(
"packages" => Ccode(constcharstar,"DISTRIBUTED_PACKAGES"),
"build" => Ccode(constcharstar,"buildsystemtype"),
"host" => Ccode(constcharstar,"hostsystemtype"),
"git description" => Ccode(constcharstar,"GIT_DESCRIPTION"),
"git branch" => Ccode(constcharstar, "GIT_BRANCH")
))));
"git description" => Ccode(constcharstar, "PACKAGE_VERSION \"-bin\""),
"git branch" => "version.m2 not found"
)))).Protected = false; -- "git description" and "git branch" will be added in m2/version.m2

-- Local Variables:
-- compile-command: "echo \"make: Entering directory \\`$M2BUILDDIR/Macaulay2/d'\" && echo \"make: Entering directory \\`$M2BUILDDIR/Macaulay2/d'\" && make -C $M2BUILDDIR/Macaulay2/d version.o "
Expand Down
1 change: 1 addition & 0 deletions M2/Macaulay2/m2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ add_custom_command(OUTPUT ${CORE_DIR}/tvalues.m2
DEPENDS M2-binary
VERBATIM)

## Populate GIT_DESCRIPTION and GIT_BRANCH
configure_file(version.m2.in ${M2_DIST_PREFIX}/${M2_INSTALL_DATADIR}/Core/version.m2 @ONLY)

foreach(filename IN LISTS M2LIST ITEMS
Expand Down
9 changes: 2 additions & 7 deletions M2/Macaulay2/m2/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,13 @@ Makefile: Makefile.in ; cd ../.. && ./config.status Macaulay2/m2/Makefile
##############################
.SUFFIXES: .m2
.PHONY: html initialize tags install-tmp
# there is a parallel list of tutorials in overview3.m2
DUMPEDM2FILES := Core.m2 startup.m2
DUMPEDM2SRCFILES := Core.m2 startup.m2.in
DUMPEDM2FILES := Core.m2 startup.m2 version.m2 $(shell cat @srcdir@/loadsequence)
DUMPEDM2SRCFILES := Core.m2 startup.m2.in version.m2.in
DUMPEDM2DOCFILES := \
@srcdir@/../packages/Macaulay2Doc/*.m2 \
@srcdir@/../packages/Macaulay2Doc/functions/*.m2 \
@srcdir@/../packages/Macaulay2Doc/operators/*.m2 \
../packages/Macaulay2Doc.m2
############################## loadsequence
LOADSEQUENCE := $(shell cat @srcdir@/loadsequence)
DUMPEDM2FILES += $(LOADSEQUENCE)
DUMPEDM2SRCFILES += $(patsubst version.m2, version.m2.in, $(LOADSEQUENCE))
############################## tvalues.m2
STOP = --stop
ARGS = -q --silent $(STOP) -e errorDepth=0
Expand Down
79 changes: 39 additions & 40 deletions M2/Macaulay2/m2/startup.m2.in
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ toString := value' getGlobalSymbol if firstTime then "simpleToString" else "toSt
local exe
local topBuilddir

m2version := (
v := replace("^release-", "", version#"git description");
if v == version#"VERSION" then v -- stable release (at release tag)
else if version#"git branch" == "" then v
else concatenate(v, 1, "(", version#"git branch", ")"))

-- this next bit has to be *parsed* after the "debug" above, to prevent the symbols from being added to the User dictionary
if firstTime then (
-- all global definitions here are set to read-only
Expand Down Expand Up @@ -279,8 +273,33 @@ if firstTime then (
initlayout();
)

pathsearch := (exe) -> (
if not isFixedExecPath exe then (
-- we search the path, but we don't do it the same way execvp does, too bad.
PATH := separate(":", getenv "PATH" | ":.:/bin:/usr/bin");
PATH = apply(PATH, dir -> if dir === "" then "." else dir);
exe = scan(PATH, dir -> if fileExists(dir | "/" | exe) then break(dir | "/" | exe)));
exe)

dir := s -> ( m := regex(".*/",s); if m === null or 0 === #m then "./" else substring(m#0#0,m#0#1-1,s))
base := s -> ( m := regex(".*/",s); if m === null or 0 === #m then s else substring(m#0#1, s))
exe = minimizeFilename (
-*
-- this can be a reliable way to get the executable in linux
-- but we don't want to use it because we don't want to chase symbolic links and it does that for us
processExe := "/proc/self/exe";
if fileExists processExe and readlink processExe =!= null then readlink processExe
else
*-
if isAbsolutePath commandLine#0 then commandLine#0 else
if isStablePath commandLine#0 then concatenate(currentDirectory() | commandLine#0)
else pathsearch commandLine#0)

if not isAbsolutePath exe then exe = currentDirectory() | exe;
exe = concatenate(realpath dir exe, base exe)
if notify then printerr("executable = ", exe)

-- called by M2version()
initcurrentlayout := () -> (
issuffix := (s,t) -> t =!= null and s === substring(t,-#s);
bindir = dir exe | "/";
Expand Down Expand Up @@ -315,8 +334,10 @@ initcurrentlayout := () -> (
if notify then printerr("topBuilddir = ", topBuilddir);
topSrcdir = if topBuilddir =!= null and fileExists(topBuilddir|"srcdir") then (
sdir := first lines get(topBuilddir|"srcdir");
minimizeFilename concatPath(topBuilddir,sdir));
realpath concatPath(topBuilddir, sdir));
if notify then printerr("topSrcdir = ", topSrcdir);
coredir = prefixDirectory | replace("PKG", "Core", currentLayout#"package");
if notify then printerr("coredir = ", coredir);
)

prefixDirectory = null -- prefix directory, after installation, e.g., "/usr/local/"
Expand All @@ -329,21 +350,13 @@ nocore = false
noinitfile = false
interpreter := commandInterpreter

-*
getRealPath := fn -> ( -- use this later if realpath doesn't work
local s;
while ( s = readlink fn; s =!= null ) do fn = if isAbsolutePath s then s else minimizeFilename(fn|"/../"|s);
fn)
*-

pathsearch := e -> (
if not isFixedExecPath e then (
-- we search the path, but we don't do it the same way execvp does, too bad.
PATH := separate(":",if "" =!= getenv "PATH" then getenv "PATH" else ".:/bin:/usr/bin");
PATH = apply(PATH, x -> if x === "" then "." else x);
scan(PATH, p -> if fileExists (p|"/"|e) then (e = p|"/"|e; break));
);
e)
M2version := () -> (
initcurrentlayout();
trySimpleLoad("version.m2", coredir | "version.m2");
v := replace("^release-", "", version#"git description");
if version#"VERSION" == v -- stable release (at release tag)
or version#"git branch" == "" then v
else concatenate(v, 1, "(", version#"git branch", ")"))

progname := notdir commandLine#0
usage := arg -> (
Expand Down Expand Up @@ -461,7 +474,7 @@ action := hashTable {
<< TeXmacsEnd << endl << flush)));
)
),
"--version" => arg -> ( << m2version << newline; exit 0; ),
"--version" => arg -> ( << M2version() << newline; exit 0; ),
"--webapp" => arg -> ( printWidth=0; topLevelMode = global WebApp; )
};

Expand Down Expand Up @@ -538,31 +551,17 @@ processCommandLineOptions := phase0 -> ( -- 3 passes

if firstTime then processCommandLineOptions 1

exe = minimizeFilename (
-*
-- this can be a reliable way to get the executable in linux
-- but we don't want to use it because we don't want to chase symbolic links and it does that for us
processExe := "/proc/self/exe";
if fileExists processExe and readlink processExe =!= null then readlink processExe
else
*-
if isAbsolutePath commandLine#0 then commandLine#0 else
if isStablePath commandLine#0 then concatenate(currentDirectory()|commandLine#0)
else pathsearch commandLine#0)
if not isAbsolutePath exe then exe = currentDirectory() | exe ;
exe = concatenate(realpath dir exe, base exe)
if notify then printerr("executable = ", exe)
-- also calls initcurrentlayout()
srcversion = M2version()

if firstTime and not nobanner then (
if topLevelMode === TeXmacs then stderr << TeXmacsBegin << "verbatim:";
stderr << "Macaulay2, version " << m2version << newline << flush;
stderr << "Macaulay2, version " << srcversion << newline << flush;
if topLevelMode === TeXmacs then stderr << TeXmacsEnd << flush)

scan(commandLine, arg -> if arg === "-q" then noinitfile = true)
homeDirectory = getenv "HOME" | "/"

initcurrentlayout()

path = {}
pkgpath = {}
corepath = {}
Expand Down
16 changes: 13 additions & 3 deletions M2/Macaulay2/m2/version.m2.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
srcversion := "@PACKAGE_VERSION@"
-- this file is populated by the build system

gitversion = new HashTable from {
"git description" => "@GIT_DESCRIPTION@",
"git branch" => "@GIT_BRANCH@",
}
version = merge(version, gitversion, last)
protect symbol version

srcversion := version#"git description"
binversion := version#"VERSION"
if srcversion =!= binversion
then stderr << "--warning: mismatch: source code version: " << srcversion << " != executable version " << binversion << endl

if not match(binversion, srcversion)
then printerr("warning: source code version: ", srcversion, " != executable version ", binversion)

-- Local Variables:
-- compile-command: "cd $M2BUILDDIR && ./config.status Macaulay2/m2/version.m2"
Expand Down

0 comments on commit 14c4182

Please sign in to comment.