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: https://github.com/karol-depka/MPSBuildFacets .
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.) :
Could anyone please advise?
Below is the facet and target code.
Any help appreciated.
Best Wishes,
Karol Depka Pradzinski
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: https://github.com/karol-depka/MPSBuildFacets .
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.) :
Code
Dependencies: after configure before generate
Could anyone please advise?
Below is the facet and target code.
Code
facet BFacet4 extends <none> { Required: TextGen, Generate <no optional facets> Targets: target myTarget overrides <none> weight default { resources policy: transform (module, models) MResource -> <no output> Dependencies: 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"); file.getParentFile().mkdirs(); Writer w = new OutputStreamWriter(new FileOutputStream(file)); w.write("Mock root concept instance name: " + rootNodeM.name + "\n"); w.close(); } } } catch (Exception e) { throw new RuntimeException(e); } }); }); }); } } }
Any help appreciated.
Best Wishes,
Karol Depka Pradzinski
Please sign in to leave a comment.
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: