Is there a simple way to check if a given class need to be recompiled ?
A class (and routine) definition can sometimes differ from it's compiled state.
When such a thing occurs, a "+" sign will be shown in the tab of the file opened in Studio.
I would like to do the same check programmatically.
For routines, it's very simple :
set routine=##class(%Routine).%New(name)
write routine.UpToDateFor classes, I could not find the equivalent. The only solution I found so far is to compare the compilation date and definition date :
set classCompiled = ##class(%Dictionary.CompiledClass).%OpenId(name)
set classDefinition = ##class(%Dictionary.ClassDefinition).%OpenId(name)
write classDefinition.TimeChanged '= classCompiled.TimeCreatedIs there a better, cleaner way ?
The main issue is that there is no proof that this is what Studio does. It probably use some more complex logic. There is a few cases where I got a "+" and it's undetected (and the opposite).
EDIT:
Checking the status of the generated classes (.1.int files) helps a little bit :
set routine=""for
{
set timeStamp = classCompiled.Routines.GetNext(.routine)
quit:routine=""set routineTime = $get(^rOBJ(routine,"INT"))
write routineTime'=timeStamp
}Comments
For classes, see $System.OBJ.IsUpToDate()
For routines, see the UpToDate property in an instance of %Library.RoutineMgr
Examples:
Create a class DC.Demo.UpToDate and save/compile it. $System.OBJ.IsUpToDate("DC.Demo.UpToDate") returns 1. Add a method with /// documentation and save but don't compile - it returns 0. Change the /// documentation for the method and save (don't compile) - $System.OBJ.IsUpToDate("DC.Demo.UpToDate") returns 0, but $System.OBJ.IsUpToDate("DC.Demo.UpToDate",0,1) returns 1.
Create a routine named DC.Demo.UpToDate, save and compile. This returns 1:
##class(%Library.RoutineMgr).%OpenId("DC.Demo.UpToDate.MAC").UpToDate
Save and don't compile. This returns 0:
##class(%Library.RoutineMgr).%OpenId("DC.Demo.UpToDate.MAC").UpToDate
Thanks. I tried it and it works great most the time. However, I got a few cases where the IsUpToDate() returns 0 while the class does not show any "+" sign in Studio. I tried different values for "type" parameter but it does not help.
The error reported is as such :
ERROR: ^oddCOM(cls,timechanged) does not exist
I checked and indeed there is no TimeChanged or TimeCreated in the class compiled global. Seems Studio is happy with that.
@Norman W. Freeman
If you upgrade to version 2023.3 or newer, you can use ##class(%RoutineMgr).OutOfDateDocuments() to check all documents in a namespace. You can use the various arguments to filter the documents that are checked (for example, to only check classes).