How to run the generator via command line?

Hello.

I'm new to MPS: just finished the 'calculator tutorial' and created a couple of simple languages for things I'm working with and I'm already full of enthusiasm:)

I'm interested if I can integrate some code generation within my build process. Is there any way to run the generator via command line?

Thanks,
Alexey
5 comments
Yes, you are quite right, you can run generation from an ant script. In MPS 2.0 location of the ant task changed, you can read the documentation for 2.0 version of the task here http://confluence.jetbrains.net/display/MPSD2/Generating+MPS+models+from+Ant

--
Regards,
Julia
0
Unfortunately, I'm still failed with running the ant script for generating. Here is my build file:
<project name="test" default="generate">
  <property name="mps.home" value="C:/Program Files/JetBrains/MPS-7347"/>
  <taskdef resource="jetbrains/mps/build/ant/antlib.xml" classpath="${mps.home}/languages/generate.ant.task.jar"/>
  <target name="generate">
    <mps.generate>
      <model file="D:/..../models/sandbox.mps"/>
    </mps.generate>
  </target>
</project>
prettyPrint();
My first attempt failed with message, that file <MPS home>/*platform*/generate.ant.task.jar does not exist or is not a directory or a jar file. It doesn't exist indeed, it's located in the 'language' folder (I'm using MPS 2.0 build 7347).
Then I've found that there was some bug, and downloaded the newer version of generate.ant.task.jar from here: http://confluence.jetbrains.net/download/attachments/39781994/generate.ant.task.jar (161653 bytes). Now generation seems to be started, but it failed with JavaHeapSpace. See the stack trace below..
D:\temp\test> ant
Buildfile: D:\temp\test\build.xml

generate:
[mps.generate] log4j:ERROR No output stream or file set for the appender named [null].
[mps.generate] java.lang.OutOfMemoryError: Java heap space
[mps.generate]  at java.util.Arrays.copyOf(Arrays.java:2786)
[mps.generate]  at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:94)
[mps.generate]  at java.util.zip.DeflaterOutputStream.deflate(DeflaterOutputStream.java:161)
[mps.generate]  at java.util.zip.DeflaterOutputStream.finish(DeflaterOutputStream.java:134)
[mps.generate]  at java.util.zip.DeflaterOutputStream.close(DeflaterOutputStream.java:146)
[mps.generate]  at com.intellij.util.io.storage.RefCountingStorage.writeBytes(RefCountingStorage.java:80)
[mps.generate]  at com.intellij.openapi.vfs.newvfs.persistent.FSRecords$BaseOutputStream.writeBytes(FSRecords.java:1186)
[mps.generate]  at com.intellij.openapi.vfs.newvfs.persistent.FSRecords.writeContent(FSRecords.java:1089)
[mps.generate]  at com.intellij.openapi.vfs.newvfs.persistent.PersistentFS.writeContent(PersistentFS.java:252)
[mps.generate]  at com.intellij.openapi.vfs.newvfs.persistent.PersistentFS.access$200(PersistentFS.java:51)
[mps.generate]  at com.intellij.openapi.vfs.newvfs.persistent.PersistentFS$2.close(PersistentFS.java:505)
[mps.generate]  at java.io.BufferedInputStream.close(BufferedInputStream.java:451)
[mps.generate]  at jetbrains.mps.reloading.JarFileClassPathItem.transformFile(JarFileClassPathItem.java:267)
[mps.generate]  at jetbrains.mps.reloading.JarFileClassPathItem.<init>(JarFileClassPathItem.java:53)
[mps.generate]  at jetbrains.mps.reloading.ClassPathFactory.get(ClassPathFactory.java:74)
[mps.generate]  at jetbrains.mps.reloading.ClassPathFactory.createFromPath(ClassPathFactory.java:41)
[mps.generate]  at jetbrains.mps.project.AbstractModule.getClassPathItem(AbstractModule.java:290)
[mps.generate]  at jetbrains.mps.project.AbstractModule$ModuleBytecodeLocator.find(AbstractModule.java:614)
[mps.generate]  at jetbrains.mps.runtime.BundleClassLoader.findClassBytes(BundleClassLoader.java:86)
[mps.generate]  at jetbrains.mps.runtime.BaseClassLoader.loadClass(BaseClassLoader.java:53)
[mps.generate]  at jetbrains.mps.runtime.BundleClassLoader.loadClass(BundleClassLoader.java:37)
[mps.generate]  at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
[mps.generate]  at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
[mps.generate]  at java.lang.Class.forName0(Native Method)
[mps.generate]  at java.lang.Class.forName(Class.java:247)
[mps.generate]  at jetbrains.mps.runtime.BundleClassLoader.getClass(BundleClassLoader.java:50)
[mps.generate]  at jetbrains.mps.reloading.ClassLoaderManager.getClassFor(ClassLoaderManager.java:81)
[mps.generate]  at jetbrains.mps.project.AbstractModule.getClass(AbstractModule.java:452)
[mps.generate]  at jetbrains.mps.smodel.language.LanguageRegistry.createRuntime(LanguageRegistry.java:180)
[mps.generate]  at jetbrains.mps.smodel.language.LanguageRegistry.reloadLanguages(LanguageRegistry.java:129)
[mps.generate]  at jetbrains.mps.smodel.language.LanguageRegistry$1.run(LanguageRegistry.java:113)
[mps.generate]  at jetbrains.mps.ide.smodel.WorkbenchModelAccess.runWriteAction(WorkbenchModelAccess.java:108)

BUILD FAILED
D:\temp\test\build.xml:5: java.lang.OutOfMemoryError: Java heap space

Total time: 1 minute 34 seconds
prettyPrint();

Any suggestions? I can extract the minimal model, that can reproduce the error...

Thanks,
Alexey
0
Alexey, you can increase heap space by using forkmode (setting fork=true in the task) and using jvmargs element to set maximum heap size. For example:
<target name="generate">
    <mps.generate fork="true">
        <jvmargs>
            <arg value="-Xmx512m"/>
        </jvmargs>
        <model file="D:/..../models/sandbox.mps"/>
    </mps.generate>
</target>
prettyPrint();

Even setting fork=true alone could resolve the problem, since if no jvmargs is set, generation task is started with default arguments which look like "-Xss1024k -Xmx512m -XX:MaxPermSize=92m -XX:+HeapDumpOnOutOfMemoryError".

--
Regards,
Julia
0
Thanks a lot! Forking with even default JVM arguments solved my problem!
0

Please sign in to leave a comment.