Skip to contentSkip to conversation

Send output from bitbake environment parsing in the background

PATCH New Ioana Grigoropol 1 participant 1 message Jan 10, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Send output from bitbake environment parsing in the background

- after creating the project, the wizard should not block waiting for the environment to be populated and instead should be ran in the background

---
 .../src/org/yocto/bc/bitbake/BBSession.java        |   83 ++++++++++++--------
 .../src/org/yocto/bc/bitbake/ShellSession.java     |    3 +-
 .../org/yocto/bc/remote/utils/RemoteHelper.java    |    3 +-
 .../org/yocto/bc/remote/utils/RemoteMachine.java   |    3 -
 .../remote/utils/YoctoHostShellProcessAdapter.java |   16 +++-
 .../org/yocto/bc/ui/filesystem/OEFileSystem.java   |    6 --
 .../yocto/bc/ui/wizards/FiniteStateWizardPage.java |   54 +++++++------
 .../bc/ui/wizards/NewBitBakeFileRecipeWizard.java  |   58 +++++++-------
 .../yocto/bc/ui/wizards/install/InstallWizard.java |   63 +++++++++------
 .../yocto/bc/ui/wizards/install/OptionsPage.java   |   10 ++-
 10 files changed, 174 insertions(+), 125 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBSession.java +50 -33
index 66a6083..124b9a2 100644
@@ -13,8 +13,8 @@ package org.yocto.bc.bitbake;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileFilter;
+import java.io.FileReader;
 import java.io.IOException;
-import java.io.StringReader;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -48,7 +48,7 @@ import org.yocto.bc.ui.model.ProjectInfo;
 /**
  * BBSession encapsulates a global bitbake configuration and is the primary interface
  * for actions against a BitBake installation.
- * 
+ *
  * @author kgilmer
  *
  */
@@ -57,7 +57,9 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 	public static final int TYPE_UNKNOWN = 2;
 	public static final int TYPE_STATEMENT = 3;
 	public static final int TYPE_FLAG = 4;
