How to compile generated code

Hello!

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.

Christian
3 comments
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>            
}
   Dependencies:      
     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; 
            continue; 
          } 
          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) { 
          d.written(destFile); 
        } else { 
          d.kept(destFile); 
        } 
        deltas.add(d); 
      } 
    } 
  } 
   
  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() { 
    @Override 
    public void run() { 
      fp.flushChanges(); 
    } 
  }); 
   
  finish Build language ANT files; 
}   
prettyPrint();

Vaclav
0

Hi, Vaclav!

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

Christian

0

Please sign in to leave a comment.