- Qbs Manual
- General Services
- Qt Build Suite 1.4.4

# General Services

These are operations that do not fit into any of the other categories. They are automatically available in any Qbs project file or JavaScript file.

## Available Operations

### qbs.currentEnv

    qbs.currentEnv(): { [key: string]: string; }

Returns the environment of Qbs in the current context as an object whose properties are the environment variables.

### qbs.getEnv

    qbs.getEnv(key: string): string

Tries to find a variable with the given name in the build environment and returns its value. If no such variable could be found, `undefined` is returned.

### qbs.getHash

    qbs.getHash(key: string): string

Calculates a 16-byte hash of the input and returns it. Rules in modules should use this function to find unique locations for output artifacts in the build directory without duplicating the whole directory structure of the respective input file (to deal with the case of two files with the same name in different subdirectories of the same product).

### qbs.rfc1034Identifier

    qbs.rfc1034Identifier(str: string): string

Returns an RFC 1034 compliant identifier based on the given string by replacing each character that is not Latin alphanumeric or `.` with `-`.

### loadFile

    loadFile(filePath: string): any

Loads a JavaScript file and returns an object that contains the evaluated context of this file. This function is only available in JavaScript files. For example:

    var MyFunctions = loadFile("myfunctions.js");
    MyFunctions.doSomething();

### loadExtension

    loadExtension(extensionName: string): any

Loads a Qbs extension and returns an object that contains all functions of that extension. This function is only available in JavaScript files. For example:

    var FileInfo = loadExtension("qbs.FileInfo");
    var fileName = FileInfo.fileName(filePath);

## Extensions to JavaScript Built-in Objects

### Array.contains

    Array.contains(e: any): boolean

Returns `true` if the array contains the element `e`. Returns `false` otherwise.

### Array.uniqueConcat

    Array.uniqueConcat(other: any[]): any[]

Returns a copy of this array joined with the array `other`. Duplicates that would originate from the concatenation are removed. The order of elements is preserved.

### String.contains

    String.contains(s: string): boolean

Returns `true` if the string contains the substring `s`. Returns `false` otherwise.

### startsWith

    String.startsWith(s: string): boolean

Returns `true` if the string starts with the substring `s`. Returns `false` otherwise.

### endsWith

    String.endsWith(s: string): boolean

Returns `true` if the string ends with the substring `s`. Returns `false` otherwise.