Using Source Code Control with LabVIEW and Perforce

Using a source code control (SCC) system on a software project is very beneficial. You can use an SCC system to share files among multiple developers, improve security and quality, and track changes to shared projects.

LabVIEW can interface with several SCC systems, including Microsoft Visual Source Safe and Perforce. Perforce is a great choice for use with LabVIEW, as it shares multi-operating system support and other key characteristics. This tutorial explains the setup and use of Perforce in LabVIEW 7.0 on a Windows XP computer.

Table of Contents:

      Using Source Code Control with LabVIEW and Perforce
        Downloading and Installing Perforce

      The first step is to download the evaluation software from the Perforce Web site. There are documents on their site called The Ten Minute Demo, which take you through the basic installation process for the software:
      When installing, remember the following items:
      • Select Administrator - Typical as the installation type.
      • The evaluation copy is limited to two users and two client workspaces. If you want to have more, you must purchase a license. However, all the features are available for use in the evaluation copy.
        See Also:
        Perforce
        Using Source Code Control with LabVIEW and Perforce
          Configuring Perforce

        After you install Perforce, you must set up a client workspace, which is the only essential step for configuring Perforce.

          Note: The following information in this section is from The Ten Minute Demo - Windows 1

          Setting up a Client Workspace
          To work with files in Perforce, you need to create a client workspace.
          1. Create a folder called C:\p4client
          2. Put some test files and folders in C:\p4client
          3. Start up P4Win from the Windows Start menu by selecting Programs»Perforce»P4Win.
          4. Click OK in the pop-up that tells you you need a client workspace.
          5. Pull down ClientSpec»Edit from the menu bar to bring up the Perforce Client Specification dialog box.
          6. Enter C:\p4client in the Root field.
          7. Click Update. If you get a warning dialog saying "You have changed the root for this client...", click OK to proceed.
            Using Source Code Control with LabVIEW and Perforce
              Perforce Basics

            Using Perforce for Windows, you can learn to perform all of the necessary operations for starting your source code control project, like adding, editing, and deleting files from control, in just a few minutes.

              To Add Files to the Perforce Depot
              1. In P4Win, click the View Pending Changelists button to display the Pending Changelists pane.
              2. Open the Windows Explorer and drag the C:\p4client folder to P4Win's Pending Changelists pane.
              3. Select the Open files for add only radio button, and then click OK in the dialog box that comes up.
              4. In the Pending Changelists pane, double-click on Pending Changelists to show your pending changelists.
              5. Right-click on Default and select Submit.
              6. In the dialog box that appears, replace <enter description here> with text of your own.
              7. Click Submit. The files you added are now under Perforce's control. You'll find them under the icon in the Client View of Perforce Depot pane.

              To Edit Files
              1. Click + to expand the icon, then select the files you want to change.
              2. Right-click and select Open for Edit.
              3. Right-click and select Edit using the editor of your choice.

              To Delete Files
              1. Click + to expand the icon and select files.
              2. Right-click and select Open for Delete.

              To Submit These Changes to the Depot
              1. In the Pending Changelists pane, right-click on Default and select Submit.
              2. In the dialog box that appears, replace <enter description here> with text of your own.
              3. Click Submit.
                Using Source Code Control with LabVIEW and Perforce
                  Configuring and Using LabVIEW SCC

                LabVIEW SCC tools provide access to the more common source code control functions from within the LabVIEW development environment. You can access all the features of the LabVIEW source code control (SCC) by using the Tools»Source Code Control menu. You must first set up LabVIEW to integrate with Perforce.

                  Configuring LabVIEW with Perforce
                  Refer to the LabVIEW Help for step-by-step instructions for configuring Perforce in LabVIEW. Access the LabVIEW Help by selecting Help»VI, Function, & How-To Help.

                  When a dialog box appears to suggest that you enable the Treat read-only VIs as locked option, click the Change Option button.

                  After you configure LabVIEW with Perforce as the SCC provider, you can add, check out, and delete files from source code control in LabVIEW.

                  Adding a VI to Source Code Control
                  1. Open a VI or create a new VI.
                  2. Select File»Save As and save the VI in your Perforce directory, such as C:\P4Client.
                  3. Select Tools»Source Code Control»Add to SCC. If you saved the VI in the Perforce directory, LabVIEW adds it to source code control. Otherwise, an error message appears.
                  4. Click the Submit button to submit the changes to Perforce or click the Cancel button if you want to submit the changes later. If you click the Submit button, LabVIEW adds the VI to SCC, and if you click the Cancel button, LabVIEW adds the VI to the pending changelist in Perforce.
                  5. If you clicked the Submit button, add a description in the Perforce Change Specification window that appears and click the Submit button.

                  Checking VIs Out from Source Code Control
                  1. In LabVIEW, open the VI you want to check out and edit. The VI opens, but you cannot edit it.
                  2. Select Tools»Source Code Control»Open For Edit.
                  3. After you are done editing the VI, select Tools»Source Code Control»Submit.
                  4. In the Perforce Change Specification window that appears, enter a description of the changes and click the Submit button.

                  Deleting Files from Source Code Control
                  1. In LabVIEW, open the VI you want to remove from source code control.
                  2. Select Tools»Source Code Control»Open for Delete.
                  3. When a message appears about the deletion, click the OK button to proceed.

                  Note: LabVIEW removes the local copy of the VI from the computer.

                  Reverting to a Previous Version of a VI
                  1. Open Perforce for Windows.
                  2. Navigate to the source file you want to revert in the Depot view.
                  3. Right-click the file and select Revision History.
                  4. In the list of revisions for the file, select the version to which you want to revert.
                  5. Click the Sync button.
                  6. In the Pending Changelists pane, right-click the file and select Edit With»Associated Editor.

                  Note: You can sync to the head revision of a VI by selecting Tools»Source Code Control»Sync to Head Revision.
                      Using Source Code Control with LabVIEW and Perforce
                        Additional SCM Tools In LabVIEW

                      Along with source code control, LabVIEW has two other features that are useful for implementing a software configuration management plan. You can use the revision history settings in LabVIEW to track and document all changes that happen to a particular source file, and you can use the graphical differencing functionality to display differences in files. You can use these features to easily document a project as it develops, thus saving a lot of time during auditing, billing, and delivery.

                      Revision History
                      LabVIEW has global settings that can add information to a revision history inside the VI itself. Select Tools»Options to display the Options dialog box and select Revision History from the top pull-down menu to access these options. These options apply to all VIs that you open or create, with the exception of the login options, which require you to restart LabVIEW. If you want to apply any of these options to your project, configure the setting before the project starts and all VIs have the setting(s). You also can override the top four settings for each VI by selecting File»VI Properties and selecting Revision History from the Category pull-down menu.

                      To display the revision history of a VI, select Tools»VI Revision History. You can add as many comments for each revision as you want. LabVIEW adds the revision number, time and date, and the user before each comment. You also can extract this information from the VI programmatically, making the process of getting revision information easy for audits and code reviews.

                      Graphical Differencing
                      Most SCC systems allow you to compare different versions of a text file to see what changes have been made. This is commonly called a diff. LabVIEW's differencing is a similar concept, but instead of the character changes in a file, it displays the graphical differences in VIs. You can select Tools»Compare VI to compare two VIs for changes on both the front panel and block diagram. These changes can range from minor cosmetic changes, such as moving a control or a wire, to new functionality and VI attributes.

                      You can compare the current VI with the last revision in SCC by selecting Tools»Source Code Control»Compare VI.
                          Using Source Code Control with LabVIEW and Perforce
                            Recommendations

                          If you follow two additional guidelines along with a software configuration management plan, you will develop the project faster, it will have fewer errors, and it will be more profitable.

                          Hierarchical Design of a VI Application
                          National Instruments recommends using a hierarchical design for all your VI projects. This normally consists of the top-level VI in a directory with all its subVIs in their own subdirectories. This is the beginning of a tree type structure for the application. You probably also have a folder or folders of subVIs that you share among the applications.

                          Figure 1. Hierarchical Design

                          This kind of organization makes for easier application modularity and component merging, parallel development, and source code control organization.

                          LabVIEW Development Guidelines
                          Use the LabVIEW Development Guidelines manual to learn how to build VIs that are easy to understand, use, and revise. This manual describes project tracking, design, and documentation techniques. This manual also contains recommended style guidelines.

                          You can access the manual in LabVIEW by selecting Help»Search the LabVIEW Bookshelf. You also can access the manual on the NI Web site (linked below).
                              See Also:
                              Product Manuals: LabVIEW Development Guidelines
                              Using Source Code Control with LabVIEW and Perforce
                                References

                              1. Perforce Downloads. (n.d.). Retrieved Jan., 2004, from http://www.perforce.com/perforce/demo/nt.html

                              你可能感兴趣的:(source)