From 84db8f28ea627fb1fdf8b46170299dc4ec3d277e Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 8 Sep 2023 12:30:18 +0200 Subject: [PATCH 1/3] Removed util directory and dev scripts can be executed from anywhere --- bin/lfc-dev | 62 ++++++++++++++++++++++++++++++++- bin/lfc-dev.ps1 | 20 +++++++---- bin/lfd-dev | 62 ++++++++++++++++++++++++++++++++- bin/lfd-dev.ps1 | 20 +++++++---- bin/lff-dev | 62 ++++++++++++++++++++++++++++++++- bin/lff-dev.ps1 | 20 +++++++---- util/README.md | 4 --- util/scripts/launch.ps1 | 34 ------------------ util/scripts/launch.sh | 77 ----------------------------------------- 9 files changed, 222 insertions(+), 139 deletions(-) mode change 120000 => 100755 bin/lfc-dev mode change 120000 => 100755 bin/lfd-dev mode change 120000 => 100755 bin/lff-dev delete mode 100644 util/README.md delete mode 100644 util/scripts/launch.ps1 delete mode 100755 util/scripts/launch.sh diff --git a/bin/lfc-dev b/bin/lfc-dev deleted file mode 120000 index 1a3eb8bc0d..0000000000 --- a/bin/lfc-dev +++ /dev/null @@ -1 +0,0 @@ -../util/scripts/launch.sh \ No newline at end of file diff --git a/bin/lfc-dev b/bin/lfc-dev new file mode 100755 index 0000000000..76a9642549 --- /dev/null +++ b/bin/lfc-dev @@ -0,0 +1,61 @@ +#!/bin/bash + +#============================================================================ +# Description: Build and run the Lingua Franca compiler (lfc). +# Authors: Marten Lohstroh +# Christian Menard +# Usage: Usage: lfc-dev [options] files... +#============================================================================ + +#============================================================================ +# 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, is POSIX- +# compliant and robust to symbolic links. If a chain of more than 1000 links +# is encountered, we return. +set -euo pipefail + +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[31mfatal error: \e[0m$1" + exit 1 +} + +abs_path="$(find_dir "$0")" + +if [[ "${abs_path}" ]]; then + base=`dirname ${abs_path}` +else + fatal_error "Unable to determine absolute path to $0." +fi +#============================================================================ + +gradlew="${base}/gradlew" + +# Launch the tool. +"${gradlew}" --quiet -p "${base}" assemble ":cli:lfc:assemble" +"${base}/build/install/lf-cli/bin/lfc" "$@" diff --git a/bin/lfc-dev.ps1 b/bin/lfc-dev.ps1 index 90e6f9876a..56ecf3ac62 100644 --- a/bin/lfc-dev.ps1 +++ b/bin/lfc-dev.ps1 @@ -1,9 +1,15 @@ -#========================================================== -# Description: Run the lfc compiler. +#============================================================================ +# Description: Build and run the Lingua Franca compiler (lfc). # Authors: Ruomu Xu -# Usage: Usage: lfc [options] files... -#========================================================== +# Christian Menard +# Usage: Usage: lfc-dev [options] files... +#============================================================================ -$launchScript="$PSScriptRoot\..\util\scripts\launch.ps1" -# PS requires spattling: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Splatting?view=powershell-7.2 -. $launchScript @args + +# This script is in $base\bin +$base="$PSScriptRoot\..\" +$gradlew="${base}/gradlew.bat" + +# invoke script +& "${gradlew}" --quiet -p "${base}" assemble ":cli:lfc:assemble" +& "${base}/build/install/lf-cli/bin/lfc" @args diff --git a/bin/lfd-dev b/bin/lfd-dev deleted file mode 120000 index 1a3eb8bc0d..0000000000 --- a/bin/lfd-dev +++ /dev/null @@ -1 +0,0 @@ -../util/scripts/launch.sh \ No newline at end of file diff --git a/bin/lfd-dev b/bin/lfd-dev new file mode 100755 index 0000000000..c154379ac4 --- /dev/null +++ b/bin/lfd-dev @@ -0,0 +1,61 @@ +#!/bin/bash + +#============================================================================ +# Description: Build and run the Lingua Franca diagram generator (lfd). +# Authors: Marten Lohstroh +# Christian Menard +# Usage: Usage: lfd-dev [options] files... +#============================================================================ + +#============================================================================ +# 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, is POSIX- +# compliant and robust to symbolic links. If a chain of more than 1000 links +# is encountered, we return. +set -euo pipefail + +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[31mfatal error: \e[0m$1" + exit 1 +} + +abs_path="$(find_dir "$0")" + +if [[ "${abs_path}" ]]; then + base=`dirname ${abs_path}` +else + fatal_error "Unable to determine absolute path to $0." +fi +#============================================================================ + +gradlew="${base}/gradlew" + +# Launch the tool. +"${gradlew}" --quiet -p "${base}" assemble ":cli:lfd:assemble" +"${base}/build/install/lf-cli/bin/lfd" "$@" diff --git a/bin/lfd-dev.ps1 b/bin/lfd-dev.ps1 index 54ce9397f4..47d53f0731 100644 --- a/bin/lfd-dev.ps1 +++ b/bin/lfd-dev.ps1 @@ -1,9 +1,15 @@ -#========================================================== -# Description: Run the lff compiler. +#============================================================================ +# Description: Build and run the Lingua Franca diagram generator (lfd). # Authors: Ruomu Xu -# Usage: Usage: lff [options] files... -#========================================================== +# Christian Menard +# Usage: Usage: lfd-dev [options] files... +#============================================================================ -$launchScript="$PSScriptRoot\..\util\scripts\launch.ps1" -# PS requires spattling: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Splatting?view=powershell-7.2 -. $launchScript @args + +# This script is in $base\bin +$base="$PSScriptRoot\..\" +$gradlew="${base}/gradlew.bat" + +# invoke script +& "${gradlew}" --quiet -p "${base}" assemble ":cli:lfd:assemble" +& "${base}/build/install/lf-cli/bin/lfd" @args diff --git a/bin/lff-dev b/bin/lff-dev deleted file mode 120000 index 1a3eb8bc0d..0000000000 --- a/bin/lff-dev +++ /dev/null @@ -1 +0,0 @@ -../util/scripts/launch.sh \ No newline at end of file diff --git a/bin/lff-dev b/bin/lff-dev new file mode 100755 index 0000000000..3a656a8a96 --- /dev/null +++ b/bin/lff-dev @@ -0,0 +1,61 @@ +#!/bin/bash + +#============================================================================ +# Description: Build and run the Lingua Franca code formatter (lff). +# Authors: Marten Lohstroh +# Christian Menard +# Usage: Usage: lff-dev [options] files... +#============================================================================ + +#============================================================================ +# 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, is POSIX- +# compliant and robust to symbolic links. If a chain of more than 1000 links +# is encountered, we return. +set -euo pipefail + +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[31mfatal error: \e[0m$1" + exit 1 +} + +abs_path="$(find_dir "$0")" + +if [[ "${abs_path}" ]]; then + base=`dirname ${abs_path}` +else + fatal_error "Unable to determine absolute path to $0." +fi +#============================================================================ + +gradlew="${base}/gradlew" + +# Launch the tool. +"${gradlew}" --quiet -p "${base}" assemble ":cli:lff:assemble" +"${base}/build/install/lf-cli/bin/lff" "$@" diff --git a/bin/lff-dev.ps1 b/bin/lff-dev.ps1 index 54ce9397f4..32b7b2171f 100644 --- a/bin/lff-dev.ps1 +++ b/bin/lff-dev.ps1 @@ -1,9 +1,15 @@ -#========================================================== -# Description: Run the lff compiler. +#============================================================================ +# Description: Build and run the Lingua Franca code formatter (lff). # Authors: Ruomu Xu -# Usage: Usage: lff [options] files... -#========================================================== +# Christian Menard +# Usage: Usage: lff-dev [options] files... +#============================================================================ -$launchScript="$PSScriptRoot\..\util\scripts\launch.ps1" -# PS requires spattling: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Splatting?view=powershell-7.2 -. $launchScript @args + +# This script is in $base\bin +$base="$PSScriptRoot\..\" +$gradlew="${base}/gradlew.bat" + +# invoke script +& "${gradlew}" --quiet -p "${base}" assemble ":cli:lff:assemble" +& "${base}/build/install/lf-cli/bin/lff" @args diff --git a/util/README.md b/util/README.md deleted file mode 100644 index fd95c322f0..0000000000 --- a/util/README.md +++ /dev/null @@ -1,4 +0,0 @@ -## util - -This directory is intended for collecting utility programs associated with Lingua Franca -but that run and install independently of the main tool chain. diff --git a/util/scripts/launch.ps1 b/util/scripts/launch.ps1 deleted file mode 100644 index 9100c75434..0000000000 --- a/util/scripts/launch.ps1 +++ /dev/null @@ -1,34 +0,0 @@ -#========================================================== -# Description: Launch lfc or lff depending on the invoking script. -# Authors: Christian Menard, Peter Donovan, Ruomu Xu -# Usage: Usage: launch args... -# with invoker with name same as the programme to be invoked. -#========================================================== - -# If the invoker is Z:\nkamihara\lf\bin\lfc.ps1, $invokerName will strip out "lfc.ps1" and then get "lfc". -# See https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.2#myinvocation -$invokerPath = $MyInvocation.PSCommandPath -$invokerName = [System.IO.Path]::GetFileNameWithoutExtension("$(Split-Path -Path $invokerPath -Leaf -Resolve)") - -$mainClassTable = @{"lfc" = "org.lflang.cli.Lfc"; "lff" = "org.lflang.cli.Lff"; "lfd" = "org.lflang.cli.Lfd"} -$tool = $null -foreach ($k in $mainClassTable.Keys) { - # This replacement is not ideal, but it is kinda analogous to its counterpart in launch.sh. - if ($invokerName.Contains(($k -replace "-dev", ""))) { - $tool = $k - break - } -} -if ($null -eq $tool) { - throw ("$invokerName is not a known lf command. Known commands are [$($mainClassTable.Keys)]. " + - "In case you use a symbolic or hard link to one of the Lingua Franca " + - "command line tools, make sure that the link's name ends with one of [$($mainClassTable.Keys)]") -} - -# This script is in $base\util\scripts -$base="$PSScriptRoot\..\..\" -$gradlew="${base}/gradlew.bat" - -# invoke script -& "${gradlew}" --quiet assemble ":cli:${tool}:assemble" -& "${base}/build/install/lf-cli/bin/${tool}" @args diff --git a/util/scripts/launch.sh b/util/scripts/launch.sh deleted file mode 100755 index 5e52051c60..0000000000 --- a/util/scripts/launch.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/bash - -#============================================================================ -# Description: Run the Lingua Franca compiler. -# Authors: Marten Lohstroh -# Christian Menard -# Usage: Usage: lfc [options] files... -#============================================================================ - -#============================================================================ -# 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, is POSIX- -# compliant and robust to symbolic links. If a chain of more than 1000 links -# is encountered, we return. -set -euo pipefail - -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 -} - -abs_path="$(find_dir "$0")" - -if [[ "${abs_path}" ]]; then - base=`dirname $(dirname ${abs_path})` -else - fatal_error "Unable to determine absolute path to $0." -fi -#============================================================================ - -if [[ "${0%%-dev}" == *lfc ]]; then - tool="lfc" -elif [[ "${0%%-dev}" == *lff ]]; then - tool="lff" -elif [[ "${0%%-dev}" == *lfd ]]; then - tool="lfd" -else - known_commands="[lfc, lff, lfd]" - echo \ - "ERROR: $0 is not a known lf command! Known commands are ${known_commands}. - In case you use a symbolic or hard link to one of the Lingua Franca - command line tools, make sure that the link's name ends with one of - ${known_commands}." - exit 2 -fi - -gradlew="${base}/gradlew" - -# Launch the tool. -"${gradlew}" --quiet assemble ":cli:${tool}:assemble" -"${base}/build/install/lf-cli/bin/${tool}" "$@" From 1b3f505d480762b19d7a80c73d8eb5099630669f Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 8 Sep 2023 13:30:30 +0200 Subject: [PATCH 2/3] fix bug in readlink logic --- bin/lfc-dev | 16 +++++++--------- bin/lfd-dev | 16 +++++++--------- bin/lff-dev | 16 +++++++--------- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/bin/lfc-dev b/bin/lfc-dev index 76a9642549..2664248947 100755 --- a/bin/lfc-dev +++ b/bin/lfc-dev @@ -20,7 +20,7 @@ # is encountered, we return. set -euo pipefail -find_dir() ( +find_base_dir() ( start_dir=$PWD cd "$(dirname "$1")" link=$(readlink "$(basename "$1")") @@ -28,15 +28,15 @@ find_dir() ( while [ "${link}" ]; do if [[ "${count}" -lt 1000 ]]; then cd "$(dirname "${link}")" - link=$(readlink "$(basename "$1")") + link=$(readlink "$(basename "${link}")") ((count++)) else return fi done - real_path="$PWD/$(basename "$1")" + real_path="${PWD}" cd "${start_dir}" - echo `dirname "${real_path}"` + echo "$(dirname "${real_path}")" ) # Report fatal error and exit. @@ -45,12 +45,10 @@ function fatal_error() { exit 1 } -abs_path="$(find_dir "$0")" +base="$(find_base_dir "$0")" -if [[ "${abs_path}" ]]; then - base=`dirname ${abs_path}` -else - fatal_error "Unable to determine absolute path to $0." +if [[ -z "${base}" ]]; then + fatal_error "Unable to determine base path of $0." fi #============================================================================ diff --git a/bin/lfd-dev b/bin/lfd-dev index c154379ac4..ddb1e0e69c 100755 --- a/bin/lfd-dev +++ b/bin/lfd-dev @@ -20,7 +20,7 @@ # is encountered, we return. set -euo pipefail -find_dir() ( +find_base_dir() ( start_dir=$PWD cd "$(dirname "$1")" link=$(readlink "$(basename "$1")") @@ -28,15 +28,15 @@ find_dir() ( while [ "${link}" ]; do if [[ "${count}" -lt 1000 ]]; then cd "$(dirname "${link}")" - link=$(readlink "$(basename "$1")") + link=$(readlink "$(basename "${link}")") ((count++)) else return fi done - real_path="$PWD/$(basename "$1")" + real_path="${PWD}" cd "${start_dir}" - echo `dirname "${real_path}"` + echo "$(dirname "${real_path}")" ) # Report fatal error and exit. @@ -45,12 +45,10 @@ function fatal_error() { exit 1 } -abs_path="$(find_dir "$0")" +base="$(find_base_dir "$0")" -if [[ "${abs_path}" ]]; then - base=`dirname ${abs_path}` -else - fatal_error "Unable to determine absolute path to $0." +if [[ -z "${base}" ]]; then + fatal_error "Unable to determine base path of $0." fi #============================================================================ diff --git a/bin/lff-dev b/bin/lff-dev index 3a656a8a96..c0dc83c647 100755 --- a/bin/lff-dev +++ b/bin/lff-dev @@ -20,7 +20,7 @@ # is encountered, we return. set -euo pipefail -find_dir() ( +find_base_dir() ( start_dir=$PWD cd "$(dirname "$1")" link=$(readlink "$(basename "$1")") @@ -28,15 +28,15 @@ find_dir() ( while [ "${link}" ]; do if [[ "${count}" -lt 1000 ]]; then cd "$(dirname "${link}")" - link=$(readlink "$(basename "$1")") + link=$(readlink "$(basename "${link}")") ((count++)) else return fi done - real_path="$PWD/$(basename "$1")" + real_path="${PWD}" cd "${start_dir}" - echo `dirname "${real_path}"` + echo "$(dirname "${real_path}")" ) # Report fatal error and exit. @@ -45,12 +45,10 @@ function fatal_error() { exit 1 } -abs_path="$(find_dir "$0")" +base="$(find_base_dir "$0")" -if [[ "${abs_path}" ]]; then - base=`dirname ${abs_path}` -else - fatal_error "Unable to determine absolute path to $0." +if [[ -z "${base}" ]]; then + fatal_error "Unable to determine base path of $0." fi #============================================================================ From d234236fe238e4f5d5e81175f11d18fd08d214c3 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 8 Sep 2023 14:58:47 +0200 Subject: [PATCH 3/3] test invocation of lf*-dev scripts from another directory --- .github/scripts/test-lfc.sh | 5 +++++ .github/scripts/test-lfd.sh | 5 +++++ .github/scripts/test-lff.sh | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/.github/scripts/test-lfc.sh b/.github/scripts/test-lfc.sh index bc43342e44..27f4807da3 100755 --- a/.github/scripts/test-lfc.sh +++ b/.github/scripts/test-lfc.sh @@ -18,3 +18,8 @@ bin/lfc-dev test/C/src/Minimal.lf # Ensure that lfc can be invoked via symbolic links. test_with_links "lfc-dev" + +# Ensure that lfc can be invoked from outside the root directory. +cd bin +./lfc-dev --help +cd .. diff --git a/.github/scripts/test-lfd.sh b/.github/scripts/test-lfd.sh index 0f04fcc5b1..2ad7ce1108 100755 --- a/.github/scripts/test-lfd.sh +++ b/.github/scripts/test-lfd.sh @@ -18,3 +18,8 @@ bin/lfd-dev test/C/src/Minimal.lf # Ensure that lfd can be invoked via symbolic links. test_with_links "lfd-dev" + +# Ensure that lfd can be invoked from outside the root directory. +cd bin +./lfd-dev --help +cd .. diff --git a/.github/scripts/test-lff.sh b/.github/scripts/test-lff.sh index 273c26b429..11a3d36ceb 100755 --- a/.github/scripts/test-lff.sh +++ b/.github/scripts/test-lff.sh @@ -26,3 +26,8 @@ bin/lff-dev --dry-run test/Cpp/src/Minimal.lf # Ensure that lff can be invoked via symbolic links. test_with_links "lff-dev" + +# Ensure that lfc can be invoked from outside the root directory. +cd bin +./lff-dev --help +cd ..