Commit 2ce74392 authored by Andrey Filippov's avatar Andrey Filippov

Added Vivado launching, some cleanup of the code

parent 9d3c3811
......@@ -17,68 +17,14 @@
package com.elphel.vdt.core.launching;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.debug.internal.ui.views.console.ProcessConsole;
//import org.eclipse.core.resources.IProject;
//import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.IStreamListener;
//import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.IProcess;
//import org.eclipse.debug.ui.DebugUITools;
//import org.eclipse.ui.console.ConsolePlugin;
//import org.eclipse.ui.console.IConsoleManager;
//import org.eclipse.ui.console.IPatternMatchListener;
//import org.eclipse.ui.console.MessageConsole;
import org.eclipse.debug.core.model.IStreamMonitor;
import org.eclipse.debug.core.model.IStreamsProxy;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.ui.console.IConsole;
//import org.eclipse.debug.ui.console.IConsole;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.IOConsole;
import org.eclipse.ui.console.IOConsoleInputStream;
import org.eclipse.ui.console.IOConsoleOutputStream;
import com.elphel.vdt.Txt;
import com.elphel.vdt.core.tools.contexts.BuildParamsItem;
import com.elphel.vdt.ui.MessageUI;
//import com.elphel.vdt.VDTPlugin;
import com.elphel.vdt.veditor.VerilogPlugin;
import com.elphel.vdt.veditor.parser.OutlineContainer;
import com.elphel.vdt.veditor.preference.PreferenceStrings;
//import com.elphel.vdt.core.Utils;
import org.eclipse.ui.console.IConsoleListener;
public class RunningBuilds {
......@@ -87,19 +33,25 @@ public class RunningBuilds {
public RunningBuilds(){
unfinishedBuilds = new ConcurrentHashMap<String, VDTRunnerConfiguration>();
IConsoleManager manager = ConsolePlugin.getDefault().getConsoleManager();
// This is not used, just for testing
System.out.println("***Addded console listeners");
// This is not used, just for testing
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_LAUNCHING)) {
System.out.println("***Addded console listeners");
}
manager.addConsoleListener(new IConsoleListener(){
public void consolesAdded(IConsole[] consoles){
for (int i=0;i<consoles.length;i++){
System.out.println("+++ Added: "+consoles[i].getName());
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_LAUNCHING)) {
System.out.println("+++ Added: "+consoles[i].getName());
}
// Only shows added consoles
}
}
public void consolesRemoved(IConsole[] consoles){
for (int i=0;i<consoles.length;i++){
System.out.println("--- Removed: "+consoles[i].getName());
// unfinishedBuilds.remove(consoles[i]);
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_LAUNCHING)) {
System.out.println("--- Removed: "+consoles[i].getName());
}
// unfinishedBuilds.remove(consoles[i]);
removeConsole(consoles[i]);
}
}
......@@ -108,16 +60,24 @@ public class RunningBuilds {
public String findConsoleParent(IConsole console){
Iterator<String> iter=unfinishedBuilds.keySet().iterator();
System.out.println("findConsoleParent("+console.getName()+")");
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_LAUNCHING)) {
System.out.println("findConsoleParent("+console.getName()+")");
}
while (iter.hasNext()) {
String consoleName=iter.next();
System.out.print("Got console name:"+consoleName);
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_LAUNCHING)) {
System.out.print("Got console name:"+consoleName);
}
VDTRunnerConfiguration runConfig=unfinishedBuilds.get(consoleName);
if (runConfig.hasConsole(console)){
System.out.println(consoleName+" -> GOT IT");
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_LAUNCHING)) {
System.out.println(consoleName+" -> GOT IT");
}
return consoleName;
}
System.out.println(consoleName+" -> no luck");
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_LAUNCHING)) {
System.out.println(consoleName+" -> no luck");
}
}
return null;
}
......@@ -126,13 +86,19 @@ public class RunningBuilds {
if (consoleName!=null){
VDTRunnerConfiguration runConfig=unfinishedBuilds.get(consoleName);
runConfig.removeConsole(console);
System.out.println("Removing console "+console.getName()+" from runConfig for "+consoleName);
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_LAUNCHING)) {
System.out.println("Removing console "+console.getName()+" from runConfig for "+consoleName);
}
if (runConfig.noConsoles()){
System.out.println("No consoles left in unfinished "+consoleName+" - removing it too");
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_LAUNCHING)) {
System.out.println("No consoles left in unfinished "+consoleName+" - removing it too");
}
unfinishedBuilds.remove(consoleName);
}
} else {
System.out.println("Console "+console.getName()+" did not belong here");
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_LAUNCHING)) {
System.out.println("Console "+console.getName()+" did not belong here");
}
}
}
public boolean isUnfinished(IConsole console){
......
......@@ -42,6 +42,7 @@ import com.elphel.vdt.VDT;
import com.elphel.vdt.VerilogUtils;
// import com.elphel.vdt.VDTPlugin;
import com.elphel.vdt.veditor.VerilogPlugin;
import com.elphel.vdt.veditor.preference.PreferenceStrings;
import com.elphel.vdt.core.tools.ToolsCore;
import com.elphel.vdt.core.tools.contexts.BuildParamsItem;
import com.elphel.vdt.core.tools.params.Parameter;
......@@ -64,13 +65,17 @@ public class VDTLaunchUtil {
* Returns the VDT runner.
*/
public static VDTRunner getRunner() {
if (toolRunner == null) {
System.out.println ("Created new VDTRunner()");
toolRunner = new VDTRunner();
} else {
System.out.println ("Reused old VDTRunner()");
}
return toolRunner;
if (toolRunner == null) {
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_LAUNCHING)) {
System.out.println ("Created new VDTRunner()");
}
toolRunner = new VDTRunner();
} else {
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_LAUNCHING)) {
System.out.println ("Reused old VDTRunner()");
}
}
return toolRunner;
}
//runningBuilds
/**
......
......@@ -106,13 +106,15 @@ public class VDTRunner {
// make call it when console is closed
private void doResumeLaunch(String consoleName ) throws CoreException {
final VDTRunnerConfiguration runConfig=runningBuilds.resumeConfiguration(consoleName);
final boolean debugPrint=VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_LAUNCHING);
if (runConfig==null){
System.out.println("Turned out nothing to do. Probably a bug");
return;
}
BuildParamsItem[] argumentsItemsArray = runConfig.getArgumentsItemsArray(); // uses already calculated
int numItem=runConfig.getBuildStep();
System.out.println("--------- resuming "+ consoleName+", numItem="+numItem+" ------------");
if (debugPrint) System.out.println("--------- resuming "+ consoleName+", numItem="+numItem+" ------------");
ILaunch launch=runConfig.getLaunch();
IProgressMonitor monitor=runConfig.getMonitor();
for (;numItem<argumentsItemsArray.length;numItem++){
......@@ -132,7 +134,7 @@ public class VDTRunner {
}
if (argumentsItemsArray[numItem].getNameAsParser()!=null){
// parsers should be launched by the console scripts, in parallel to them
System.out.println("Skipping parser "+argumentsItemsArray[numItem].getNameAsParser());
if (debugPrint) System.out.println("Skipping parser "+argumentsItemsArray[numItem].getNameAsParser());
continue;
}
// Launch the configuration - 1 unit of work
......@@ -147,8 +149,6 @@ public class VDTRunner {
);
//Andrey: if there is a single item - launch asynchronously, if more - verify queue is empty
// will not change
// String consoleName=renderProcessLabel(runConfig.getToolName());
// check for cancellation
if (monitor.isCanceled() || (process==null)) {
......@@ -163,17 +163,17 @@ public class VDTRunner {
IOConsole iCons= (IOConsole) DebugUITools.getConsole(process); // had non-null fPatternMatcher , fType="org.eclipse.debug.ui.ProcessConsoleType"
if (iCons==null){
System.out.println("Could not get a console for the specified process");
System.out.println("Could not get console for the specified process");
continue;
}
System.out.println("originalConsoleName="+consoleName+
if (debugPrint) System.out.println("originalConsoleName="+consoleName+
"\nprocessConsole name="+iCons.getName());
final IOConsole fiCons=iCons;
// final String fConsoleName=fiCons.getName(); // actual console name - may be already "<terminated> ... "
final String fConsoleName=consoleName; // calculated console name - used for launching external program
// if (!fConsoleName.equals(consoleName)){ // terminated before we added listeners
if (!fConsoleName.equals(fiCons.getName())){ // terminated before we added listeners
System.out.println("Already terminated, proceed to the next item");
if (debugPrint) System.out.println("Already terminated, proceed to the next item");
continue; // proceed with the next item without pausing
}
/* Prepare to postpone next commands to be resumed by event*/
......@@ -184,37 +184,41 @@ public class VDTRunner {
public void propertyChange(PropertyChangeEvent event) {
if (!fConsoleName.equals(fiCons.getName())){
fiCons.removePropertyChangeListener(this);
System.out.println(">>> "+fConsoleName+" -> "+fiCons.getName());
// VDTRunner runner = VDTLaunchUtil.getRunner();
if (debugPrint) System.out.println(">>> "+fConsoleName+" -> "+fiCons.getName());
try {
resumeLaunch(fConsoleName); // replace with console
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println ("Failed to resume launch sequence");
}
}
}
});
if (!fConsoleName.equals(consoleName)){ // terminated before we added listeners
System.out.println("Fire!");
if (debugPrint) System.out.println("Fire!");
iCons.firePropertyChange(fiCons,"org.eclipse.jface.text", consoleName, fConsoleName);
}
System.out.println("return - waiting to be awaken");
if (debugPrint) System.out.println("return - waiting to be awaken");
int timeout=argumentsItemsArray[numItem].getTimeout();
if (timeout>0){
final int fTimeout = timeout;
final IProcess fProcess=process;
new Timer().schedule(new TimerTask() {
@Override
public void run() {
System.out.println(">>Timeout<<");
try {
fProcess.terminate();
} catch (DebugException e) {
System.out.println("Failed to terminate preocess on "+fConsoleName);
}
}
}, fTimeout*1000);
System.out.println ("timeout is only implemented for console scripts");
// implementation will require keeping track of it and canceling if program terminated earlier.
// And for the programs it is easy to kill them manually with a red square button
if (timeout>100000) { //never with no warnings
final int fTimeout = timeout;
final IProcess fProcess=process;
new Timer().schedule(new TimerTask() {
@Override
public void run() {
System.out.println(">>Timeout<<");
try {
fProcess.terminate();
} catch (DebugException e) {
System.out.println("Failed to terminate process on "+fConsoleName);
}
}
}, fTimeout*1000);
}
}
return;
......@@ -397,7 +401,9 @@ public class VDTRunner {
if (consoles.length>1){
// ((IConsole) consoles[1]).setName("Python Consloe");
}
System.out.println(consoles.length+" consoles, processes="+launch.getChildren().length);
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_LAUNCHING)){
System.out.println(consoles.length+" consoles, processes="+launch.getChildren().length);
}
return process;
//= consoles
//setImageDescriptor
......
......@@ -49,6 +49,14 @@
icon="my_tool.gif"
call="RemotePythonCommand"/>
<menuitem name="Vivado"
label="Run remote Vivado session"
icon="xilinx.png"
call="Vivado"/>
<menuitem name="Vivado Test"
label="Send a command to the remote Vivado session"
icon="my_tool.gif"
call="VivadoTest"/>
<menu name="XDS"
label="Demo XDS Tools"
......
......@@ -30,9 +30,11 @@
<parameter id="ShellSwitches" label="Shell switches" type="String"
format="CopyValue" default="-c" readonly="false" visible="true" />
<parameter id="SSHSwitches" label="Remote ssh switches"
type="String" format="CopyValue" default="" readonly="false" visible="true" />
<parameter id="TerminalMode" type="BoolYesNo" format="None"
default="false" label="Force termonal mode for remote program" />
<parameter id="SSHSwitches" label="Other ssh switches"
type="String" format="CopyValue" default="" readonly="false" visible="true" />
<parameter id="RemoteCommand" label="Remote ssh command"
type="String" format="CopyValue" default="python -i -u" readonly="false"
......@@ -45,6 +47,7 @@
<group name="General">
"RemoteHost"
"RemoteUser"
"TerminalMode"
"ShellSwitches"
"PreSSH"
"SSHSwitches"
......@@ -59,11 +62,13 @@
"%ShellSwitches"
"%PreSSH"
"ssh"
"-t"
<if TerminalMode = "true">
"-t -t"
</if>
"%SSHSwitches"
"-l"
"%RemoteUser"
"%RemoteHost"
"%SSHSwitches"
"'"
"%RemoteCommand"
"'"
......
<?xml version="1.0" encoding="UTF-8"?>
<vdt-project>
<interface name="VivadoInterface" extends="project_interface">
<syntax name="ProgramSyntax" format="%(%%ParamValue%|\n%)" />
</interface>
<tool name="Vivado" project="FPGA_project" label="Launch Vivado"
shell="/bin/bash" interface="VivadoInterface" description="Launching remote Xilinx Vivado in console"
errors="(.*):([0-9]+): [a-z ]*error: (.*)" warnings="(.*):([0-9]+): warning: (.*)"
info="(.*):([0-9]+): info: (.*)"> <!--does not actually exist -->
<extensions-list>
<extension mask="v" />
<extension mask="tf" />
</extensions-list>
<action-menu>
<action label="Launch Vivado" resource="" icon="xilinx.png" />
</action-menu>
<parameter id="RemoteHost" label="Remote Host IP" type="String"
format="CopyValue" default="192.168.0.122" readonly="false" visible="true" />
<parameter id="RemoteUser" label="Remote user name" type="String"
format="CopyValue" default="xilinx" readonly="false" visible="true" />
<parameter id="PreSSH" label="pre-ssh shell parameters"
type="String" format="CopyValue" default="" readonly="false" visible="true" />
<parameter id="ShellSwitches" label="Shell switches" type="String"
format="CopyValue" default="-c" readonly="false" visible="true" />
<parameter id="TerminalMode" type="BoolYesNo" format="None"
default="false" label="Force termonal mode for remote program" />
<parameter id="SSHSwitches" label="Other ssh switches"
type="String" format="CopyValue" default="" readonly="false" visible="true" />
<parameter id="RemoteCommand" label="Remote ssh command"
type="String" format="CopyValue" default="/opt/Xilinx/Vivado/2013.4/bin/vivado -mode tcl" readonly="false"
visible="true" />
<parameter id="SSHExtra" label="ssh extra parameters" type="String"
format="CopyValue" default="" readonly="false" visible="true" />
<input>
<group name="General">
"RemoteHost"
"RemoteUser"
"TerminalMode"
"ShellSwitches"
"PreSSH"
"SSHSwitches"
"RemoteCommand"
"SSHExtra"
</group>
</input>
<output>
<line name="vivado_launch"
interrupt="\x03">
"%ShellSwitches"
"%PreSSH"
"ssh"
<if TerminalMode = "true">
"-t -t"
</if>
"%SSHSwitches"
"-l"
"%RemoteUser"
"%RemoteHost"
"'"
"%RemoteCommand"
"'"
"%SSHExtra"
</line>
</output>
</tool>
<tool name="VivadoTest" project="FPGA_project" label="VivadoCommand"
shell="/bin/bash" interface="VivadoInterface"
description="Sending command to a remote Vivado session" errors="(.*):([0-9]+): [a-z ]*error: (.*)"
warnings="(.*):([0-9]+): warning: (.*)" info="(.*):([0-9]+): info: (.*)"> <!--does not actually exist -->
<extensions-list>
<extension mask="v" />
<extension mask="tf" />
</extensions-list>
<action-menu>
<action label="Vivado Command" resource="" icon="xilinx.png" />
</action-menu>
<parameter id="RemoteCommand" label="Remote Command to send"
type="Stringlist" format="ProgramSyntax" default="puts &quot;Hello, World!&quot;"
readonly="false" visible="true" />
<parameter id="vivado_console" default="Vivado"
type="String" format="CopyValue" visible="false" />
<parameter id="Timeout" label="Script timeout(sec)" type="Cardinal"
format="CopyValue" default="10" readonly="false" visible="true" />
<input>
<group name="General">
"RemoteCommand"
"Timeout"
</group>
</input>
<output>
<line name="pre_tcl">
"-c"
"echo 'scp files here' ;"
"sleep 2 ;"
</line>
<!-- TODO: Make it OK to ose just strings, not parameters in dest (for console names) -->
<line name="vivado_line_01"
dest="vivado_console"
mark="``"
sep="\n"
prompt="@@FINISH@@"
stdout="parser_001"
timeout="Timeout">
"%RemoteCommand"
"puts '@@FINISH@@'"
"``"`" <!-- two new lines should generate a pair of prompts from the remote -->
</line>
<line name="command_line_02">
"-c"
"echo 'Will scp result files back here' ;"
"sleep 2 ;"
</line>
<!-- parser_01 being referenced should be launched in an asynchronous process/console, removed from the launch sequence -->
<line name="parser_001"
errors="(.*):([0-9]+): [a-z ]*error: (.*)"
warnings="(.*):([0-9]+): warning: (.*)"
info="(.*):([0-9]+): info: (.*)">
"-c"
"cat"
</line>
</output>
</tool>
</vdt-project>
<!-- /opt/Xilinx/Vivado/2013.4/bin/vivado -mode tcl -->
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment