Skip to content

Commit

Permalink
Merge pull request #1422 from lf-lang/refactor-cli
Browse files Browse the repository at this point in the history
New lff script and `org.lflang.cli` moved into `org.lflang` as subpackage
  • Loading branch information
lhstrh authored Oct 28, 2022
2 parents 5ae08c3 + 734c05c commit bbbfad6
Show file tree
Hide file tree
Showing 43 changed files with 294 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

set -euo pipefail

# build lf compiler
./gradlew clean buildLfc
# build lf cli tools
./gradlew clean buildAll

# find the version number
jar_path="org.lflang.cli/build/libs/org.lflang.cli-*-lfc.jar"
version="$(ls ${jar_path} | xargs -n 1 basename | sed 's/^org.lflang.cli-\(.*\)-lfc.jar$/\1/')"
jar_path="org.lflang/build/libs/org.lflang-*.jar"
version="$(ls ${jar_path} | xargs -n 1 basename | sed 's/^org.lflang-\(.*\).jar$/\1/')"

# use a different naming convention for nightly build artifacts
if [[ "$#" > 0 && "$1" = "nightly" ]]; then
echo "Packaging Lingua Franca Nightly Build"
outname="lfc_nightly_$(date '+%Y%m%d-%H%M%S')"
outname="lf-cli-nightly-$(date '+%Y%m%d-%H%M%S')"
else
echo "Packaging Lingua Franca v${version}"
outname="lfc_${version}"
outname="lf-cli-${version}"
fi

# assemble the files in a separate directory
Expand All @@ -24,13 +24,15 @@ mkdir -p "${outname}/lib/scripts"
mkdir -p "${outname}/lib/jars"

# move the jar
mv org.lflang.cli/build/libs/org.lflang.cli-*-lfc.jar "${outname}/lib/jars"
mv org.lflang/build/libs/org.lflang-*.jar "${outname}/lib/jars"

# copy the Bash scripts
cp -a lib/scripts "${outname}/lib/"
ln -s "../lib/scripts/launch.sh" "${outname}/bin/lfc"
ln -s "../lib/scripts/launch.sh" "${outname}/bin/lff"
# copy the PowerShell script
cp bin/lfc.ps1 "${outname}/bin/lfc.ps1"
cp bin/lff.ps1 "${outname}/bin/lff.ps1"

# zip/tar everything - the files will be put into the build_upload directory
mkdir -p build_upload
Expand Down
25 changes: 25 additions & 0 deletions .github/scripts/test-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

# Exit 1 if any command returns with a non-zero exit code.
set -euo pipefail

cd $GITHUB_WORKSPACE

function test_with_links() {
rm -rf foo
mkdir -p foo/bar/baz
ln -s ../bin/${1} foo/link-foo
ln -s ../link-foo foo/bar/link-bar
ln -s ../link-bar foo/bar/baz/link-baz
foo/bar/baz/link-baz --help
}

# Test the build-lf-cli executable and its flags.
bin/build-lf-cli
bin/build-lf-cli --help
bin/build-lf-cli -h
bin/build-lf-cli -c -o -s
bin/build-lf-cli --clean --offline --stacktrace

# Ensure that build-lf-cli is robust to symbolic links.
test_with_links "build-lf-cli"
17 changes: 2 additions & 15 deletions .github/scripts/test-lfc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,10 @@ function test_with_links() {
mkdir -p foo/bar/baz
ln -s ../bin/${1} foo/link-foo
ln -s ../link-foo foo/bar/link-bar
ln -s ../link-bar foo/bar/baz/link-baz
foo/bar/baz/link-baz --help
ln -s ../link-bar foo/bar/baz/link-${1}
foo/bar/baz/link-${1} --help
}

# Test the build-lfc executable and its flags.
bin/build-lfc
bin/build-lfc --help
bin/build-lfc -h
bin/build-lfc --run --help
bin/build-lfc -r --help
bin/build-lfc --run test/C/src/Minimal.lf
bin/build-lfc -c -o -s
bin/build-lfc --clean --offline --stacktrace

# Ensure that build-lfc is robust to symbolic links.
test_with_links "build-lfc"

bin/lfc test/C/src/Minimal.lf

# -c,--clean Clean before building.
Expand Down
28 changes: 28 additions & 0 deletions .github/scripts/test-lff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

