Analyze Project Dependencies

To analyze the structure of a project and discover files required by the project, run a dependency analysis. You can run dependency analysis at any point in your workflow when you want to check that the project has all required files. For example, it is a good idea to check dependencies when setting up a project, before submitting a version of your project to source control, and before sharing the project.

Running a dependency analysis can show you how a change affects other files before you make the change. For example, it is common to use dependency analysis to examine your project structure, to find, investigate, and resolve problems in project files, or to find the toolboxes required by the project. When investigating the potential impact of a change in requirements, use dependency analysis to find the design files linked to the requirements document. You also can use it to investigate change set impact by finding upstream and downstream dependencies of modified files before committing the changes. Finding these dependencies can help you identify design and test files that need modification and help you find the tests you need to run.

After dependency analysis, you can open or label the files. You can also export the results as workspace variables, images, or reloadable files. And you can send these files for custom task processing. Exporting the results enables further processing or archiving of impact analysis results. You can add the exported list of files to reports or other documents that describe the impact of a change.

Run Dependency Analysis

Before running a dependency analysis on a project, make sure that you have added all your files to the project. The dependency analysis only checks the files in your project. For more information, see Add Files to Project.

To run a dependency analysis on all the files in your project, select the Dependency Analysis view. Then, on the Dependency Analysis tab, click Analyze.

To analyze only specific files, on the Dependency Analysis tab, click Analyze > Select Files to Analyze. Select the files for analysis and then click Analyze.

To analyze the dependencies of external toolboxes, on the Dependency Analysis tab, click Options > Analyze External Toolboxes.

After performing dependency analysis, the Impact View shows:

  • Your project structure and its file dependencies, showing how files such as models, libraries, functions, data files, source files, and derived files relate to each other.

  • Required products and toolboxes.

  • Relationships between source and derived files (such as .m and .p files, , .slx and .slxp, .ssc and .sscp, or .c and .mex files), and between C/C++ source and header files. You can see what code is generated by each model, and find what code needs to be regenerated if you modify a model.

  • Warnings about problem files, such as missing files, files not in the project, files with unsaved changes, and out-of-date derived files.

To examine project dependencies and problem files, at the top right of the Dependency Analysis view, click Table View.

After you run the first dependency analysis of your project, subsequent analyses are incremental updates. However, if you update external toolboxes and want to discover dependency changes in them, you must perform a complete analysis. To perform a complete analysis, go to the Dependency Analysis tab and click Analyze > Reanalyze All.

For more information about running a dependency analysis on Simulink® models and libraries, see Perform Impact Analysis (Simulink).

Investigate and Resolve Problems

After you run a dependency analysis, the impact graph for the whole project appears in Impact View. The project dependency analysis identifies problems, such as missing files, files not in the project, unsaved changes, and out-of-date derived files. You can examine problem files using the Impact View or the Table View.

Use the Impact View to investigate problem files graphically. The center of the view displays the impact graph for your project. The right panel of the Impact View shows the toolbox dependencies and a list of problem files.

  • To show only the problem files in the graph, hover over the Problems heading in the right pane of the Impact View and click Find All. To return to the full project view, clear the filter in the search box (for instance, Dependencies of "filename").

  • To see the details for a specific problem file, including the path, type, and problem message, select the file in the graph. To clear the file selection and see all problem files for a project, click a blank area of the graph.

  • To view the dependencies of a file, hover over the problem file and click Find All. The graph updates to display only the problem file and its dependencies. To return to the full project view, clear the filter in the search box (for instance, problem=='*').

Use the Table View to investigate your project dependencies and problem files as a table. To use the Table View, at the top right of the Dependency Analysis view, select Table View.

  • To view the files with problems at the top of the list, sort the table by the Problem Description column.

  • To view the problems for a file, check the message in the Problem Description column for that file.

  • To view the dependencies of a file, select the file in the table. The lower pane shows the files that depend on the selected file. You can view either the Directly Impacted Files or switch to the Directly Required Files.

Resolve Problems

For each problem file, take actions to resolve the problem. This table lists common problems and describes how to fix them.

Problem Message

Description

Fix

Not in project

The file is not in the project.

Add the file to the project.

You do not need to add all required files to the project. For example, you can exclude derived S-function binary files that the source code in your project generates. For more information, see Add Files to Project.

To remove a file from the problem list without adding it to the project, right-click the file and select Add External File.

Missing project file

The file is in the project but does not exist on disk.

Create the file, or recover it using source control.

Outside project root

The file is outside the project root folder.

If this is OK, set the file as an external file. Otherwise move it under the project root.

If you need a file that is outside the project root to be in your project, copy or move the file within the project root, and add it to the project and the path. Remove the original file location from the path.

