ModuleProvider | Qbs Manual
Description: Creates modules on demand.

- Qbs Manual
- QbsLanguageItems
- ModuleProvider
- Qbs 3.1.1

Module ◦ Parameter

# ModuleProvider

Creates modules on demand. More...

- List of all members, including inherited members
- ModuleProvider is part of List of All Items.

## Properties

- isEager : bool
- moduleName : string
- 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.

A ModuleProvider item may contain Probe items.

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

isEager : bool `[default: true]`

Holds whether provider is eager.

Eager provider is executed only once and should create multiple modules at once when executed). A non-eager provider is executed multiple times, one time for each module Qbs tries to instantiate.

See also ModuleProvider::moduleName.

moduleName : string

This property is set by QBS for non-eager providers and contains the name of the module that is currently being instantiated by the provider.

For eager providers, the value of this property is `undefined`.

See also ModuleProvider::isEager.

name : string

The name of the module provider.

This property is set by Qbs.

If provider is requested via the qbsModuleProviders property, it is the name specified in this property and matches the provider file name, without the `.qbs` extension. Otherwise, it is the name of the directory the provider was found in, relative to the particular module-providers base directory. 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