Qbs Manual

Qbs 1.14.0

Module ◦ Parameter

# ModuleProvider

Creates modules on demand. More...

- List of all members, including inherited members

## Properties

- name : string
- outputBaseDir : string
- relativeSearchPaths : stringList

## Detailed Description

The `ModuleProvider` item implements the module creation part of the procedure described in the Module Providers overview. It is always located in a file called `provider.qbs`.

The actual module creation is done on the right-hand side of the relativeSearchPaths property.

Here is a complete minimal example of a module provider. It just creates an empty module. If you put this item into the file `module-providers/mymodule/provider.qbs` in your project source directory, you will be able to successfully build a product which contains a dependency on the module `mymodule`.

      import qbs.File
      import qbs.FileInfo
      import qbs.TextFile

      ModuleProvider {
          relativeSearchPaths: {
              var moduleDir = FileInfo.joinPaths(outputBaseDir, "modules", name);
              File.makePath(moduleDir);
              var moduleFilePath = FileInfo.joinPaths(moduleDir, name + ".qbs");
              var moduleFile = new TextFile(moduleFilePath, TextFile.WriteOnly);
              moduleFile.writeLine("Module {");
              moduleFile.writeLine("}");
              moduleFile.close();
              return "";
          }
      }

## Property Documentation

name : string

The name of the module provider.

This property is set by Qbs. For simple dependency names, it is the name of the dependency as specified in the Depends item. If the dependency name consists of multiple components, the value is the name up until (and including) the component that corresponds to the directory the provider was found in. For instance, if the dependency is `x.m1` and the provider was found in `module-providers/x/m1/provider.qbs`, then `name` is `x.m1`. If the provider was found in `module-providers/x/provider.qbs`, then `name` is `x`.

outputBaseDir : string

The path under which the new modules should be created when relativeSearchPaths is evaluated. The path is unique for the current provider in the given configuration.

This property is set by Qbs.

relativeSearchPaths : stringList

This property gets evaluated by Qbs to retrieve new search paths with which to re-attempt the module look-up.

It is here where you need to put the code that creates the new module files. Use the directory structure explained in Custom Modules and Items. That is, the file for a module called `m` will be located in a directory `modules/m/`, anchored at outputBaseDir.

The return value is the list of search paths required to find the new module, relative to outputBaseDir. In most cases, only a single search path will be required, in which case a single-element list containing an empty string should be returned (or just the empty string, because of Qbs' auto-conversion feature).

The returned list can also be empty, which means that the module provider was not able to generate any modules in this environment.

Module ◦ Parameter