If required files are outside your project root, you cannot add these files to your project. This dependency might not indicate a problem if the file is on your path and is a utility or resource that is not part of your project. Use dependency analysis to ensure that you understand the design dependencies.

In unreferenced project

The file is within a project that is not referenced by the current project.

Add the project containing the file as a project reference.

Missing file

The file or variable cannot be found.

If this status is acceptable, right-click the file and select Add External File.

Unsaved changes

The file has unsaved changes in the MATLAB® editor.

Save the file.

Derived file out of date

The derived file is older than the source file it was derived from.

Regenerate the derived file. If it is a .p file, you can regenerate it automatically by running the project checks. On the Project tab, click Check Project and follow prompts to rebuild files.

If you rename a source file, the project detects the impact to the derived file and prompts you to update it.

Missing product

The project has a dependency on a missing product.

Install the missing product.

Find Required Toolboxes

After running a dependency analysis on a project, the Impact View shows the required toolboxes for the whole project or for selected files. You can see which products are required to use the project, or find which file is introducing a product dependency.

In the right pane of the Dependency Analysis view, the Product section displays the required products for the whole project. To view products required by selected files, select some files by clicking the graph or a legend.

To find which file is introducing a product dependency, hover over the product name and click Find Usages.

The graph updates to show only the files using the selected product. To return to the full project view, clear the filter in the search box (for instance, Usages of "productname").

If a required product is missing, the product list labels it Missing. To resolve a missing product, install the product and rerun the dependency analysis.

Find File Dependencies

To investigate the dependencies of a file after running a dependency analysis, in the Impact View, right-click the file in the graph and select Find All Dependencies, Find Impacted Files, or Find Required Files. The graph shows the selected file and the file dependencies.

Alternatively, select the file, go to the Dependency Analysis tab, and, in the Impact Analysis section, click Find. Select from the available options.

To select groups of files, in the File Type legend at the top-left corner of the Impact View, select from the available options. For example, to select all function files, click File Type and select Function. To change how files in the view are grouped, go to the Dependency Analysis tab, and in the View section, click Group By. Select from the available options.

To select modified files, problem files, or external files, go to the Dependency Analysis tab, and in the Impact Analysis section, click Select. Select from the available options.

To examine or edit a file dependency, expand the file by clicking the arrows next to the file name in the graph. Then, double-click the referencing component (such as a line of MATLAB code that references a problem file) to open it. To expand all files in the graph, in the View section, click Expand All.

To reset the graph to show all analyzed dependencies in the project, on the Dependency Analysis tab, in the Impact Analysis section, select Find > All Files.

Tip

For large projects, viewing the results in a table can make navigation easier. To use the Table View, at the top right of the Dependency Analysis view, select Table View.

Find Requirements Documents

In a project, a dependency analysis finds requirements documents linked using the Requirements Management Interface.

  • You can view and navigate to and from the linked requirements documents.

  • You can create or edit Requirements Management links only if you have Simulink Requirements™.

To highlight requirements documents in the graph, at the top right of the Impact View, click the Dependency Type legend and select Requirements Link. Arrows connect requirements documents to the files with the requirement links.

To find the requirement links for a specific file, expand the file by clicking the arrows next to the file name in the graph. To expand all files in the graph, in the View section, click Expand All. An arrow connects the component containing the requirement link to the requirements document.

To open a requirements document, double-click the document in the graph.

Save, Open, and Compare Dependency Analysis Results

After running a dependency analysis in a project, you can save the results of the analysis. Then, you can open and view the results without having to repeat the analysis.

To save your results as a .graphml file, go to the Dependency Analysis tab, and in the File section, click Save As. Choose a file name and location.

To open a saved dependency analysis result, on the Dependency Analysis tab, in the File section, click Open.

To compare the results of a current dependency analysis with previously saved results, go to the Dependency Analysis tab, and in the File section, click Compare to Saved. Select a .graphml file and inspect the differences in the comparison report.

Export Files in Impact View

To export all the files displayed in the Impact View of a dependency analysis, first, click the graph background to clear the selection on all files. Then, go to the Dependency Analysis tab, and in the Impact Analysis section, click Export. Select from the available options:

  • Save to Workspace — Save the selected file paths to a variable.

  • Send to Custom Task — Open the Custom Task dialog box with the files selected.

  • Show in Files View — Switch to the Files view with the files selected.

To export a subset of files in the graph, select the files, and then click Export. The menu displays how many files are selected: Selected files: number of files . Alternatively, you can right-click the selected files, and select from the options in the Export menu.

Export Graph to Image File

To export the Impact View graph as an image file for sharing or archiving, go to the Dependency Analysis tab, and in the File section, select Save As > Save As Image. Use the Save dialog box to specify the name, file type, and location. The default file type is SVG, which supports image scaling.

You also can copy the image to the clipboard using the keyboard. You then can paste the clipboard contents into other documents.

Related Topics