qibuild.envsetter – controlling environment variables


class qibuild.envsetter.EnvSetter

A class to manager environment variables

Typical usage:

envsetter = EnvSetter()
envsetter.set_env_var("WITH_SPAM", "ON")
build_env = envsetter.get_build_env()
# build_env is now a *copy* of os.environ, os.environ does
# NOT change
qibuild.command.call("cmake", env=build_env)


  • this will work even in cmake was not in %PATH% before, because we will use build_env when searching for ‘cmake’. (see qibuild.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.

Returns a dict containing the new environnment (note that os.environ is presevered)

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 dictionnary on windows.


Append a directory to PATH environment variable


Read a qibuild.config.QiBuildConfig instance

set_env_var(variable, value)

Set a new variable


Set environment variables using a .bat script

Note: right now, this only works well with vcvarsall.bat scripts.