Main Content

packNGo

Package generated code in ZIP file for relocation

Description

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 ZIP file can include these types of files:

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

  • Header files (for example, .h, .cuh, 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.

  • CMake configuration files (CMakeLists.txt) that you use to generate makefiles or projects for a compiler environment.

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.

example

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 build 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.

You can configure ZIP file packaging by using the set_param function. During the build process, the code generator uses packNGo to create a ZIP file.

To configure ZIP file packaging for the model zingbit, run this command:

set_param('zingbit', 'PackageGeneratedCodeAndArtifacts', 'on');

The packNGo function creates the file zingbit.zip.

To specify another name for the ZIP file, for example, portzingbit.zip, run these commands:

set_param('zingbit', 'PackageGeneratedCodeAndArtifacts', 'on');
set_param('zingbit', 'PackageName', 'portzingbit.zip')

Input Arguments

collapse all

During the build process, the code generator places buildInfo.mat in the build 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 Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

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

If 'flat', package the generated code files in a ZIP file as a single, flat folder. The function does not package:

  • Child buildInfo.mat files.

  • CMakeLists.txt files.

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.

  • CMakeLists.txt files in the build folder.

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, cuh, 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.

Version History

Introduced in R2006b