From 918b9043dca527bd096e1cd18a7438528b13057f Mon Sep 17 00:00:00 2001 From: Dale Henrichs Date: Sat, 12 Oct 2019 06:50:56 -0700 Subject: [PATCH] Issue #260: start sketching out the new directory structures --- alt_bin/defHOME_PATH.env | 12 + alt_bin/gsdevkit_launcher | 251 ++++++++++++++++++ alt_bin/gsdevkit_topaz_launcher | 195 ++++++++++++++ alt_bin/hello.st | 15 ++ shared/gemstone/README.md | 1 + shared/repos/.gitignore | 1 + .../repos/GsDevKit_launcher/scripts/README.md | 0 shared/repos/GsDevKit_launcher/src/README.md | 0 8 files changed, 475 insertions(+) create mode 100644 alt_bin/defHOME_PATH.env create mode 100755 alt_bin/gsdevkit_launcher create mode 100755 alt_bin/gsdevkit_topaz_launcher create mode 100755 alt_bin/hello.st create mode 100644 shared/gemstone/README.md create mode 100644 shared/repos/GsDevKit_launcher/scripts/README.md create mode 100644 shared/repos/GsDevKit_launcher/src/README.md diff --git a/alt_bin/defHOME_PATH.env b/alt_bin/defHOME_PATH.env new file mode 100644 index 00000000..e353f05b --- /dev/null +++ b/alt_bin/defHOME_PATH.env @@ -0,0 +1,12 @@ +#========================================================================= +# Copyright (c) 2019 GemTalk Systems, LLC . +# +# MIT license: https://github.com/GsDevKit/GsDevKit_home/blob/master/license.txt +# +#========================================================================= + +cd "$( dirname "${BASH_SOURCE[0]}" )" +cd .. +export GS_HOME=`pwd` +export PATH="$GS_HOME/alt_bin:$GS_HOME/bin":$PATH + diff --git a/alt_bin/gsdevkit_launcher b/alt_bin/gsdevkit_launcher new file mode 100755 index 00000000..05ec842d --- /dev/null +++ b/alt_bin/gsdevkit_launcher @@ -0,0 +1,251 @@ +#!/usr/bin/env bash +# +# + +usage() { + cat < is required to be the first +argument following the . + +The $(basename $0) options may be interspersed with the topz vm args as of +GemStone 3.5.0. + +If the scriptdefault.envto use '--' to terminate it's argument parsing, then a +'--' must precede the script arguments on the command line. + +OPTIONS + -D + Bring up topaz debugger for StashCommandError exceptions. Normally these exceptions result in + an error message to stderr. + -H + Display help message and exit. + -V + Verbose output + +EXAMPLES + $(basename $0) -H # this message + $(basename $0) ./hello.st solo_350 -h -- # topaz help message + $(basename $0) ./hello.st solo_350 -- -h # hello.st help message using solo_350 image + $(basename $0) ./hello.st -- -h # hello.st help message using default image + $(basename $0) ./hello.st -h # hello.st help message using default image + $(basename $0) ./hello.st -x # run hello.st with an invalid option --> error message on stderr + $(basename $0) ./hello.st solo_350 -D -- -x # run hello.st with an invalid option --> bring up topaz debugger + +HELP +} + +. $HOME/.config/st_launcher/st_launcher_default.env + +stashFile=`realpath $1` +scriptName="$(basename -- $1)" +shift +scriptArgs="" +launcherVmArgs="" +imageName="$ST_LAUNCHER_DEFAULT_IMAGE_NAME" + +interpArgs="$*" + +for argument in $@ ; do + if [ "$argument" = "--" ] ; then + launcherVmArgs=$scriptArgs + args=($launcherVmArgs) + case ${args[0]} in + -*) # allow imageName to be optional first argument + ;; + *) imageName=${args[0]} ;; + esac + + scriptArgs="" + else + scriptArgs+=" $argument" + fi +done + +debugCommandError="false" +for argument in $launcherVmArgs ; do + case "$argument" in + -D) debugCommandError="true" ;; + -H) usage; exit 0 ;; + -V) set -x ;; + *);; + esac +done + +if [ "${ST_LAUNCHER_HOME}x" = "x" ] ; then + export ST_LAUNCHER_HOME="$ST_LAUNCHER_DEFAULT_IMAGE_PATH/../.." +fi + +# +# this is the smalltalk code executed by the vm aasociated with the \$imageName image +# it is fed to the vm launched by the \$scriptCmdLine +# +vmScriptFile=`mktemp -p /tmp tmp.XXXXXXXXXX.stash` +pwd=`pwd` +cat - > $vmScriptFile << EOF + + [ + StLauncherScript + loadAndExecuteScriptClassFile: '$stashFile' + stashArgs: '$scriptArgs' + imageName: '$imageName' + scriptName: '$scriptName' + workingDir: '$pwd'. + true ] + on: StashCommandError, Error, Warning + do: [:ex | + (ex isKindOf: Warning) + ifTrue: [ + $debugCommandError + ifTrue: [ ex pass ] + ifFalse: [ ex resume ] ]. + $debugCommandError + ifTrue: [ ex pass ] + ifFalse: [ + StashScript + ansiRedOn: StLauncherCommon stderr + during: [ StLauncherCommon stderr nextPutAll: ex description ]. + StLauncherCommon stderr lf. + false ] ]. +EOF + +# +# code used to launch the vm associated with the default image, that generates the \$scriptCmdLine +# + +if [ "$ST_LAUNCHER_DEFAULT_PLATFORM" = "gemstone" ] ; then + inputFile=`mktemp` + cat - > $inputFile << EOF +# st_launcher debugging only +iferr 1 stack +iferr 2 exit 1 +display oops + + set solologin on + login + + expectvalue true + run + | launcherArgMap | + launcherArgMap := Dictionary new + at: '-H' put: #none; "help" + at: '-D' put: #none; "debug StashCommandErrors" + at: '-V' put: #none; "list script execution" + yourself. + ^ StLauncherPlatform + generateSmalltalkScriptLaunchCommandLineFor: '$imageName' + launchScriptPath: '$vmScriptFile' + launcherArgs: '$interpArgs' + launcherArgMap: launcherArgMap + debugCommandError: $debugCommandError. +% +EXITIFNOERROR +EOF + export GEMSTONE="$ST_LAUNCHER_DEFAULT_PRODUCT_PATH" + if [ "$debugCommandError" = "false" ] ; then + scriptFile=`mktemp` + $GEMSTONE/bin/topaz -lq -I "$ST_LAUNCHER_DEFAULT_IMAGE_PATH/.topazini" -C "GEM_SOLO_EXTENT=$ST_LAUNCHER_DEFAULT_SNAPSHOT_PATH" -S $inputFile > $scriptFile + status=$? + if [ "$status" != "0" ]; then + exit $status + fi + chmod +x $scriptFile + $scriptFile + status=$? + if [ "$status" != "0" ]; then + exit $status + fi + else + # expecting to interactively debug topaz + stdoutF=`mktemp` + $GEMSTONE/bin/topaz -lq -I "$ST_LAUNCHER_DEFAULT_IMAGE_PATH/.topazini" -C "GEM_SOLO_EXTENT=$ST_LAUNCHER_DEFAULT_SNAPSHOT_PATH" -S $inputFile | tee $stdoutF >&2 + status="${PIPESTATUS[0]}" + if [ "$status" != "0" ]; then + echo "-- debug session in topaz exited with a non-zero exit status" + exit $status + fi +# >&2 echo "-- debug session ended, continuing execution" + scriptCmdLine=`cat $stdoutF` + fi +elif [ "$ST_LAUNCHER_DEFAULT_PLATFORM" = "pharo" ] ; then + echo "PHARO not supported ... yet" + exit 1 +else + echo "Unsupported platform: \$ST_LAUNCHER_DEFAULT_PLATFORM" + exit 1 +fi + +# >&2 echo "$scriptCmdLine" +$scriptCmdLine + +# https://github.com/mkropat/sh-realpath/blob/master/realpath.sh +realpath() { + canonicalize_path "$(resolve_symlinks "$1")" +} + +resolve_symlinks() { + _resolve_symlinks "$1" +} + +_resolve_symlinks() { + _assert_no_path_cycles "$@" || return + + local dir_context path + path=$(readlink -- "$1") + if [ $? -eq 0 ]; then + dir_context=$(dirname -- "$1") + _resolve_symlinks "$(_prepend_dir_context_if_necessary "$dir_context" "$path")" "$@" + else + printf '%s\n' "$1" + fi +} + +_prepend_dir_context_if_necessary() { + if [ "$1" = . ]; then + printf '%s\n' "$2" + else + _prepend_path_if_relative "$1" "$2" + fi +} + +_prepend_path_if_relative() { + case "$2" in + /* ) printf '%s\n' "$2" ;; + * ) printf '%s\n' "$1/$2" ;; + esac +} + +_assert_no_path_cycles() { + local target path + + target=$1 + shift + + for path in "$@"; do + if [ "$path" = "$target" ]; then + return 1 + fi + done +} + +canonicalize_path() { + if [ -d "$1" ]; then + _canonicalize_dir_path "$1" + else + _canonicalize_file_path "$1" + fi +} + +_canonicalize_dir_path() { + (cd "$1" 2>/dev/null && pwd -P) +} + +_canonicalize_file_path() { + local dir file + dir=$(dirname -- "$1") + file=$(basename -- "$1") + (cd "$dir" 2>/dev/null && printf '%s/%s\n' "$(pwd -P)" "$file") +} + diff --git a/alt_bin/gsdevkit_topaz_launcher b/alt_bin/gsdevkit_topaz_launcher new file mode 100755 index 00000000..1c26957a --- /dev/null +++ b/alt_bin/gsdevkit_topaz_launcher @@ -0,0 +1,195 @@ +#!/usr/bin/env bash +# +# command line interpretter for topaz script +# +# using 3.5.0 and beyond topaz commands +# + +usage() { + cat < [ ] -- [ ] [ -- [ ] [ -- [ ] ] ] +HELP +} + +# https://github.com/mkropat/sh-realpath/blob/master/realpath.sh +realpath() { + canonicalize_path "$(resolve_symlinks "$1")" +} + +resolve_symlinks() { + _resolve_symlinks "$1" +} + +_resolve_symlinks() { + _assert_no_path_cycles "$@" || return + + local dir_context path + path=$(readlink -- "$1") + if [ $? -eq 0 ]; then + dir_context=$(dirname -- "$1") + _resolve_symlinks "$(_prepend_dir_context_if_necessary "$dir_context" "$path")" "$@" + else + printf '%s\n' "$1" + fi +} + +_prepend_dir_context_if_necessary() { + if [ "$1" = . ]; then + printf '%s\n' "$2" + else + _prepend_path_if_relative "$1" "$2" + fi +} + +_prepend_path_if_relative() { + case "$2" in + /* ) printf '%s\n' "$2" ;; + * ) printf '%s\n' "$1/$2" ;; + esac +} + +_assert_no_path_cycles() { + local target path + + target=$1 + shift + + for path in "$@"; do + if [ "$path" = "$target" ]; then + return 1 + fi + done +} + +canonicalize_path() { + if [ -d "$1" ]; then + _canonicalize_dir_path "$1" + else + _canonicalize_file_path "$1" + fi +} + +_canonicalize_dir_path() { + (cd "$1" 2>/dev/null && pwd -P) +} + +_canonicalize_file_path() { + local dir file + dir=$(dirname -- "$1") + file=$(basename -- "$1") + (cd "$dir" 2>/dev/null && printf '%s/%s\n' "$(pwd -P)" "$file") +} + +. $HOME/.config/st_launcher/st_launcher_default.env + +topazScript=`realpath $1` +shift +imageName="$1" +shift + +if [ "$imageName" = "--" ] ; then + phase="topaz-args" + imageName="$ST_LAUNCHER_DEFAULT_IMAGE_NAME" +elif [ "$imageName" = "" ] ; then + phase="topaz-args" + imageName="$ST_LAUNCHER_DEFAULT_IMAGE_NAME" +else + phase="image-name" +fi +theArgs="" +scriptArgs="" +topazArgs="" + +for argument in $@ ; do + if [ "$argument" = "--" ] ; then + case "$phase" in + image-name) + phase="topaz-args" + ;; + topaz-args) + phase="script-args" + topazArgs=$theArgs + theArgs="" + ;; + script-args) + scriptArgs+=$theArgs + theArgs="" + ;; + *) + echo "unknown phase" + usage + exit 1 + ;; + esac + else + theArgs+=" $argument" + fi +done + +case "$phase" in + image-name) + topazArgs=$theArgs + ;; + topaz-args) + if [ "${theArgs}x" = "x" ] ; then + echo "missing required topaz arguments" + usage + exit 1 + fi + topazArgs=$theArgs + ;; + script-args) + scriptArgs+=$theArgs + ;; + *) + echo "unknown phase" + usage + exit 1 + ;; +esac + +topazArgs+=" -S $topazScript" + +if [ "${ST_LAUNCHER_HOME}x" = "x" ] ; then + export ST_LAUNCHER_HOME="$ST_LAUNCHER_DEFAULT_IMAGE_PATH/../.." +fi + +export GEMSTONE="$ST_LAUNCHER_DEFAULT_PRODUCT_PATH" +topaziniPath="$ST_LAUNCHER_DEFAULT_IMAGE_PATH/.topazini" +soloExtentArg="-C \"GEM_SOLO_EXTENT=$ST_LAUNCHER_DEFAULT_SNAPSHOT_PATH\"" +if [ "$imageName" = "$ST_LAUNCHER_DEFAULT_IMAGE_NAME" ] ; then + # use default image parameters ... not necessary to generate a command line + +$GEMSTONE/bin/topaz -lq -I "$topaziniPath" $soloExtentArg -S $topazScript -- $scriptArgs +else + # non-default image name, need to generate the command line, since it is based on params associated with the image + + export GEMSTONE="$ST_LAUNCHER_DEFAULT_PRODUCT_PATH" + generateCommandLineFile=`mktemp` + debugCommandError="true" + + cat - > $generateCommandLineFile << EOF + set solologin on + login + + expectvalue true + run + StLauncherPlatform + generateVmScriptLaunchCommandLineFor: '$imageName' + vmScriptPath: '$topazScript' + launcherArgs: '$interpArgs' + launcherArgMap: Dictionary new + debugCommandError: $debugCommandError. +% +EXITIFNOERROR +EOF + # end up with a two line file ... $GEMSTONE on one line command on second line + scriptFile=`mktemp` + $GEMSTONE/bin/topaz -lq -I "$topaziniPath" $soloExtentArg -S $generateCommandLineFile > $scriptFile + chmod +x $scriptFile + $scriptFile +# $scriptCommandLine -- $scriptArgs +fi + + + diff --git a/alt_bin/hello.st b/alt_bin/hello.st new file mode 100755 index 00000000..81e01376 --- /dev/null +++ b/alt_bin/hello.st @@ -0,0 +1,15 @@ +#!/usr/bin/env gsdevkit_launcher +" +Hello world GsDevKit script +" +Class { + #name : 'GsDevKitLauncher_Hello', + #superclass : 'AbstractProgram', + #category : 'gsdevKit_launcher-Scripts' +} + +{ #category : 'main' } +GsDevKitLauncher_Hello >> main [ + + ^'hello world' +] diff --git a/shared/gemstone/README.md b/shared/gemstone/README.md new file mode 100644 index 00000000..3df19750 --- /dev/null +++ b/shared/gemstone/README.md @@ -0,0 +1 @@ +This is where the topaz solo extent will be located diff --git a/shared/repos/.gitignore b/shared/repos/.gitignore index 83f97f06..576e1b36 100644 --- a/shared/repos/.gitignore +++ b/shared/repos/.gitignore @@ -2,3 +2,4 @@ !/todeClient !/pharo3.0 !.gitignore +!/GsDevKit_launcher diff --git a/shared/repos/GsDevKit_launcher/scripts/README.md b/shared/repos/GsDevKit_launcher/scripts/README.md new file mode 100644 index 00000000..e69de29b diff --git a/shared/repos/GsDevKit_launcher/src/README.md b/shared/repos/GsDevKit_launcher/src/README.md new file mode 100644 index 00000000..e69de29b