Article
· Nov 2, 2023 3m read

How to hide the source program

InterSystems FAQ rubric

For routines (*.mac)

You can hide the source by exporting/importing only the *.obj that is generated after compiling the source program.

The command execution example specifies EX1Sample.obj and EX2Sample.obj, which are generated by compiling EX1Sample.mac and EX2Sample.mac, as export targets and exports them to the second argument file.

After moving to another namespace, I am using the exported XML file to perform the import.

USER>do $system.OBJ.Export("EX1Sample.obj,EX2Sample.obj","D:\routine.xml")       
Exporting to XML started on 10/23/2023 11:33:49
Exporting object code: EX1Sample.obj
Exporting object code: EX2Sample.obj
Export finished successfully.
 
USER>zn "USER2"  //change namespace
USER2>do $system.OBJ.Load("D:\routine.xml")
 
Load started on 10/23/2023 11:34:26
Loading file D:\routine.xml as xml
Imported object code: EX1Sample
Imported object code: EX2Sample
Load finished successfully.
 
USER2>

For classes (*.cls)

For classes, after exporting/importing *.cls in XML, execute MakeClassDeployed() on the server.

However, in relatively new versions, after executing MakeClassDeployed(), the source file (*.cls) is only set to deployment mode (it cannot be edited) and can only be viewed.

If you also want to make it invisible, set the Hidden property of the class after executing MakeClassDeployed() (set the property attribute Hidden=True).

An example of command execution is as follows.

USER>do $system.OBJ.Export("WH.Color.cls,WH.Size.cls","D:\test.xml")
 
Exporting to XML started on 10/23/2023 11:39:24
Exporting class: WH.Color
Exporting class: WH.Size
Export finished successfully.
 
USER>zn "USER2"
USER2>do $system.OBJ.Load("D:\test.xml","ck")
 
Load started on 10/23/2023 11:39:48
Loading file D:\test.xml as xml
Imported class: WH.Color
Imported class: WH.Size
Compiling 2 classes
Compiling class WH.Size
Compiling class WH.Color
Compiling table WH.Size
Compiling routine WH.Color.1
Compiling routine WH.Size.1
Load finished successfully.
 
USER2>do $system.OBJ.MakeClassDeployed("WH.Size")
 
USER2>

For CSP (*.csp)

For CSP files, copy *.csp and paste it into the destination CSP folder.

After compiling on the server, turn off automatic compilation in the CSP settings, then delete *.csp and execute MakeClassDeployed().

An example of execution is as follows.

1) After copying the CSP file, paste it to the server's CSP directory and compile it.

TEST>do $SYSTEM.CSP.LoadPageDir("/csp/test")

2) Set "Auto compile" to No in the web application path settings

[Version 2013.1 or later] [Administration Portal] > [System Management] > [Security] > [Applications] > [Web Applications] > Link of applicable application name

[Version 201.1 - Version 2012.2] [Management Portal] > [System Management] > [Security] > [Applications] > [Web Applications] > [Edit] of the applicable application name

[Version 2010.2 or earlier] [System Management Portal] > [System] > [Security Management] > [CSP Application] > [Edit] of the applicable application name

3) Execute MakeClassDeployed()

 *Example when copying cspsample.csp

TEST>do $system.OBJ.MakeClassDeployed("csp.cspsample")
Discussion (1)0
Log in or sign up to continue

Great article!

For cases, where you don't want to share the source at all (even if it's immediately deleted), the following approach would work:

1. On your system (with source code) execute:

set p=##class(%Studio.Project).%New()
do p.AddItem("WH.Color.cls")
do p.AddItem("WH.Size.cls")
do p.DeployToFile("c:\test\app.xml",,1)

It will create an XML export with object code only and no source code included.

2. Transfer the file into a target system and execute:

set sc=##class(%Studio.Project).InstallFromFile("c:\test\app.xml")