Skip to content

Commit

Permalink
Initial support for distribution run time from IDE
Browse files Browse the repository at this point in the history
  • Loading branch information
miranha committed Sep 18, 2017
1 parent cd7978e commit 3dada75
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
Expand Up @@ -19,6 +19,70 @@ public class CGenUtil {
* @param jarfile The vdmclib JAR file that contains the native library sources
* @param outfolder The output folder
*/
public static void copyDistributionLibFiles(InputStream jarfile, File outfolder)
{
if (!outfolder.exists())
{
outfolder.mkdir();
}

try
{
JarInputStream jarstream = new JarInputStream(jarfile);
JarEntry filejarentry = jarstream.getNextJarEntry();

// Simply step through the JAR containing the library files and extract only the code files.
// These are copied to the source output folder.
while (filejarentry != null)
{
if(!filejarentry.getName().contains("src/main") ||
filejarentry.getName().contains("META") || filejarentry.isDirectory())
{
filejarentry = jarstream.getNextJarEntry();
continue;
}

File outputFile = new File(outfolder.toString()
+ File.separator
+ filejarentry.getName().replace("src/main/", ""));

if (filejarentry.getName().contains("ProjectCMakeLists") ||
filejarentry.getName().contains("main.c") ||
filejarentry.getName().contains("README"))
{
outputFile = new File(outputFile.getAbsolutePath().replace("distributionLib"
+ File.separator, ""));
}

if(outputFile.getParentFile() != null)
{
outputFile.getParentFile().mkdirs();
}

FileOutputStream fos = new java.io.FileOutputStream(outputFile);

while (jarstream.available() > 0)
{
int b = jarstream.read();
if (b >= 0)
{
fos.write(b);
}
}
fos.flush();
fos.close();
jarstream.closeEntry();
filejarentry = jarstream.getNextJarEntry();

}
jarstream.close();
jarfile.close();
} catch (IOException e)
{
e.printStackTrace();
}
}

public static void copyNativeLibFiles(InputStream jarfile, File outfolder)
{
if (!outfolder.exists())
Expand Down
Expand Up @@ -85,13 +85,13 @@ public void generate(File cCodeOutputFolder) throws CoreException,
// If distribution, these maps exist
for(String cpu : SystemArchitectureAnalysis.distributionMapStr.keySet()){

// Copy the distribution run-time
CGenUtil.copyNativeLibFiles(Vdm2CCommand.class.getClassLoader().getResourceAsStream("jars/distributionLib.jar"),
new File(cCodeOutputFolder + File.separator + cpu /* + File.separator + "distributionLib"*/));

// Copy files from vdmclib.jar.
CGenUtil.copyNativeLibFiles(Vdm2CCommand.class.getClassLoader().getResourceAsStream("jars/vdmclib.jar"),
new File(cCodeOutputFolder + File.separator + cpu + File.separator + "nativelib"));

// Copy the distribution run-time
CGenUtil.copyDistributionLibFiles(Vdm2CCommand.class.getClassLoader().getResourceAsStream("jars/distributionLib.jar"),
new File(cCodeOutputFolder + File.separator + cpu + File.separator + "distributionLib"));

//Emit empty main.c file so that the generated project compiles.
//emitMainFile(new File(cCodeOutputFolder + File.separator + cpu + File.separator + "main.c"), vdm2c.getHeaders());
Expand Down

0 comments on commit 3dada75

Please sign in to comment.