packNGo

Package generated code in ZIP file for relocation

Description

example

packNGo(buildInfo,Name,Value) packages the code files in a compressed ZIP file so that you can relocate, unpack, and rebuild them in another development environment. The list of name-value pairs is optional.

The types of code files in the ZIP file include:

  • Source files (for example, .c and .cpp files)

  • Header files (for example, .h and .hpp files)

  • MAT-file that contains the build information object (.mat file)

  • Nonbuild-related files (for example, .dll files and .txt informational files) required for a final executable

  • Build-generated binary files (for example, executable .exe file or dynamic link library .dll).

    The code generator includes the build-generated binary files (if present) in the ZIP file. The ignoreFileMissing property does not apply to build-generated binary files.

Use this function to relocate files. You can then recompile the files for a specific target environment or rebuild them in a development environment in which MATLAB® is not installed. By default, the function packages the files as a flat folder structure in a ZIP file within the code generation folder. You can customize the output by specifying name-value pairs. After relocating the ZIP file, use a standard ZIP utility to unpack the compressed file.

The packNGo function can potentially modify the build information passed in the first packNGo argument. As part of code packaging, packNGo can find additional files from source and include paths recorded in the build information. When these files are found, packNGo adds them to the build information.

To ensure that packNGo finds header files, add their paths to buildInfo by using the addIncludePaths function.

Note

When generating standalone code by using the codegen command, you can use the -package option to both generate code and package the code in a ZIP file in a single step.

Examples

collapse all

After the build process is complete, you can run packNGo from the Command Window. Use packNGo for ZIP file packaging of generated code in the file portzingbit.zip. Maintain the relative file hierarchy.

  1. Change folders to the code generation folder. For example, using MATLAB Coder™, codegen/dll/zingbit or for Simulink® code generation, zingbit_grt_rtw.

  2. Load the buildInfo object that describes the build.

  3. Run packNGo with property settings for packType and fileName.

cd codegen/dll/zingbit;
load buildInfo.mat
packNGo(buildInfo,'packType', 'hierarchical', ...
   'fileName','portzingbit');

If you configure ZIP file packaging from the code generation pane, the code generator uses packNGo to output a ZIP file during the build process.

  1. Select Code Generation > Package code and artifacts. Optionally, provide a Zip file name. To apply the changes, click OK.

  2. Build the model. At the end of the build process, the code generator outputs the ZIP file. The folder structure in the ZIP file is hierarchical.

If you configure ZIP file packaging by using the set_param function, the code generator uses packNGo to output a ZIP file during the build process.

To configure ZIP file packaging for the model zingbit in the file zingbit.zip, use the set_param function.

set_param('zingbit','PostCodeGenCommand', ...
   'packNGo(buildInfo);');

Input Arguments

collapse all

During the build process, the code generator places buildInfo.mat in the code generation folder. This MAT-file contains the buildInfo object. The object provides information that packNGo uses to produce the ZIP file.

You can specify the argument as a buildInfo object:

load buildInfo.mat
packNGo(buildInfo,'packType', 'hierarchical', ...
   'fileName','portzingbit');

Or, you can specify the argument as the path to the buildInfo.mat file:

buildInfoFile = fullfile(pathToBuildFolder, 'buildInfo.mat');
packNGo(buildInfoFile,'packType', 'hierarchical', ...
   'fileName','portzingbit');

Or, you can specify the argument as the path to the folder that contains buildInfo.mat:

packNGo(pathToBuildFolder,'packType', 'hierarchical', ...
   'fileName','portzingbit');

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'packType','flat','nestedZipFiles',true

If 'flat', package the generated code files in a ZIP file as a single, flat folder.

If 'hierarchical', package the generated code files hierarchically in a primary ZIP file. The hierarchy contains top model, referenced model, and shared utility folders. The function also packages the corresponding buildInfo.mat files for the folders.

Example: 'packType','flat'

If true, create a primary ZIP file that contains three secondary ZIP files:

  • mlrFiles.zip — Files in your matlabroot folder tree

  • sDirFiles.zip — Files in and under your code generation folder

  • otherFiles.zip — Required files not in the matlabroot or start folder trees

If false, create a primary ZIP file that contains folders, for example, your code generation folder and matlabroot.

Example: 'nestedZipFiles',true

If you do not specify the 'fileName'-value pair, the function packages the files in a ZIP file named modelOrFunctionName.zip and places the ZIP file in the code generation folder.

If you specify 'fileName' with the value, 'myName', the function creates myName.zip in the code generation folder.

To specify another location for the primary ZIP file, provide the absolute path to the location, fullPath/myName.zip

Example: 'fileName','/home/user/myModel.zip'

If true, include only the minimal header files required to build the code in the ZIP file.

If false, include header files found on the include path in the ZIP file.

Example: 'minimalHeaders',true

If false, do not include the html folder in the ZIP file.

If true, include the html folder in the ZIP file.

Example: 'includeReport',false

If false, terminate on parse errors.

If true, do not terminate on parse errors.

Example: 'ignoreParseError',false

If false, terminate on missing file errors.

If true, do not terminate on missing files errors.

Example: 'ignoreFileMissing',false

Limitations

  • The function operates on source files only, such as *.c, *.cpp, and *.h files. The function does not support compile flags, defines, or makefiles.

  • The function does not package source files for reusable library subsystems.

  • Unnecessary files might be included. The function might find additional files from source paths and include paths recorded in the build information, even if those files are not used.

Introduced in R2006b