# Exit 1 if any command returns with a non-zero exit code.
set -euo pipefail

cd $GITHUB_WORKSPACE

function test_with_links() {
rm -rf foo
mkdir -p foo/bar/baz
ln -s ../bin/${1} foo/link-foo
ln -s ../link-foo foo/bar/link-bar
ln -s ../link-bar foo/bar/baz/link-${1}
foo/bar/baz/link-${1} --help
}

# just a couple of smoke tests
bin/lff --help
bin/lff --version

bin/lff -d test/C/src/Minimal.lf
bin/lff --dry-run test/Cpp/src/Minimal.lf

bin/lff -d test/C/src/Minimal.lf
bin/lff --dry-run test/Cpp/src/Minimal.lf

# Ensure that lff is robust to symbolic links.
test_with_links "lff"
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ jobs:
fetch-depth: 0
- name: Prepare build environment
uses: ./.github/actions/prepare-build-env
- name: Build and package lfc (nightly build)
run: .github/scripts/package_lfc.sh nightly
- name: Build and package lf cli tools (nightly build)
run: .github/scripts/package-cli.sh nightly
shell: bash
if: ${{ inputs.nightly == true }}
- name: Build and package lfc (regular build)
run: .github/scripts/package_lfc.sh
- name: Build and package lf cli tools (regular build)
run: .github/scripts/package-cli.sh
shell: bash
if: ${{ inputs.nightly != true }}
- name: Check Maven/Java configuration
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
cancel:
uses: lf-lang/lingua-franca/.github/workflows/cancel.yml@master

# Test the Maven build.
# Test the Gradle and Maven build.
build:
uses: lf-lang/lingua-franca/.github/workflows/build.yml@master
uses: lf-lang/lingua-franca/.github/workflows/build.yml@refactor-cli
needs: cancel

# Run the unit tests.
Expand All @@ -32,7 +32,7 @@ jobs:

# Run tests for the standalone compiler.
cli-tests:
uses: lf-lang/lingua-franca/.github/workflows/cli-tests.yml@master
uses: lf-lang/lingua-franca/.github/workflows/cli-tests.yml@refactor-cli
needs: cancel

# Run the C benchmark tests.
Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/cli-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,24 @@ jobs:
fetch-depth: 0
- name: Prepare build environment
uses: ./.github/actions/prepare-build-env
- name: Run standalone cli tests
# FIXME: reenable once the cli test is fixed
# - name: Run standalone cli tests
# run: |
# ./gradlew :org.lflang.cli:test --stacktrace
- name: Test build bash scripts (Linux and macOS only)
run: |
./gradlew :org.lflang.cli:test --stacktrace
- name: Test Bash scripts (Linux or macOS only)
.github/scripts/test-build.sh
if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }}
- name: Test lfc bash scripts (Linux or macOS only)
run: |
.github/scripts/test-lfc.sh
if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }}
- name: Test lff bash scripts (Linux or macOS only)
run: |
.github/scripts/test-lff.sh
if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }}
- name: Test PowerShell script (Windows only)
run: |
./gradlew buildLfc
./gradlew buildAll
bin/lfc.ps1 --help
if: ${{ runner.os == 'Windows' }}
1 change: 1 addition & 0 deletions bin/build-lf-cli
49 changes: 4 additions & 45 deletions bin/lfc.ps1
Original file line number Diff line number Diff line change
@@ -1,50 +1,9 @@
#==========================================================
# Description: Run the lfc compiler.
# Authors: Christian Menard, Peter Donovan
# Authors: Ruomu Xu
# Usage: Usage: lfc [options] files...
#==========================================================

$base="$PSScriptRoot\.."
$java_home = "$Env:JAVA_HOME"
$java_cmd = "$java_home\bin\java.exe"
$jarpath_dev="$base\org.lflang.cli\build\libs\org.lflang.cli-*-lfc.jar"
$jarpath_release="$base\lib\jars\org.lflang.cli-*-lfc.jar"

function Test-Dev {
Test-Path "$base\org.lflang.cli" -PathType container
}

