# qiBuild documentation

# qisys.envsetter – controlling environment variables

## qisys.envsetter.EnvSetter

class `qisys.envsetter.``EnvSetter`(build_env=None)

  A class to manage environment variables Typical usage:

      envsetter = EnvSetter()
      envsetter.prepend_to_path(r"c:\path\to\cmake")
      envsetter.set_env_var("WITH_SPAM", "ON")
      envsetter.source_bat(r"C:\path\to\vcvars.bat")
      build_env = envsetter.get_build_env()
      # build_env is now a *copy* of os.environ, os.environ does
      # NOT change
      qisys.command.call("cmake", env=build_env)

  Notes: * this will work even if `cmake` was not in `%PATH%` before,

  > because we will use `build_env` when searching for `cmake`. (see `qisys.command.call()` documentation)

  - the `source_bat()` function is useful to use `cl.exe` and `NMake Makefiles`. In this case, you have to source `vsvarsall.bat`.
  `get_build_env`()

    Returns a dictionary containing the new environment (note that `os.environ` is preserved)

  `set_env_var`(variable, value)

    Set a new variable

  `prepend_directory_to_variable`(directory, variable)

    Append a new directory to an environment variable containing a list of paths (most of the time PATH, but can be LIBDIR, for instance when using cl.exe) * The path will always be sanitize first

    > (absolute, native path)

    - No directory will be added twice
    - The variable will be put in upper case on the dictionary on windows.
  `prepend_to_path`(directory)

    Append a directory to PATH environment variable

  `source_bat`(bat_file)

    Set environment variables using a .bat script Note: right now, this only works well with vcvarsall.bat scripts.

  `read_config`(qibuild_cfg)

    Read a `qibuild.config.QiBuildConfig` instance

Changelog CMake index Python index Index