Commit d55c78ac authored by Florian Hölzl's avatar Florian Hölzl
Browse files

added gcc tool chain runners

refs 727
parent e2e4877a
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.tools.base;
import static org.eclipse.core.runtime.Assert.isNotNull;
import static org.eclipse.core.runtime.Assert.isTrue;
import java.io.File;
import java.io.IOException;
import org.fortiss.tooling.kernel.model.INamedElement;
/**
* Base implementation of {@link ToolRunnerBase} without intermediate generation capability.
* Instead of generating the input file(s) for the external tool this runner uses an existing file
* (or folder) as its source.
*
* @param <T>
* the result type
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public abstract class SimpleToolRunnerBase<T> extends ToolRunnerBase<INamedElement, T> {
/** The file or location used by this tool runner. */
private final File physicalFile;
/** Constructor. */
public SimpleToolRunnerBase(File physicalFileOrLocation) {
isNotNull(physicalFileOrLocation);
isTrue(physicalFileOrLocation.exists());
this.physicalFile = physicalFileOrLocation;
}
/** Constructor. */
public SimpleToolRunnerBase() {
this.physicalFile = null;
}
/** {@inheritDoc} */
@Override
protected final File generatePhysicalFile(ITextGenerator<INamedElement> textGen,
String fileExtension) {
return physicalFile;
}
/** A lazy result of GCC. */
protected class SimpleLazyResult extends LazyResultBase {
/** Constructor. */
public SimpleLazyResult(File physicalFile) {
super(new SimpleToolRunningTask(physicalFile));
}
}
/** A simple tool runner task. */
private class SimpleToolRunningTask extends ToolRunningTask {
/** Constructor. */
SimpleToolRunningTask(File physicalFile) {
super(physicalFile, getResultBuilder(), getCommandList());
}
/** {@inheritDoc} */
@Override
protected T doProcessRunResults(StreamReader errorStreamReader,
StreamReader inputStreamReader) throws IOException, Exception {
return resultBuilder.buildResult(inputStreamReader.getReadLines());
}
}
/** The result builder for this tool runner. */
public abstract IResultBuilder<T> getResultBuilder();
/** The command list for this tool runner. */
public abstract String[] getCommandList();
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.tools.gcc;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.info;
import java.io.File;
import java.util.List;
import org.fortiss.af3.tools.ToolsActivator;
import org.fortiss.af3.tools.base.IResultBuilder;
/**
* Builder for GCC result, i.e., an object file location.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 194E8C06948F411A6EB17165BBC17CCF
*/
public class GCCResultBuilder implements IResultBuilder<File> {
/** {@inheritDoc} */
@Override
public File buildResult(List<String> lines) {
info(ToolsActivator.getDefault(), "Parsing GCC results!");
// FIXME: implement
return null;
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.tools.gcc;
import java.io.File;
import org.fortiss.af3.tools.base.ILazyResult;
import org.fortiss.af3.tools.base.IResultBuilder;
/**
* Tool runner class for running GCC.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class GCCRunner extends GCCToolChainRunnerBase {
/** Constructor. */
public GCCRunner(File sourceFile) {
super(sourceFile);
}
/** Constructor. */
public GCCRunner() {
super();
}
/** {@inheritDoc} */
@Override
public ILazyResult<File> runTool() throws Exception {
return null;
}
/** {@inheritDoc} */
@Override
protected String getToolCommand() {
return "gcc";
}
/** {@inheritDoc} */
@Override
public IResultBuilder<File> getResultBuilder() {
return new GCCResultBuilder();
}
/** {@inheritDoc} */
@Override
public String[] getCommandList() {
// FIXME: -v
return new String[] {"-v"};
}
/** {@inheritDoc} */
@Override
protected String getVersionInfo(String helpMessage) {
int startOfVersioningInfo = helpMessage.indexOf("gcc version ");
return helpMessage.substring(startOfVersioningInfo + 12, startOfVersioningInfo + 17);
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.tools.gcc;
import java.io.File;
import org.conqat.lib.commons.collections.Pair;
import org.fortiss.af3.tools.base.SimpleToolRunnerBase;
/**
* Base class for runners of GCC tool chain tools (configure, make, gcc, ld).
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public abstract class GCCToolChainRunnerBase extends SimpleToolRunnerBase<File> {
/** Constructor. */
public GCCToolChainRunnerBase(File physicalFileOrLocation) {
super(physicalFileOrLocation);
}
/** Constructor. */
public GCCToolChainRunnerBase() {
super();
}
/** {@inheritDoc} */
@Override
public String testToolAvailability() {
String toolCmd = "which " + getToolCommand() + " && " + getToolCommand();
Pair<String, String> outputs = smokeToolRun(toolCmd, "-v");
if(outputs != null && outputs.getSecond().length() > 0) {
String helpMessage = outputs.getSecond();
String whichOutput = "/" + getToolCommand() + "\n";
int endOfWhichLocation = helpMessage.indexOf(whichOutput) + whichOutput.length();
String whichLocation = helpMessage.substring(0, endOfWhichLocation - 1);
return whichLocation + " " + getVersionInfo(helpMessage);
}
return null;
}
/** Returns the version info contained in the given help message. The default */
protected abstract String getVersionInfo(String helpMessage);
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.tools.gcc;
import java.io.File;
import org.fortiss.af3.tools.base.ILazyResult;
import org.fortiss.af3.tools.base.IResultBuilder;
/**
* Tool runner class for running Make.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class MakeRunner extends GCCToolChainRunnerBase {
/** Constructor. */
public MakeRunner(File sourceFile) {
super(sourceFile);
}
/** Constructor. */
public MakeRunner() {
super();
}
/** {@inheritDoc} */
@Override
public ILazyResult<File> runTool() throws Exception {
return null;
}
/** {@inheritDoc} */
@Override
protected String getToolCommand() {
return "make";
}
/** {@inheritDoc} */
@Override
public IResultBuilder<File> getResultBuilder() {
// FIXME: not gcc
return new GCCResultBuilder();
}
/** {@inheritDoc} */
@Override
public String[] getCommandList() {
// FIXME: -v
return new String[] {"-v"};
}
/** {@inheritDoc} */
@Override
protected String getVersionInfo(String helpMessage) {
int startOfVersioningInfo = helpMessage.indexOf("GNU Make ");
return helpMessage.substring(startOfVersioningInfo + 9, startOfVersioningInfo + 4);
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.tools.gcc;
import java.io.File;
import org.fortiss.af3.tools.base.ILazyResult;
import org.fortiss.af3.tools.base.IResultBuilder;
/**
* Tool runner class for running Shell scripts (e.g the configure script).
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class ShellRunner extends GCCToolChainRunnerBase {
/** Constructor. */
public ShellRunner(File sourceFile) {
super(sourceFile);
}
/** Constructor. */
public ShellRunner() {
super();
}
/** {@inheritDoc} */
@Override
public ILazyResult<File> runTool() throws Exception {
return null;
}
/** {@inheritDoc} */
@Override
protected String getToolCommand() {
return "sh";
}
/** {@inheritDoc} */
@Override
public IResultBuilder<File> getResultBuilder() {
// FIXME: not gcc
return new GCCResultBuilder();
}
/** {@inheritDoc} */
@Override
public String[] getCommandList() {
// FIXME: -version
return new String[] {"-version"};
}
/** {@inheritDoc} */
@Override
protected String getVersionInfo(String helpMessage) {
int startOfVersioningInfo = helpMessage.indexOf("version ");
return helpMessage.substring(startOfVersioningInfo + 8, startOfVersioningInfo + 6);
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package test.org.fortiss.af3.tools.gcc;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.fortiss.af3.tools.gcc.GCCRunner;
import org.fortiss.af3.tools.gcc.MakeRunner;
import org.fortiss.af3.tools.gcc.ShellRunner;
import org.junit.Test;
/**
* Smoke test case for GCC tool chain.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class SmokeTest {
/** Test GCC availability. */
@Test
public void gccAvailabilityTest() {
GCCRunner runner = new GCCRunner();
String result = runner.testToolAvailability();
assertNotNull(result);
assertTrue(result.startsWith("4.")); // 4th generation GCC
}
/** Test Make availability. */
@Test
public void makeAvailabilityTest() {
MakeRunner runner = new MakeRunner();
String result = runner.testToolAvailability();
assertNotNull(result);
assertTrue(result.startsWith("3.")); // 3rd generation Make
}
/** Test Shell availability. */
@Test
public void shellAvailabilityTest() {
ShellRunner runner = new ShellRunner();
String result = runner.testToolAvailability();
assertNotNull(result);
// 3rd or 4th generation shell
assertTrue(result.startsWith("3.") || result.startsWith("4."));
}
}
<!--
$Id$
@version $Rev$
@ConQAT.Rating GREEN Hash: 7FC4C81CE9623AC885FBCCCC2111284A
-->
<body>
Base package for tests of GCC-based tool chain in AF3.
These tests include typical GCC-like call-chain consisting of
<OL>
<LI>"./configure" script</LI>
<LI>"make all" script (which calls gcc compiler and ld linker)</LI>
<LI>"LocalMachine.run" executable (i.e. the result of the build)</LI>
<OL>
</body>
Supports Markdown
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