Skip to content

Commit

Permalink
Make the build work cross-platform
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Nov 17, 2023
1 parent 75fd972 commit 366b62c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 49 deletions.
2 changes: 1 addition & 1 deletion res/spectral/build.id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
65
104
47 changes: 15 additions & 32 deletions res/spectral/launcher → res/spectral/prefix
Original file line number Diff line number Diff line change
Expand Up @@ -36,44 +36,14 @@ backOut() {
fi
}

ensure() {
command -v "$1" > /dev/null || printf "The command %s is required, but was not found. Please install %s and try again.\n" "$1" "$2" 1>&2
command -v "$1" > /dev/null || exit 1
}

installJava() {
local dir
mkdir -p "$dataHomeDir/java"
ensure unzip Unzip

case "$(uname -s)" in
Linux|GNU*) os="linux" ;;
Win*|Cygwin|Msys) os="windows" ;;
Mac*|Darwin*) os="mac" ;;
SunOS) os="solaris" ;;
*) exit 1 ;;
esac

case "$(uname -m)" in
x86_64|amd64|i686-64) arch="x64" ;;
x86|i686|i386|i86pc) arch="x86" ;;
aarch64_be|aarch64|armv8b|armv8l|arm64) arch="aarch64" ;;
*) exit 1 ;;
esac

unzip -p "$script" "spectral/jre-$javaVersion-$os-$arch.tar.gz" 2>/dev/null | tar xzf - -C "$dataHomeDir/java"
dir=$(unzip -p "$script" "spectral/jre-$javaVersion-$os-$arch.tar.gz" 2>/dev/null | tar tzf - | head -n1)
mv "$dataHomeDir/java/$dir" "$javaHome"
}

abort() {
touch "$failFile"
printf '' > "$waitFile"
rm -f "$waitFile" "$initFile"
}

launch() {
test -x "$javaHome/bin/java" || installJava
test -x "$javaHome/bin/java" || extract
mkfifo "$waitFile" 2> /dev/null && (exec nohup "$javaHome/bin/java" -Dspectral.name="$name" -Dspectral.script="$script" -Dspectral.command="$(command -v "$name")" -Dspectral.fpath="$(zsh -c 'printf "%s\n" $fpath' 2> /dev/null || echo '')" -jar "$script" > /dev/null 2>&1 || abort) &
launchPid=$!
flock "$initFile" sh -c "test -f \"$portFile\" || cat \"$waitFile\"" > /dev/null 2>&1 || abort
Expand All @@ -89,6 +59,16 @@ handle() {
printf "s\n%s\n%s\n" "$pid" "$1" >/dev/tcp/localhost/$port
}

extract() {
local -i offset
local dir
mkdir -p "$dataHomeDir/java"
offset=$(grep -aobm1 'TERMINUS$' "$script" | cut -d: -f1)
tail -c +$((offset+10)) $script | tar xz -C "$dataHomeDir/java" 2> /dev/null
dir="$(tail -c +$((offset+10)) $script | tar tzf - 2> /dev/null | head -n1)"
mv "$dataHomeDir/java/$dir" "$javaHome"
}

terminate() {
exec 6<> /dev/tcp/localhost/$port
printf "x\n%s\n" "$pid" >&6
Expand Down Expand Up @@ -138,6 +118,7 @@ printf "\n##\n" >&7
env -0 >&7
printf "\n##\n" >&7
cat >&7 <&0 &
stdoutPid=$!
cat <&7 &
pipePid=$!

Expand All @@ -152,6 +133,8 @@ do
done

test -t 0 && stty "$ttystate"

kill $stdoutPid
terminate
exit 1

: TERMINUS
32 changes: 16 additions & 16 deletions src/example/example.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ import workingDirectories.daemonClient
def example(): Unit =
import errorHandlers.throwUnsafely
import parameterInterpretation.posix

daemon[Int]:

daemon[Int]:
val Lang = Flag[Language](t"language", false, List('L'), t"the two-letter code of the language")
val Size = Flag[Text](t"size", false, List('S'), t"big, medium or small")
val Age = Flag[Int](t"age", false, List('a'), t"the number of years")
Expand All @@ -49,21 +48,22 @@ def example(): Unit =
Verbose()
Lang()


execute:
//TabCompletions.install().foreach(Out.println(_))
supervise:
terminal:
Out.println(t"Running 2")
Out.println(Age().debug)
Out.println(Size().debug)
Thread.sleep(Age().or(0))
tty.events.foreach: event =>
Out.println(event.debug)

Out.println(Color().debug)
Out.println(Lang().debug)
ExitStatus.Ok
Out.println(t"Hello world!")
ExitStatus.Ok

// supervise:
// terminal:
// Out.println(t"Running 2")
// Out.println(Age().debug)
// Out.println(Size().debug)
// Thread.sleep(Age().or(0))
// tty.events.foreach: event =>
// Out.println(event.debug)

// Out.println(Color().debug)
// Out.println(Lang().debug)
// ExitStatus.Ok

object Language:
given Suggestions[Language] = () => Language.values.map: language =>
Expand Down

0 comments on commit 366b62c

Please sign in to comment.