Skip to content

Commit

Permalink
Fixed #651.
Browse files Browse the repository at this point in the history
  • Loading branch information
lhstrh committed Oct 22, 2021
1 parent 7a3fba9 commit c9fdb97
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 14 deletions.
11 changes: 3 additions & 8 deletions lib/scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@

# Set up the environment.

# -e: Immediately exit if any command has a non-zero exit status.
# disabled: -e: Immediately exit if any command has a non-zero exit status.
# -u: Error on referencing unset variables.
# -o pipefail: Prevents errors in a pipeline from being masked.
set -euo pipefail
set -uo pipefail

# Obtain path to the directory containing this script, even in presence of links.
bindir=`dirname "$(readlink -f "$0")"`
# Get to the base directory by going from "./lib/scripts" to ".".
base=`dirname $(dirname ${bindir})`

# Paths (relative to the base directory).
# Paths (relative to the base directory), which is assumed to have been set.
lfc_src_pkg_name="org.lflang.lfc"
lfc_jar_build_path="${lfc_src_pkg_name}/build/libs/${lfc_src_pkg_name}-*-SNAPSHOT-all.jar"
lfc_jar_release_path="lib/jars/${lfc_src_pkg_name}-*-SNAPSHOT-all.jar"
Expand Down
56 changes: 50 additions & 6 deletions lib/scripts/launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,60 @@
# Usage: Usage: lfc [options] files...
#============================================================================

# Initialize the environment.
source "$(dirname "$(readlink -f "$0")")/init.sh"
#============================================================================
# Preamble
#============================================================================
# Find the directory in which this script resides in a way that is compatible
# with MacOS, which has a `readlink` implementation that does not support the
# necessary `-f` flag to canonicalize by following every symlink in every
# component of the given name recursively.
# This solution, adapted from an example written by Geoff Nixon, ia POSIX-
# compliant and robust to symbolic links. If a chain of more than 1000 links
# is encountered, we return.
find_dir() (
start_dir=$PWD
cd "$(dirname "$1")"
link=$(readlink "$(basename "$1")")
count=0
while [ "${link}" ]; do
if [[ "${count}" -lt 1000 ]]; then
cd "$(dirname "${link}")"
link=$(readlink "$(basename "$1")")
((count++))
else
return
fi
done
real_path="$PWD/$(basename "$1")"
cd "${start_dir}"
echo `dirname "${real_path}"`
)

# Report fatal error and exit.
function fatal_error() {
1>&2 echo -e "\e[1mlfc: \e[31mfatal error: \e[0m$1"
exit 1
}

rel_path="/lib/scripts"
abs_path="$(find_dir "$0")"

if [[ "${abs_path}" ]]; then
base=`dirname $(dirname ${abs_path})`
# Initialize Lingua Franca shell environment.
source "${base}/${rel_path}/init.sh"
else
fatal_error "Unable to determine absolute path to $0."
fi
#============================================================================

# Find the jar; report error if it was not found.
# 1. Find the jar; report error if it was not found.
if ! find_jar_path; then
fatal_error "Cannot find lfc jar."
fatal_error "Cannot find the Lingua Franca jar."
fi

# Make sure the correct JRE is available.
# 2. Make sure the correct JRE is available.
check_jre_version

# Launch the compiler.
# 3. Launch the compiler.
run_jar_with_args "$@"

0 comments on commit c9fdb97

Please sign in to comment.