How to compile generated code


I have written a simple DSL that generates TeX documents which I want to get compiled during the build process.

What's the general approach here? I have already created a make facet but am unable to determine the name of the generated TeX file.

Comment actions Permalink
Hi Christian,

the name of the generated file is specified in TextGen for your root concept, if that is what you are struggling with.
In the make facet you can get access to the file names through "TextGenOutcomeResource". Here's an example of a make facet accessing the generated files:

optional target copyFiles overrides <none> weight default { 
  resources policy: transform TextGenOutcomeResource -> <no output>            
     after textGen    
     before reconcile 
   <no properties>    
   <no queries>       
   <no config>        
   (progressMonitor, input)->void { 
  final FileProcessor fp = new FileProcessor(); 
  list<FilesDelta> deltas = new arraylist<FilesDelta>; 
  begin work Build language ANT files covering ALL units of total work left, expecting input.size + 2 units; 
  foreach res in input { 
    advance 1 units of Build language ANT files with comment res.getModel().getModelName(); 
    TextGenResult textGenResult = res.getTextGenResult(); 
    for (TextUnit tu : textGenResult.getUnits()) { 
      string targetXml = CopyFacetUtil.getTargetPath(tu.getStartNode()); 
      if (targetXml != null) { 
        string fileName = tu.getFileName(); 
        if (!fileName.endsWith(".xml")) { 
          string ext = Utils.getExtensionWithDot(fileName); 
          if (ext.isEmpty) { 
            // do not copy 
            report warning "Ignored " + fileName; 
          targetXml = Utils.withoutExtension(targetXml) + ext; 
        report info String.format("copy generated script: %s --> %s", fileName, targetXml); 
        IFile destFile = FileSystem.getInstance().getFileByPath(targetXml); 
        boolean changed = fp.saveContent(destFile, tu.getBytes()); 
        FilesDelta d = new FilesDelta(destFile.getParent()); 
        if (changed) { 
        } else { 
  if (deltas.isNotEmpty) { 
    IDelta folded = deltas.ofType<IDelta>.reduceLeft({~a,~b => a.merge(b); }); 
    output (delta = new singleton<IDelta>(folded)); 
  advance 1 units of Build language ANT files with comment "writing..."; 
  FileSystem.getInstance().runWriteTransaction(new Runnable() { 
    public void run() { 
  finish Build language ANT files; 

Comment actions Permalink

Hi, Vaclav!

Thanks for you reply. Is there any documentation regarding the various available resources? I haven't found any for TextGenOutcomeResource.



Please sign in to leave a comment.