-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1713 from lf-lang/lfd
lfd binary for generating diagrams from the command line
- Loading branch information
Showing
22 changed files
with
477 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/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 | ||
} | ||
|
||
bin/lfd test/C/src/Minimal.lf | ||
|
||
# Ensure that lfd is robust to symbolic links. | ||
test_with_links "lfd" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../util/scripts/launch.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\..\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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
buildSrc/src/main/groovy/org.lflang.distribution-conventions.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,31 @@ | ||
plugins { | ||
id 'distribution' | ||
id 'org.lflang.platform' | ||
} | ||
|
||
tasks.withType(Tar) { | ||
compression = Compression.GZIP | ||
archiveExtension = 'tar.gz' | ||
enabled = !platform.isWindows | ||
} | ||
|
||
tasks.withType(Zip) { | ||
enabled = platform.isWindows | ||
} | ||
|
||
tasks.withType(Jar) { | ||
enabled = true | ||
} | ||
|
||
tasks.withType(CreateStartScripts) { | ||
doLast { | ||
if (platform.isWindows) { | ||
delete unixScript | ||
// Fix long path issue on Windows | ||
// See https://github.com/gradle/gradle/issues/1989 | ||
windowsScript.text = windowsScript.text.replaceAll('set CLASSPATH=.*', 'set CLASSPATH=.;%APP_HOME%/lib/*') | ||
} else { | ||
delete windowsScript | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
tasks.register('platform') { | ||
def osVar = project.hasProperty('targetOS') ? project.getProperty('targetOS') : System.getProperty('os.name') | ||
def archVar = project.hasProperty('targetArch') ? project.getProperty('targetArch') : System.getProperty('os.arch') | ||
if (archVar == 'amd64') { | ||
archVar = 'x86_64' | ||
} | ||
|
||
ext { | ||
os = osVar | ||
arch = archVar | ||
isWindows = osVar.toLowerCase().contains('windows') | ||
isLinux = osVar.toLowerCase().contains('linux') | ||
isMacos = osVar.toLowerCase().contains('mac') | ||
isNative = !project.hasProperty('targetOS') && !project.hasProperty('targetArch') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plugins { | ||
id 'org.lflang.java-application-conventions' | ||
} | ||
|
||
dependencies { | ||
implementation project(':cli:base') | ||
implementation("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.standalone:$klighdVersion") { | ||
exclude group: 'de.cau.cs.kieler.swt.mock' | ||
} | ||
implementation("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.piccolo:${klighdVersion}") { | ||
exclude group: 'de.cau.cs.kieler.swt.mock' | ||
} | ||
implementation("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.piccolo.freehep:${klighdVersion}") { | ||
exclude group: 'de.cau.cs.kieler.swt.mock' | ||
} | ||
implementation("org.freehep:freehep-graphicsio-svg:${freehepVersion}") | ||
|
||
testImplementation(testFixtures(project(':core'))) | ||
testImplementation(testFixtures(project(':cli:base'))) | ||
} | ||
|
||
application { | ||
mainClass = 'org.lflang.cli.Lfd' | ||
tasks.run.workingDir = System.getProperty("user.dir") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.lflang.cli; | ||
|
||
import de.cau.cs.kieler.klighd.Klighd; | ||
import de.cau.cs.kieler.klighd.LightDiagramServices; | ||
import de.cau.cs.kieler.klighd.standalone.KlighdStandaloneSetup; | ||
import java.nio.file.Path; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.emf.ecore.resource.Resource; | ||
import org.lflang.lf.Model; | ||
import org.lflang.util.FileUtil; | ||
import picocli.CommandLine.Command; | ||
|
||
/** | ||
* Command lin tool for generating diagrams from Lingua Franca programs. | ||
* | ||
* @author Christian Menard | ||
*/ | ||
@Command( | ||
name = "lfd", | ||
// Enable usageHelp (--help) and versionHelp (--version) options. | ||
mixinStandardHelpOptions = true, | ||
versionProvider = VersionProvider.class) | ||
public class Lfd extends CliBase { | ||
|
||
@Override | ||
public void doRun() { | ||
KlighdStandaloneSetup.initialize(); | ||
Klighd.setStatusManager( | ||
(status, style) -> { | ||
switch (status.getSeverity()) { | ||
case IStatus.ERROR -> { | ||
reporter.printError(status.getMessage()); | ||
if (status.getException() != null) { | ||
status.getException().printStackTrace(); | ||
} | ||
} | ||
case IStatus.WARNING -> reporter.printWarning(status.getMessage()); | ||
default -> reporter.printInfo(status.getMessage()); | ||
} | ||
}); | ||
|
||
for (Path relativePath : getInputPaths()) { | ||
Path path = toAbsolutePath(relativePath); | ||
final Resource resource = getResource(path); | ||
if (resource == null) { | ||
reporter.printFatalErrorAndExit(path.toString() + " is not an LF program."); | ||
} | ||
final Model model = (Model) resource.getContents().get(0); | ||
String baseName = FileUtil.nameWithoutExtension(relativePath); | ||
Path outFile = io.getWd().resolve(baseName + ".svg").toAbsolutePath(); | ||
IStatus status = LightDiagramServices.renderOffScreen(model, "svg", outFile.toString()); | ||
if (!status.isOK()) { | ||
reporter.printFatalErrorAndExit(status.getMessage()); | ||
} | ||
} | ||
|
||
reporter.exit(); | ||
} | ||
|
||
/** | ||
* Main entry point of the diagram tool. | ||
* | ||
* @param args CLI arguments | ||
*/ | ||
public static void main(String[] args) { | ||
main(Io.SYSTEM, args); | ||
} | ||
|
||
/** | ||
* Programmatic entry point, with a custom IO. | ||
* | ||
* @param io IO streams. | ||
* @param args Command-line arguments. | ||
*/ | ||
public static void main(Io io, final String... args) { | ||
cliMain("lfd", Lfd.class, io, args); | ||
} | ||
} |
Oops, something went wrong.