MPS custom Build Facets problem - generated files appear only every second rebuild.

Hello Fellow Metaprogrammers :).

I've written a custom generator that takes root concept instances and generates text files for them (bypassing traditional
generator and TextGen which turned out to be problematic for my purposes).
It works reasonably well, except for the fact that the generated files disappear exactly every second RE-build. Weird.
It means, that for every change in the build facet, I have to rebuild twice to get the output files, which slows down the development a lot.

Below is a very simplified version of my generator's facet, which I built from scratch to demonstrate the problem.
Whole project contents to be found here: .

I'm suspecting that the problem may be in that part (for example a collision with some other target, that may be trying to clean files, etc.) :

         after configure
         before generate

Could anyone please advise?

Below is the facet and target code.

facet BFacet4 extends <none> {
  Required: TextGen, Generate

  <no optional facets>
    target myTarget overrides <none> weight default {
      resources policy: transform (module, models) MResource -> <no output>
         after configure
         before generate

        <no properties>
        <no queries>
        <no config>

        (progressMonitor, input)->void {

          input.forEach({~inpt =>
            begin work myTarget covering ALL units of total work left, expecting input.size units;

            inpt.models().forEach({~curModel =>
              ModelAccess.instance().runReadAction({ =>
 try {
   string outputPath = SModuleOperations.getOutputPathFor(curModel);
   foreach rootNode in curModel.getRootNodes() {
     ifInstanceOf (rootNode is RootConceptMock rootNodeM) {
       string modelPath = rootNode.getModel().getModelName().replace(".", "/");
       string fileDir = outputPath + "/" + modelPath;
       File file = new File(fileDir + "/" + rootNode.getName() + "." + "cxx");
       Writer w = new OutputStreamWriter(new FileOutputStream(file));
       w.write("Mock root concept instance name: " + + "\n");
 } catch (Exception e) {
   throw new RuntimeException(e);

Any help appreciated.

Best Wishes,
Karol Depka Pradzinski
It's a pity you had to write your custom solution, would you care to tell us what functionality you miss in the generator+texgen pair?

As to your problem, it's actually quite normal that you're seeing files deleted after being generated. It's the standard behaviour of Make, which takes care of cleaning the output folder from the "unknown" files.

The textgen not only writes the files, but also reports which files exactly were written and/or "touched" in the form of "deltas". You may want to see the TextGen make facet, as well as "reconcile" target of Make.

In short, your facet should have the code similar to:

FilesDelta delta = new FilesDelta(outputDir);


delta.written(<written file>); // for each written file; notice the use of IFile here


output (delta = delta, module = ..., modelDescriptor = ...); // the "TResource" tuple


Please sign in to leave a comment.