function Get-JarPath {
if (Test-Dev) {
if (Test-Path $jarpath_dev -PathType leaf) {
$jarpath=$(Get-ChildItem $jarpath_dev).toString()
} else {
throw "Failed to find a copy of the Lingua Franca compiler matching the pattern ""$jarpath_dev"". Did you remember to build?"
}
} else {
if (Test-Path $jarpath_release -PathType leaf) {
$jarpath=$(Get-ChildItem $jarpath_release).toString()
} else {
throw "Failed to find a copy of the Lingua Franca compiler matching the pattern ""$jarpath_release""."
}
}
$jarpath
}

# check if we can find java executable in $java_home
if (-not (Test-Path $java_cmd)) {
# otherwise, try to run java directly
if (-not (Get-Command java -errorAction SilentlyContinue)) {
throw "JRE not found"
}
$java_cmd = "java"
}

# check for correct java version
$java_version = (Get-Command java | Select-Object -ExpandProperty Version).toString()
if ([version]$java_version -lt [version]"17.0") {
throw "JRE $java_version found but 17.0 or greater is required."
}

# invoke lfc
& $java_cmd -jar $(Get-JarPath) $args
$launchScript="$PSScriptRoot\..\lib\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
1 change: 1 addition & 0 deletions bin/lff
9 changes: 9 additions & 0 deletions bin/lff.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#==========================================================
# Description: Run the lff compiler.
# Authors: Ruomu Xu
# Usage: Usage: lff [options] files...
#==========================================================

$launchScript="$PSScriptRoot\..\lib\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
20 changes: 9 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,14 @@ subprojects {
}
}

gradle.projectsEvaluated {
// Our CI uses --tests filters, which fails if some
// subprojects have no matching test.
//
// https://stackoverflow.com/questions/26147480/how-to-make-gradle-not-to-mark-build-failed-if-no-tests-are-found
subprojects {
test {
filter {
setFailOnNoMatchingTests(false)
}
// Our CI uses --tests filters, which fails if some
// subprojects have no matching test.
//
// https://stackoverflow.com/questions/26147480/how-to-make-gradle-not-to-mark-build-failed-if-no-tests-are-found
subprojects {
test {
filter {
setFailOnNoMatchingTests(false)
}
}
}
Expand Down Expand Up @@ -112,4 +110,4 @@ spotless {
formatAnnotations()
}
}
tasks.withType(SpotlessTask) { it.dependsOn(":org.lflang.cli:jarLff") }
tasks.withType(SpotlessTask) { it.dependsOn(":org.lflang:jarCliTools") }
25 changes: 7 additions & 18 deletions lib/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
# 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.

if [[ "$0" == *build-lfc ]]; then
echo -e "\033[33mWarning; buid-lfc is deprecated! Please use build-lf-cli instead.\033[0m"
fi

find_dir() (
start_dir=$PWD
cd "$(dirname "$1")"
Expand Down Expand Up @@ -60,7 +65,7 @@ fi

# Print message explaining the CLI args.
function usage() {
echo "Usage: build-lfc [options] [[-r | --run] [lfc-args]]"
echo "Usage: build-lf-cli [options] [lfc-args]]"
echo "Options:"
echo " -c | --clean Build entirely from scratch."
echo " -h | --help Display this information."
Expand All @@ -87,15 +92,6 @@ while [[ "$#" -gt 0 ]]; do
usage
exit 0
;;
-r | --run )
run=true
shift
while [[ "$#" -gt 0 ]]; do
args+=("$1")
shift
done
break
;;
*)
usage
exit 1
Expand All @@ -121,22 +117,15 @@ jar_path="$(get_jar_path)"

if [ ! -f "${jar_path}" ] || ! "${find_cmd}" "${base}" \
-path "${src_pkg_path}" \
-path "${lfc_src_pkg_path}" \
-prune -o \
-type f \
-newer "${jar_path}" \
-exec false {} +; then
# Rebuild.
1>&2 echo "Jar file is missing or out-of-date; starting rebuild..."
"${base}/gradlew" ${flags} -p "${base}" buildLfc
"${base}/gradlew" ${flags} -p "${base}" buildAll
# Update the timestamp in case the jar was not touched by Gradle.
touch -c -- "${jar_path}"
else
echo "Already up-to-date."
fi

# Run lfc with the provided arguments.
if [[ "${run}" == "true" ]]; then
echo "Running lfc..."
run_lfc_with_args "${args[@]}"
fi
Loading

0 comments on commit bbbfad6

Please sign in to comment.