reimplemented initial support for referencing contiki source files in cooja projects

This commit is contained in:
fros4943 2010-11-10 13:11:43 +00:00
parent d6070a0c94
commit 3563089a91
4 changed files with 68 additions and 4 deletions

View file

@ -1,4 +1,4 @@
# $Id: Makefile.cooja,v 1.41 2010/06/11 15:17:26 fros4943 Exp $
# $Id: Makefile.cooja,v 1.42 2010/11/10 13:11:43 fros4943 Exp $
## The COOJA Simulator Contiki platform Makefile
##
@ -50,6 +50,9 @@ CONTIKI_APP_OBJ = $(CONTIKI_APP).co
COOJA = $(CONTIKI)/platform/$(TARGET)
CONTIKI_TARGET_DIRS = . dev lib sys cfs net
# (COOJA_SOURCEDIRS contains additional sources dirs set from simulator)
vpath %.c $(COOJA_SOURCEDIRS)
COOJA_BASE = simEnvChange.c cooja_mt.c cooja_mtarch.c rtimer-arch.c slip.c watchdog.c
COOJA_INTFS = beep.c button-sensor.c ip.c leds-arch.c moteid.c \

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: ContikiMoteType.java,v 1.43 2010/03/24 12:29:33 fros4943 Exp $
* $Id: ContikiMoteType.java,v 1.44 2010/11/10 13:11:43 fros4943 Exp $
*/
package se.sics.cooja.contikimote;
@ -295,6 +295,10 @@ public class ContikiMoteType implements MoteType {
libFile,
archiveFile,
javaClassName);
CompileContiki.redefineCOOJASources(
this,
env
);
} catch (Exception e) {
throw (MoteTypeCreationException) new MoteTypeCreationException(
"Error when creating environment: " + e.getMessage()).initCause(e);

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: CompileContiki.java,v 1.6 2010/03/15 11:04:07 fros4943 Exp $
* $Id: CompileContiki.java,v 1.7 2010/11/10 13:11:43 fros4943 Exp $
*/
package se.sics.cooja.dialogs;
@ -49,6 +49,7 @@ import javax.swing.Action;
import org.apache.log4j.Logger;
import se.sics.cooja.GUI;
import se.sics.cooja.MoteType;
import se.sics.cooja.MoteType.MoteTypeCreationException;
import se.sics.cooja.contikimote.ContikiMoteType;
@ -450,6 +451,7 @@ public class CompileContiki {
env.add(new String[] { "LIBNAME", identifier });
env.add(new String[] { "CLASSNAME", javaClass });
env.add(new String[] { "CONTIKI_APP", contikiAppNoExtension });
env.add(new String[] { "COOJA_SOURCEDIRS", "" });
env.add(new String[] { "COOJA_SOURCEFILES", "" });
env.add(new String[] { "CC", GUI.getExternalToolsSetting("PATH_C_COMPILER") });
env.add(new String[] { "EXTRA_CC_ARGS", ccFlags });
@ -463,4 +465,54 @@ public class CompileContiki {
env.add(new String[] { "PATH", System.getenv("PATH") });
return env.toArray(new String[0][0]);
}
public static void redefineCOOJASources(MoteType moteType, String[][] env) {
if (moteType == null || env == null) {
return;
}
/* Check whether cooja projects include additional sources */
String[] coojaSources = moteType.getConfig().getStringArrayValue(ContikiMoteType.class, "C_SOURCES");
if (coojaSources == null) {
return;
}
String sources = "";
String dirs = "";
for (String s: coojaSources) {
if (s.trim().isEmpty()) {
continue;
}
File p = moteType.getConfig().getUserProjectDefining(ContikiMoteType.class, "C_SOURCES", s);
if (p == null) {
logger.warn("Project defining C_SOURCES$" + s + " not found");
continue;
}
/* Redefine sources. TODO Move to createCompilationEnvironment. */
sources += s + " ";
dirs += p.getPath() + " ";
/* XXX Cygwin specific directory style */
if (dirs.contains("C:\\")) {
dirs += p.getPath().replace("C:\\", "/cygdrive/c/") + " ";
}
}
if (!sources.trim().isEmpty()) {
for (int i=0; i < env.length; i++) {
if (env[i][0].equals("COOJA_SOURCEFILES")) {
env[i][1] = sources;
break;
}
}
}
if (!dirs.trim().isEmpty()) {
for (int i=0; i < env.length; i++) {
if (env[i][0].equals("COOJA_SOURCEDIRS")) {
env[i][1] = dirs.replace("\\", "/");
break;
}
}
}
}
}

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: ContikiMoteCompileDialog.java,v 1.7 2010/03/15 11:04:07 fros4943 Exp $
* $Id: ContikiMoteCompileDialog.java,v 1.8 2010/11/10 13:11:43 fros4943 Exp $
*/
package se.sics.cooja.dialogs;
@ -167,6 +167,11 @@ public class ContikiMoteCompileDialog extends AbstractCompileDialog {
((ContikiMoteType)moteType).archiveFile,
((ContikiMoteType)moteType).javaClassName
);
CompileContiki.redefineCOOJASources(
moteType,
env
);
String[] envOneDimension = new String[env.length];
for (int i=0; i < env.length; i++) {
envOneDimension[i] = env[i][0] + "=" + env[i][1];