- Objectives
- PowerBuilder Deployment Through the Years
- Application Deployment with PowerBuilder 9
- Command-Line Deployment with OrcaScript
- Delivering the Completed Application to End Users
- Additional Tips and Tricks
- Conclusion
Application Deployment with PowerBuilder 9
There comes a point in the lifecycle of every software application in which the developer feels confident enough in the quality of the code to "release" the application for others to use. These users might be a Quality Assurance group or a Beta tester, or they might be the eventual end users. PowerBuilder developers must choose between several alternatives before the deployment process can be started. This section examines those alternatives and discusses the various factors that affect the deployment process for PowerBuilder applications.
Compiler Basics
PowerBuilder offers two different compiler formats for PB applications: interpreted Pcode (pseudocode) and machine code. There are distinct advantages and disadvantages to each format, as shown in Table 3.1.
Table 3.1 Comparison of Pcode and Machine Code Compilation
|
Advantages |
Disadvantages |
Pcode |
Smaller file size than DLLs |
Slower performance for PowerScript- intensive operations |
|
Faster compile times |
|
|
Portable to all supported PB platforms |
|
Machine Code |
Faster execution for computation-intensive operations |
Larger file sizes |
|
|
Slower compile times |
|
|
Not portable to other execution platforms |
Basically, if your primary goal is to optimize speed of execution for computation-intensive script operations, choose machine code. It will offer better performance for operations such as floating point arithmetic and looping constructs. This improved performance will come at the expense of the speed of the compile process, and the overall size of the distributed application files will increase.
For nearly all other applications, Pcode compiles should provide adequate performance, with faster compile times and smaller application file sizes. In addition, Pcode can be run on any platform that is supported by PowerBuilder's Virtual Machine (PBVM), whereas machine code applications can only run on the same platform on which they were compiled.
The Application Package
All PowerBuilder applications consist of at least one of the following items:
The executable file
Dynamic libraries
External resources
For client/server applications, there will always be an executable file. This file, at a minimum, contains code that enables the application to start and initiate processing. The packaging model that was chosen at compile time determines the additional content of the EXE file. The EXE file can contain one or more of the following:
-
Compiled versions of the objects from the application's libraries
-
An execution library list
-
External resources
This is the default packaging model, in which all the objects are compiled directly into one large EXE file. This increases the overall size of the EXE file, but greatly simplifies the deployment task because there's only one application file to deploy.
PowerBuilder provides the option to compile PBLs into dynamically linked libraries (either Pcode PBDs or machine code DLLs). This packaging model offers several benefits, which are covered in the next section.
Bitmaps, icons, cursors, and other image files can be compiled directly into the application's EXE or dynamic libraries, or delivered as separate files to be resolved at runtime.
Using Dynamic Runtime Libraries
Compiling PowerBuilder applications to dynamic runtime libraries instead of a single large EXE file offers several important benefits, and it's important to understand the differences between these two deployment options:
-
Increased Modularity
-
Improved Reusability
-
Reduced Complexity
The application is broken up into smaller, more logically organized files rather than a single large EXE file. These dynamic libraries will carry the same name as their corresponding PBL, but will have either a .pbd (Pcode) or .dll (machine code) file extension.
It is possible for several PowerBuilder applications to share the same set of dynamic libraries. For example, a library of common report datawindows can be compiled to a single dynamic library and shared across separate applications. However, it should be noted that sharing of dynamic libraries might result in application instability. An example of this would be a PFC-based application that implements a corporate, or "PFD," set of libraries between the PFC and PFE libraries. This application could not share its PFC and PFE dynamic libraries with a second PFC-based application that did not use the same PFD layer. To ensure the overall stability of the suite in such an arrangement, each application should have its own set of dynamic libraries.
When compiling an application into a single EXE file, PB will scan the PBL files and only copy in the objects that are specifically referenced by that application. The goal of that step is to reduce the overall size of the deployed EXE file. Consequently, objects that are only referenced dynamically will not be included in the deployed application. Typical examples of dynamic references would be
dw_1.dataobject = "d_customer"
-
or
CREATE n_base USING "n_cst_customer"
In these examples, the datawindow "d_customer" and the nonvisual object "n_cst_customer" are referenced only as text strings in PowerScript and would not be automatically compiled into a deployed EXE file. However, there are techniques to work around this limitation. The compiler will find any dynamically referenced datawindow objects whose names have been listed in a PowerBuilder Resource File (PBR). PBR files are covered in more detail in the next section. However, no such facility exists for other object classes, such as the nonvisual object "n_cst_customer" listed previously. One technique is to create a "dummy" nonvisual object that has local variable declarations for all the dynamically referenced classes.
This complexity is eliminated completely simply by using dynamic libraries. PB copies all the objects in a PBL into its corresponding PBD or DLL at compile time, so all object classes, even those that are referenced dynamically, are resolvable at runtime.
Using External Resources
In addition to PowerBuilder objects such as windows, menus, and user objects, applications can also use external resources, such as image files, bitmaps, icons, and so on. When these resources are used in an application, they must be delivered along with the PowerBuilder objects. There are several different approaches for the delivery of these external resources as well:
-
Include them in the executable file.
For objects that are compiled into the executable file (as opposed to dynamic libraries), PowerBuilder will automatically scan these objects looking for specific resource file references, usually found in the object's properties panel. These files will be compiled directly into the EXE file. Dynamically referenced resources and datawindows will not be detected during this scan. To build these resources into the executable file, you must create a PowerBuilder Resource (.PBR) file. This is an ASCII text file that tells the PB compiler where to find the resources that are used by the application. Listing 3.1 shows a few lines from a sample PBR file.
Listing 3.1 Sample PBR File Listing
peat.pbl(d_project) iopen.bmp peat.bmp c:\myapp\peat.pbl(d_dddw_project) .\icons\deviate.ico
Resource file references in a PBR file can be qualified with either full or relative references, or unqualified. The first line of Listing 3.1 shows an unqualified datawindow reference, and the second and third lines show unqualified bitmap file references. For these to be successfully copied into the executable, they must exist in the current directory when the compile is performed. The fourth line shows a fully qualified datawindow reference. The fifth line shows another technique, using relative path references. In this case, the .ICO file must exist in a folder named \icons that exists below the current directory. Relative path references are less restrictive than fully qualified pathnames and still allow for references to resources outside of the current directory.
It is important to note that the path and file naming convention used in the PBR file must exactly match the reference in the script. PB will not find the resource at runtime if the references are not exactly equal. For example, the peat.bmp file referenced in Listing 3.1 will not be found at runtime if the file is referenced in PowerScript as "c:\myapp\peat.bmp".
Include them in dynamic libraries.
If the application is packaged into dynamic libraries (either PBDs or DLLs), PowerBuilder can compile the resource files into the corresponding dynamic libraries. However, the "automatic scan" that happens for objects compiled into the EXE doesn't happen, even for explicitly referenced resources. Therefore, it's necessary to build a PBR file when deploying PBDs or DLLs with external resource references. It is not, however, required to place datawindow references into the PBR file when compiling to dynamic libraries because all the objects in the PBL are copied into the corresponding PBD or DLL file.
Deliver them as separate files.
A final option is to deliver the resource files along with the compiled application code. This increases the number of files that need to be delivered, but can be beneficial when a resource file needs to be updated. If the resource is compiled into the EXE or PBD/DLL, it would be necessary to recompile and redeploy the application. If the resource files are delivered separately, it's possible to swap in a new image file without recompiling.
It's important to note that this is the least efficient model at execution time because the PB application must search the file system for the requested resource file.
The Project Painter
The Project object encapsulates all the information required to regenerate and compile a PowerBuilder target. Project objects are maintained in the Project painter. This painter received a facelift in version 8 and is unchanged in version 9.
Open a new project by selecting File, New from any menu, and then navigating to the Project tab. If there are multiple Targets in the current Workspace, they will be shown in the Target drop-down list at the bottom of the dialog box. Select the correct Target, select the Application icon, and then click OK to open the Project painter. For a step-by-step approach to constructing the Project, select the Application Wizard icon. That presents each section of the Project painter screen in a wizard-based dialog box. Figure 3.1 shows a typical Project object in the PB 9 Project painter.
Figure 3.1 Project Painter.The following list describes the various options and choices available in the Project painter screen, shown in Figure 3.1:
Executable Filename: This is the name of the EXE file that will be created. If a pathname is specified (either fully qualified or relative), the EXE file will be created in that folder. If no path is specified, the EXE file will be created in the folder that contains the PBL with the Project object.
Resource Filename: This is the name of the PBR file that helps to resolve external resources, such as bitmaps, icons, and cursors. The proper use of PBR files will be discussed in the next section.
The following are the Project Build options:
Prompt for Overwrite: When this setting is on, the user will be prompted to overwrite the EXE and PBD files as they are being written.
Rebuild: This option offers the choice between an incremental or full rebuild during the regeneration stage of the compile. An incremental rebuild is designed to only regenerate objects that have been changed since they were last regenerated, including ancestor and descendent classes, as well as all objects referenced by those that have changed. This option can result in quicker regeneration times, but can be less reliable than a full rebuild, which regenerates all objects in the entire Target. It is recommended to always perform a full rebuild prior to releasing an application for QA testing or deploying to an end user.
The following are the Code Generation options:
Machine Code: Select this option to compile to machine code DLLs instead of Pcode PBDs.
Trace Information: For machine code compilation only. When selected, it will add debugging information into the DLLs that allow the /PBDEBUG switch to create the .DBG files for the application. This capability is built-in for PBDs, so the option is not applicable.
Error Context Information: For machine code compilation only. Check this on to display context information (such as object, event, and script line number) for runtime errors.
Optimization: For machine code compilation only. If this option is selected, PowerBuilder will apply optimizations to reduce the size of the DLL files or to increase their execution speed.
Library: This section lists each PBL found in the target's library list. Each PBL in the list will have the following two options available.
PBD/DLL: Select this option to deploy the specified PBL as either a Pcode PBD or a machine code DLL. If this option is not selected, the objects in the specified library will be compiled directly into the EXE file.
Resource Filename: Use this entry to reference a specific PBR resource file for the selected library. If a .PBR file is specified here, the external resources that are referenced will be compiled into the corresponding dynamic library.
NOTE
When compiling to machine code, the label of the PBD/DLL option will read "DLL."
In prior releases, someone examining the File Properties for a compiled PowerBuilder application would only see "Sybase Corporation." It is now possible to stamp the compiled executable file with customized information. The settings made in this section will appear in the File Properties of the compiled executable, as shown in Figure 3.2.
Figure 3.2 The File Properties dialog box.The first four attributes are self-explanatory, and they appear in the File Properties dialog box with the same attribute name. Compare the dialog box shown in Figure 3.2 with the Project object shown in Figure 3.1.
Company Name
Product Name
Description
Copyright
The next two attributes have two separate fields, and their entries appear in different places in the File Properties dialog box. The two smaller fields on the left are a series of four comma-separated numbers, and they could be used to store the Major/Minor/Incremental/Build numbers of the application. The larger fields on the right are simple text values:
Product Version (left side): This number does not appear in the File Properties dialog box, but it can be seen in a tool such as Visual C++ by opening the EXE file as a resource. An installation tool, such as Microsoft's Windows Installer, can use this value to decide whether to overwrite the file during a patch process. Prior to PB 9, the only version information available in the EXE file itself referred to the version of PowerBuilder that was used to perform the compile.
Product Version (right side): This value appears in the Product Version file property.
File Version (left side): This value can be seen as the File Version property, found at the top of the File Properties dialog box. It is also seen in the ToolTip for the EXE file.
File Version (right side): This value also appears as the File Version property, but this is the one in the list at the bottom of the File Properties dialog box.
Target-level Deployment
Once a Target contains a Project object, it becomes possible to use the "Deploy" operation on that Target. This option appears in the System Tree context menu for the Target, and in the Entry, Target menu in the Library Painter.
The Target properties dialog box contains a tab labeled Deploy (see Figure 3.3). This tab lists all the Project objects that are found in the Target. If more than one Project exists for the Target, use this tab page to specify which Projects are to be built and in which order.
Figure 3.3 The Target Properties/Deploy dialog box.If the Target is registered to Source Control, it will first be necessary to perform a checkout on the Target before its properties can be altered.
Workspace-level Deployment
When the Workspace contains multiple Targets, and a Project object has been enabled for the Targets as outlined in the previous section, the Workspace can also be deployed with a single mouse-click. The Workspace properties dialog box contains a Targets tab that is similar in nature to the page found in the Target properties dialog box. This list shows all the Targets, and the Projects in those Targets, that have been set up for automatic deployment. Use the check marks to include or exclude Targets from automatic Workspace deployment and also to rearrange the order of their deployment within the Workspace.
The second tab in the Workspace properties dialog box is labeled Deploy Preview. The changes made in the Targets page are immediately reflected in the Deploy Preview page, so this is a way to verify the proper order of deployment before the changes are applied.
Figure 3.4 shows a side-by-side view of both the Targets and the Deploy Preview tabs of the Workspace properties dialog box. The example shown is a Workspace that contains multiple Targets, and each Target has a single Project object enabled in its corresponding Target properties dialog box.
Figure 3.4 The Workspace Properties dialog box.Building a Runtime Library
The option to recompile a single PBD has existed for several generations of PowerBuilder, and it continues to be an available option for quickly rebuilding a single library following a minor change to an object in the corresponding PBL. In PB 9, the Build Runtime Library... option exists in the System Tree context menu when the selected treeview item is a PBL, and in the Entry, Library menu item of the Library Painter. When selected, the dialog box shown in Figure 3.5 is presented. This dialog box contains a subset of the Project painter options discussed in the previous section. When this option is used, a dynamic library is created for the selected PBL. If the Machine Code option is selected, a DLL will be created; otherwise, PB will generate a Pcode PBD.
Figure 3.5 The Build Runtime Library dialog box.This feature should be used with caution because it can lead to unstable applications. For example, if a function definition in an ancestor class is altered, and only the PBL containing that class is rebuilt into a PBD, other PBLs containing descendent classes or other objects referencing that function would become invalid. This would result in runtime errors when the deployed application was executed. The proper way to compile following an object change of this nature would be to perform an incremental or full rebuild of the entire Target.