Question Maarten Van den Vreken · Jul 18, 2017

Trigger a class compilation

Hi all,

I was wondering if there is any way to trigger the compilation of a class based on the compilation of another (unrelated) class. For example:

Class 1 = test.class

Class 2 = test.class.type.one

Class 3 = test.class.type.two

Every time class 2 or class 3 is compiled in Studio I would like to have class 1 automatically compiled as well.

The reason I need this is because class 1 has a method with CodeMode set to objectgenerator which generates some code based on what is found in classes 2 and 3.

Comments

Maarten Van den Vreken  Jul 18, 2017 to Eduard Lebedyuk

Thanks. This worked perfectly. Is there any list available with methods like this one? The Caché documentation does not contain any results for a search on OnCompile and even looking in the source code it's only used once in %SOAP.WebBase. How do you even know this exists?

0
Maarten Van den Vreken  Jul 18, 2017 to Lexi Hayden

It looks like this only checks if the dependant class exists and is properly compiled, but does not actually trigger a recompile of that class.

0
Daniel Kutac · Jul 18, 2017

Use your own custom Projection, put it into your primary class, it runs every time you compile your primary class, in the code you can do whatever you want, e.g. compile other classes.

0
Eduard Lebedyuk  Jul 19, 2017 to Maarten Van den Vreken

The name is not important. This method is an method generator, so it runs during compilation. But as it produces no code, the method does not get generated.

0
Eduard Lebedyuk · Jul 18, 2017

You can use method generators:

ClassMethod OnCompile() [ CodeMode = objectgenerator ]
{
    do $system.OBJ.Compile("class")
    quit $$$OK
}

If method generator produces no code, then it would not be created, only ran at compile time.

0
Lexi Hayden · Jul 18, 2017

I believe the preferred option is the DependsOn class keyword.  We use this often in DeepSee, because whenever you recompile the base class on which you base your cube, you should also recompile the cube class. So the cube class  looks like this, for example:

Class DeepSee.Model.PatientsCube Extends %DeepSee.CubeDefinition [ DependsOn = DeepSee.Study.Patient ]

See http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=ROBJ_class_dependson

0
Lexi Hayden · Jul 18, 2017

True. But also, if you recompile a set of classes (e.g., by compiling a package), then we look through for dependencies like this and make sure to compile the independent class before the dependent one.

0