Skip to content

Commit

Permalink
Merge pull request #1995 from lf-lang/no-util
Browse files Browse the repository at this point in the history
More robust dev scripts and removed util directory
  • Loading branch information
cmnrd authored Sep 8, 2023
2 parents 6e6d0e9 + d234236 commit f1921bc
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 139 deletions.
5 changes: 5 additions & 0 deletions .github/scripts/test-lfc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..
5 changes: 5 additions & 0 deletions .github/scripts/test-lfd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..
5 changes: 5 additions & 0 deletions .github/scripts/test-lff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..
1 change: 0 additions & 1 deletion bin/lfc-dev

This file was deleted.

59 changes: 59 additions & 0 deletions bin/lfc-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/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_base_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 "${link}")")
((count++))
else
return
fi
done
real_path="${PWD}"
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
}

base="$(find_base_dir "$0")"

if [[ -z "${base}" ]]; then
fatal_error "Unable to determine base path of $0."
fi
#============================================================================

gradlew="${base}/gradlew"

# Launch the tool.
"${gradlew}" --quiet -p "${base}" assemble ":cli:lfc:assemble"
"${base}/build/install/lf-cli/bin/lfc" "$@"
20 changes: 13 additions & 7 deletions bin/lfc-dev.ps1
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion bin/lfd-dev

This file was deleted.

59 changes: 59 additions & 0 deletions bin/lfd-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/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_base_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 "${link}")")
((count++))
else
return
fi
done
real_path="${PWD}"
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
}

base="$(find_base_dir "$0")"

if [[ -z "${base}" ]]; then
fatal_error "Unable to determine base path of $0."
fi
#============================================================================

gradlew="${base}/gradlew"

# Launch the tool.
"${gradlew}" --quiet -p "${base}" assemble ":cli:lfd:assemble"
"${base}/build/install/lf-cli/bin/lfd" "$@"
20 changes: 13 additions & 7 deletions bin/lfd-dev.ps1
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion bin/lff-dev

This file was deleted.

59 changes: 59 additions & 0 deletions bin/lff-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/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_base_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 "${link}")")
((count++))
else
return
fi
done
real_path="${PWD}"
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
}

base="$(find_base_dir "$0")"

if [[ -z "${base}" ]]; then
fatal_error "Unable to determine base path of $0."
fi
#============================================================================

gradlew="${base}/gradlew"

# Launch the tool.
"${gradlew}" --quiet -p "${base}" assemble ":cli:lff:assemble"
"${base}/build/install/lf-cli/bin/lff" "$@"
20 changes: 13 additions & 7 deletions bin/lff-dev.ps1
Original file line number Diff line number Diff line change
@@ -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
4 changes: 0 additions & 4 deletions util/README.md

This file was deleted.

34 changes: 0 additions & 34 deletions util/scripts/launch.ps1

This file was deleted.

Loading

0 comments on commit f1921bc

Please sign in to comment.