-	
+
+	public static final String BB_ENV_FILE = "bitbake.env";
+
 	public static final String BUILDDIR_INDICATORS [] = {
 		"/conf/local.conf",
 		"/conf/bblayers.conf",
@@ -74,20 +76,20 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 	private final Lock wlock = rwlock.writeLock();
 	protected String parsingCmd;
 	private boolean silent = false;
-	
+
 	public BBSession(ShellSession ssession, URI projectRoot) throws IOException {
 		shell = ssession;
 		this.pinfo = new ProjectInfo();
 		pinfo.setLocation(projectRoot);
 		pinfo.setInitScriptPath(ProjectInfoHelper.getInitScriptPath(projectRoot));
-		this.parsingCmd = "DISABLE_SANITY_CHECKS=\"1\" bitbake -e";
+		this.parsingCmd = "sh -c 'DISABLE_SANITY_CHECKS=\"1\" bitbake -e >& " + BB_ENV_FILE + "  '" ;
 	}
 
 	public BBSession(ShellSession ssession, URI projectRoot, boolean silent) throws IOException {
 		this(ssession, projectRoot);
 		this.silent = silent;
 	}
-	
+
 	private Collection adapttoIPath(List<File> asList, IProject project) {
 
 		List pathList = new ArrayList();
@@ -102,7 +104,7 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 
 		return pathList;
 	}
-	
+
 	private String appendAll(String[] elems, int st) {
 		StringBuffer sb = new StringBuffer();
 
@@ -112,7 +114,7 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 
 		return sb.toString();
 	}
-	
+
 	private int charCount(String trimmed, char c) {
 		int i = 0;
 		int p = 0;
@@ -124,11 +126,13 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 
 		return i;
 	}
-	
+
+	@Override
 	public void clear() {
 		throw new RuntimeException("BB configuration is read-only.");
 	}
 
+	@Override
 	public boolean containsKey(Object arg0) {
 		try {
 			checkValidAndLock(true);
@@ -141,6 +145,7 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 		}
 	}
 
+	@Override
 	public boolean containsValue(Object arg0) {
 		try {
 			checkValidAndLock(true);
@@ -153,6 +158,7 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 		}
 	}
 
+	@Override
 	public Set entrySet() {
 		try {
 			checkValidAndLock(true);
@@ -188,7 +194,7 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 
 	/**
 	 * Recursively generate list of Recipe files from a root directory.
-	 * 
+	 *
 	 * @param rootDir
 	 * @param recipes
 	 * @param fileExtension
@@ -197,6 +203,7 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 	private void findRecipes(File rootDir, List recipes, final String fileExtension, IProject project) {
 		File[] children = rootDir.listFiles(new FileFilter() {
 
+			@Override
 			public boolean accept(File pathname) {
 				return pathname.isFile() && pathname.getName().endsWith(fileExtension);
 			}
@@ -209,6 +216,7 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 
 		File[] childDirs = rootDir.listFiles(new FileFilter() {
 
+			@Override
 			public boolean accept(File pathname) {
 				return pathname.isDirectory();
 			}
@@ -240,6 +248,7 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 		return recipes;
 	}
 
+	@Override
 	public Object get(Object arg0) {
 		try {
 			checkValidAndLock(true);
@@ -274,9 +283,9 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 				conMan.addConsoles(new IConsole[] { sessionConsole });
 			}
 		}
-		
+
 		ConsolePlugin.getDefault().getConsoleManager().showConsoleView(sessionConsole);
-		
+
 		return sessionConsole;
 	}
 
@@ -348,6 +357,7 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 		if(clear)
 			console.clearConsole();
 		new WorkbenchJob("Display parsing result") {
+			@Override
 			public IStatus runInUIThread(IProgressMonitor monitor) {
 				if(code != 0) {
 					info.setColor(JFaceResources.getColorRegistry().get(JFacePreferences.ERROR_COLOR));
@@ -378,11 +388,11 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 				if(!initialized) { //recheck
 					boolean hasErrors = false;
 					String result = shell.execute(parsingCmd, hasErrors);
-					if(!hasErrors) {
-						properties = parseBBEnvironment(result);
-					} else {
-						properties = parseBBEnvironment("");
-					}
+
+					//FIXME : wait for bitbake to finish
+
+					properties = parseBBEnvironment(result);
+
 					initialized = true;
 				}
 			} finally {
@@ -396,6 +406,7 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 		//not release lock
 	}
 
+	@Override
 	public void initialize() throws Exception {
 		try {
 			checkValidAndLock(false);
@@ -414,6 +425,7 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 		// return trimmed.indexOf('{') > -1 && trimmed.indexOf('}') == -1;
 	}
 
+	@Override
 	public boolean isEmpty() {
 		try {
 			checkValidAndLock(true);
@@ -425,7 +437,8 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 			rlock.unlock();
 		}
 	}
-	
+
+	@Override
 	public Set keySet() {
 		try {
 			checkValidAndLock(true);
@@ -438,10 +451,8 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 		}
 	}
 
-	protected void parse(String content, Map outMap) throws Exception {
-		if (content == null)
-			return;	
-		BufferedReader reader = new BufferedReader(new StringReader(content));
+	protected void parse(String bbOutfilePath, Map outMap) throws Exception {
+		BufferedReader reader = new BufferedReader(new FileReader(bbOutfilePath + BB_ENV_FILE));
 		String line;
 		boolean inLine = false;
 		StringBuffer sb = null;
@@ -484,7 +495,7 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 			parseLine(line, outMap);
 		}
 	}
-	
+
 	private void parseAdditiveAssignment(String line, String operator, Map mo) throws Exception {
 		String[] elems = splitAssignment(line, "\\+=");
 
@@ -507,18 +518,18 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 	protected URI getDefaultDepends() {
 		return null;
 	}
-	
-	protected Map parseBBEnvironment(String bbOut) throws Exception {
+
+	protected Map parseBBEnvironment(String bbOutFilePath) throws Exception {
 		Map env = new Hashtable();
 		this.depends = new ArrayList<URI>();
 
-		parse(bbOut, env);
+		parse(bbOutFilePath, env);
 
 		String included = (String) env.get("BBINCLUDED");
 		if(getDefaultDepends() != null) {
 			this.depends.add(getDefaultDepends());
-		} 
-		
+		}
+
 		if(included != null) {
 			String[] includedSplitted = included.split(" ");
 			for (String incl : includedSplitted){
@@ -531,13 +542,13 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 
 		return env;
 	}
-	
+
 
 	private List parseBBFiles(String bbfiles) {
 		return Arrays.asList(bbfiles.split(" "));
 	}
-	
-	//Map delegate methods 
+
+	//Map delegate methods
 
 	private void parseConditionalAssignment(String line, Map mo) throws Exception {
 		String[] elems = splitAssignment(line, "\\?=");
@@ -611,14 +622,17 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 		return l;
 	}
 
+	@Override
 	public Object put(Object arg0, Object arg1) {
 		throw new RuntimeException("BB configuration is read-only.");
 	}
 
+	@Override
 	public void putAll(Map arg0) {
 		throw new RuntimeException("BB configuration is read-only.");
 	}
 
+	@Override
 	public Object remove(Object arg0) {
 		throw new RuntimeException("BB configuration is read-only.");
 	}
@@ -637,6 +651,7 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 		return line;
 	}
 
+	@Override
 	public int size() {
 		try {
 			checkValidAndLock(true);
@@ -686,7 +701,7 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 
 	/**
 	 * Return a string with variable substitutions in place.
-	 * 
+	 *
 	 * @param expression
 	 * @return Input string with any substitutions from this file.
 	 */
@@ -710,6 +725,7 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 		return expression;
 	}
 
+	@Override
 	public Collection values() {
 		try {
 			checkValidAndLock(true);
@@ -722,6 +738,7 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 		}
 	}
 
+	@Override
 	public void changeNotified(IResource[] added, IResource[] removed, IResource[] changed) {
 		wlock.lock();
 		try {
@@ -746,8 +763,8 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 			wlock.unlock();
 		}
 	}
-
 	public Map<String, String> getProperties() {
 		return (Map<String, String>) properties;
 	}
+
 }
plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java +2 -1
index 38e2557..6441029 100644
@@ -108,7 +108,8 @@ public class ShellSession {
 		try {
 			if (projectInfo.getConnection() != null) {
 				hasErrors = RemoteHelper.runCommandRemote(projectInfo.getConnection(), new YoctoCommand(command, root.getAbsolutePath() + "/build/", ""));
-				return RemoteHelper.getProcessBuffer(projectInfo.getConnection()).getMergedOutputLines();
+//				return RemoteHelper.getProcessBuffer(projectInfo.getConnection()).getMergedOutputLines();
+				return root.getAbsolutePath() + "/build/";
 			}
 			return null;
 		} catch (Exception e) {
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/RemoteHelper.java +1 -2
index e511e06..814e3a5 100644
@@ -272,7 +272,6 @@ public class RemoteHelper {
 					getHostShell(connection).writeToShell(fullRemoteCommand);
 					while (!adapter.isFinished())
 						Thread.sleep(2);
-//					return hostShellProcessAdapter.hasErrors();
 				} catch (Exception e) {
 					e.printStackTrace();
 				}
@@ -281,7 +280,7 @@ public class RemoteHelper {
 		return true;
 	}
 
-	public static void runBatchRemote(IHost connection, List<YoctoCommand> cmds, boolean waitForOutput) throws CoreException {
+	public static void runBatchRemote(IHost connection, List<YoctoCommand> cmds, boolean displayOutput) throws CoreException {
 		try {
 			String remoteCommand = "";
 			for (YoctoCommand cmd : cmds) {
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/RemoteMachine.java +0 -3
index a25eea4..76c8e8a 100644
@@ -123,9 +123,6 @@ public class RemoteMachine {
 	}
 
 	public IHost getConnection() {
-//		if (connection == null) {
-//			connection = RemoteHelper.getRemoteConnectionForURI(, new NullProgressMonitor());
-//		}
 		return connection;
 	}
 	public void setConnection(IHost connection) {
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/YoctoHostShellProcessAdapter.java +13 -3
index bb137b1..2072102 100644
@@ -138,9 +138,10 @@ public class YoctoHostShellProcessAdapter extends  HostShellProcessAdapter {
 				if (value.isEmpty()) {
 					continue;
 				}
-				System.out.println(value);
+//				System.out.println(value);
 				this.processStreamBuffer.addErrorLine(value);
-				this.commandResponseHandler.response(value, false);
+				if (this.commandResponseHandler != null)
+					this.commandResponseHandler.response(value, false);
 			}
 		} else {
 			for (IHostOutput line : lines) {
@@ -156,7 +157,8 @@ public class YoctoHostShellProcessAdapter extends  HostShellProcessAdapter {
 				reportProgress(value);
 				System.out.println(value);
 				this.processStreamBuffer.addOutputLine(value);
-				this.commandResponseHandler.response(value, false);
+				if (this.commandResponseHandler != null)
+					this.commandResponseHandler.response(value, false);
 			}
 		}
 
@@ -185,4 +187,12 @@ public class YoctoHostShellProcessAdapter extends  HostShellProcessAdapter {
 		return new NullProgressMonitor();
 	}
 
+	public CommandResponseHandler getCommandResponseHandler() {
+		return commandResponseHandler;
+	}
+
+	public void setCommandResponseHandler(CommandResponseHandler commandResponseHandler) {
+		this.commandResponseHandler = commandResponseHandler;
+	}
+
 }
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/OEFileSystem.java +0 -6
index 5efdcdc..4cb0921 100644
@@ -49,12 +49,6 @@ public class OEFileSystem extends FileSystem {
 		fileStoreCache = new Hashtable();
 	}
 
-//	public OEFileSystem(ProjectInfo pInfo) {
-//		ref = this;
-//		projInfo = pInfo;
-//		fileStoreCache = new Hashtable();
-//	}
-
 	@Override
 	public IFileStore getStore(URI uri) {
 
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java +30 -24

138 lines not on this page · raw message

plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java +30 -28

156 lines not on this page · raw message

plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java +40 -23

150 lines not on this page · raw message

plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java +8 -2
index ac33760..486bd8b 100644
@@ -29,6 +29,7 @@ import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
 import org.yocto.bc.remote.utils.RemoteHelper;
@@ -88,8 +89,13 @@ public class OptionsPage extends FiniteStateWizardPage {
 			@Override
 			public void reportError(String errorMessage, boolean infoOnly) {
 				setMessage(errorMessage);
-				validatePage();
-				updateModel();
+				if (validatePage()) {
+	                updateModel();
+	                setPageComplete(true);
+	                return;
+	            }
+
+	            setPageComplete(false);
 			}
 		};
 
Signature · 1 line
1.7.9.5