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.

Answers

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.

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?

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.

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.

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

 

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.

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.

Comments