Ejemplo n.º 1
0
 def test_no_side_effects(self):
     # messing up with the return value of EnvSetter
     # should not change envsetter.get_build_env()
     envsetter = qisys.envsetter.EnvSetter()
     build_env = envsetter.get_build_env()
     build_env["spam"] = "eggs"
     self.assertTrue(envsetter.get_build_env().get("spam") is None)
Ejemplo n.º 2
0
 def test_no_side_effects(self):
     # messing up with the return value of EnvSetter
     # should not change envsetter.get_build_env()
     envsetter = qisys.envsetter.EnvSetter()
     build_env = envsetter.get_build_env()
     build_env["spam"] = "eggs"
     self.assertTrue(envsetter.get_build_env().get("spam") is None)
Ejemplo n.º 3
0
 def test_prepend_to_path_twice_the_same(self):
     # adding the same path twice should be a no-op
     previous_path = os.environ["PATH"]
     envsetter = qisys.envsetter.EnvSetter()
     envsetter.prepend_to_path(self.unlikely)
     path_env1 = envsetter.get_build_env()["PATH"]
     envsetter.prepend_to_path(self.unlikely)
     path_env2 = envsetter.get_build_env()["PATH"]
     self.assertEquals(os.environ["PATH"], previous_path)
     self.assertEquals(path_env1, path_env2)
     self._check_is_in_path(self.unlikely, path_env1)
Ejemplo n.º 4
0
 def test_prepend_to_path_twice_the_same(self):
     # adding the same path twice should be a no-op
     previous_path = os.environ["PATH"]
     envsetter = qisys.envsetter.EnvSetter()
     envsetter.prepend_to_path(self.unlikely)
     path_env1 = envsetter.get_build_env()["PATH"]
     envsetter.prepend_to_path(self.unlikely)
     path_env2 = envsetter.get_build_env()["PATH"]
     self.assertEquals(os.environ["PATH"], previous_path)
     self.assertEquals(path_env1, path_env2)
     self._check_is_in_path(self.unlikely, path_env1)
Ejemplo n.º 5
0
def get_build_env():
    """ Return the build environnment as read from qibuild config file. """
    qibuild_cfg = QiBuildConfig()
    qibuild_cfg.read(create_if_missing=True)
    envsetter = qisys.envsetter.EnvSetter()
    envsetter.read_config(qibuild_cfg)
    return envsetter.get_build_env()
Ejemplo n.º 6
0
def test_prepending_variable_already_here():
    env = {"PATH": "/foo:/bar"}
    envsetter = qisys.envsetter.EnvSetter(build_env=env)
    envsetter.prepend_to_path("/baz")
    envsetter.prepend_to_path("/foo")
    actual = envsetter.get_build_env()["PATH"]
    assert actual == "/foo:/baz:/bar"
Ejemplo n.º 7
0
def get_build_env():
    """ Return the build environnment as read from qibuild config file. """
    qibuild_cfg = QiBuildConfig()
    qibuild_cfg.read(create_if_missing=True)
    envsetter = qisys.envsetter.EnvSetter()
    envsetter.read_config(qibuild_cfg)
    return envsetter.get_build_env()
Ejemplo n.º 8
0
def do(args):
    """ Main entry point. """
    build_worktree = qibuild.parsers.get_build_worktree(args)
    envsetter = qisys.envsetter.EnvSetter()
    envsetter.read_config(build_worktree.build_config.qibuild_cfg)
    qibuild.run.run(build_worktree.build_projects, args.binary, args.bin_args,
                    env=envsetter.get_build_env(), exec_=args.exec_)
Ejemplo n.º 9
0
 def test_prepend_to_path(self):
     previous_path = os.environ["PATH"]
     envsetter = qisys.envsetter.EnvSetter()
     envsetter.prepend_to_path(self.unlikely)
     build_env = envsetter.get_build_env()
     self.assertEquals(os.environ["PATH"], previous_path)
     new_path = build_env["PATH"]
     self._check_is_in_path(self.unlikely, new_path)
Ejemplo n.º 10
0
 def test_prepend_to_path_multi(self):
     """ Adding a directory containing os.path.sep should do the smart thing """
     envsetter = qisys.envsetter.EnvSetter()
     to_add = self.unlikely + os.path.pathsep + self.absurd
     envsetter.prepend_to_path(to_add)
     env_path = envsetter.get_build_env()["PATH"]
     self._check_is_in_path(self.unlikely, env_path)
     self._check_is_in_path(self.absurd, env_path)
Ejemplo n.º 11
0
 def test_prepend_to_path(self):
     previous_path = os.environ["PATH"]
     envsetter = qisys.envsetter.EnvSetter()
     envsetter.prepend_to_path(self.unlikely)
     build_env = envsetter.get_build_env()
     self.assertEquals(os.environ["PATH"], previous_path)
     new_path = build_env["PATH"]
     self._check_is_in_path(self.unlikely, new_path)
Ejemplo n.º 12
0
 def test_prepend_to_path_multi(self):
     # Adding a directory containing os.path.sep should
     # do the smart thing:
     envsetter = qisys.envsetter.EnvSetter()
     to_add = self.unlikely + os.path.pathsep + self.absurd
     envsetter.prepend_to_path(to_add)
     env_path = envsetter.get_build_env()["PATH"]
     self._check_is_in_path(self.unlikely, env_path)
     self._check_is_in_path(self.absurd, env_path)
Ejemplo n.º 13
0
def test_prepending_variable_already_here():
    env = {
            "PATH" : "/foo:/bar"
    }
    envsetter = qisys.envsetter.EnvSetter(build_env=env)
    envsetter.prepend_to_path("/baz")
    envsetter.prepend_to_path("/foo")
    actual = envsetter.get_build_env()["PATH"]
    assert actual == "/foo:/baz:/bar"
Ejemplo n.º 14
0
 def test_prepend_to_path_several_times(self):
     # adding two different paths should work
     previous_path = os.environ["PATH"]
     envsetter = qisys.envsetter.EnvSetter()
     envsetter.prepend_to_path(self.unlikely)
     envsetter.prepend_to_path(self.absurd)
     path_env = envsetter.get_build_env()["PATH"]
     self.assertEquals(os.environ["PATH"], previous_path)
     self._check_is_in_path(self.unlikely, path_env)
     self._check_is_in_path(self.absurd  , path_env)
Ejemplo n.º 15
0
def do(args):
    """Main entry point """
    build_worktree = qibuild.parsers.get_build_worktree(args)
    envsetter = qisys.envsetter.EnvSetter()
    envsetter.read_config(build_worktree.build_config.qibuild_cfg)
    qibuild.run.run(build_worktree.build_projects,
                    args.binary,
                    args.bin_args,
                    env=envsetter.get_build_env(),
                    exec_=args.exec_)
Ejemplo n.º 16
0
 def test_prepend_to_path_several_times(self):
     # adding two different paths should work
     previous_path = os.environ["PATH"]
     envsetter = qisys.envsetter.EnvSetter()
     envsetter.prepend_to_path(self.unlikely)
     envsetter.prepend_to_path(self.absurd)
     path_env = envsetter.get_build_env()["PATH"]
     self.assertEquals(os.environ["PATH"], previous_path)
     self._check_is_in_path(self.unlikely, path_env)
     self._check_is_in_path(self.absurd, path_env)
Ejemplo n.º 17
0
def get_build_env(build_config):
    """ Read env settings from ~/.config/qi/qibuild.xml """
    # This is required to find CMake at the correct location,
    # and to source vcvarsall.bat on Windows

    qibuild_cfg = qibuild.config.QiBuildConfig()
    qibuild_cfg.read()
    qibuild_cfg.set_active_config(build_config.name)
    envsetter = qisys.envsetter.EnvSetter()
    envsetter.read_config(qibuild_cfg)
    return envsetter.get_build_env()
Ejemplo n.º 18
0
        def test_source_bat(self):
            vc_path  = r'c:\microsoft\vc\bin'
            lib_path = r'c:\microsoft\vc\lib'
            with qisys.sh.TempDir() as tmp:
                sourceme = os.path.join(tmp, "sourceme.bat")
                to_write = r"""@echo hello world
set PATH=%PATH%;{}
set LIBPATH={}
""".format(vc_path, lib_path)
                with open(sourceme, "w") as fp:
                    fp.write(to_write)
                envsetter = qisys.envsetter.EnvSetter()
                envsetter.source_bat(sourceme)
                build_env = envsetter.get_build_env()
                # simple assert:
                build_env_path = build_env["PATH"]
                self._check_is_in_path(vc_path, build_env["PATH"])
                self._check_is_in_path(lib_path, build_env["LIBPATH"])
                # sourcing the .bat twice should not change the PATH env var
                envsetter.source_bat(sourceme)
                build_env_path2 = envsetter.get_build_env()["PATH"]
                self.assertEquals(build_env_path2, build_env_path)
Ejemplo n.º 19
0
        def test_source_bat(self):
            vc_path = r'c:\microsoft\vc\bin'
            lib_path = r'c:\microsoft\vc\lib'
            with qisys.sh.TempDir() as tmp:
                sourceme = os.path.join(tmp, "sourceme.bat")
                to_write = r"""@echo hello world
set PATH=%PATH%;{}
set LIBPATH={}
""".format(vc_path, lib_path)
                with open(sourceme, "w") as fp:
                    fp.write(to_write)
                envsetter = qisys.envsetter.EnvSetter()
                envsetter.source_bat(sourceme)
                build_env = envsetter.get_build_env()
                # simple assert:
                build_env_path = build_env["PATH"]
                self._check_is_in_path(vc_path, build_env["PATH"])
                self._check_is_in_path(lib_path, build_env["LIBPATH"])
                # sourcing the .bat twice should not change the PATH env var
                envsetter.source_bat(sourceme)
                build_env_path2 = envsetter.get_build_env()["PATH"]
                self.assertEquals(build_env_path2, build_env_path)
Ejemplo n.º 20
0
    def __init__(self, worktree,
            config=None,
            qibuild_cfg=None,
            build_type="Debug",
            cmake_flags=None,
            profiles=None,
            cmake_generator=None):
        """
        Create a new Toc object. Most of the keyargs come directly from
        the command line. (--worktree, --debug, -c, etc.)

        :param worktree:  see :py:meth:`qisys.worktree.WorkTree.__init__`
        :param qibuild_cfg: a  :py:class:`qibuild.config.QiBuildConfig` instance
                            if not given, a new one will be created
        :param build_type: a build type, could be debug or release
                           (defaults to debug)
        :param cmake_flags:     optional additional cmake flags
        :param cmake_generator: optional cmake generator
                         (defaults to Unix Makefiles)
        """
        # Set during qibuild.cmdparse.projects_from_args and
        # used by get_sdk_dirs().
        # Why? Assume you have hello depending on world, which is both
        # a project and a pacakge.
        # qc hello  -> get_sdk_dirs('hello') = []
        # qc world hello -> get_sdk_dirs('hello') = ["world/build/sdk"]
        self.active_projects = list()
        self.worktree = worktree
        # The local config file in which to write
        dot_qi = os.path.join(self.worktree.root, ".qi")
        qisys.sh.mkdir(dot_qi)
        self.config_path =  os.path.join(dot_qi, "qibuild.xml")
        if not os.path.exists(self.config_path):
            with open(self.config_path, "w") as fp:
                fp.write("<qibuild />\n")

        # Perform format conversion if necessary
        handle_old_qibuild_cfg(self.worktree.root)
        handle_old_qibuild_xml(self.worktree.root)

        # Handle config:
        if not qibuild_cfg:
            self.config = qibuild.config.QiBuildConfig(config)
            self.config.read()
        else:
            self.config = config
        self.config.read_local_config(self.config_path)
        self.active_config = self.config.active_config
        # Special case if "--system" was used:
        if config == "system":
            self.active_config = None

        self.local_cmake = None
        if self.active_config:
            local_dir = os.path.join(worktree.root, ".qi")
            local_cmake = os.path.join(local_dir, "%s.cmake" % self.active_config)
            if os.path.exists(local_cmake):
                self.local_cmake = local_cmake

        self.build_type = build_type
        if not self.build_type:
            self.build_type = "Debug"

        self.cmake_generator   = cmake_generator
        self.build_folder_name = None

        # Set build environment
        envsetter = qisys.envsetter.EnvSetter()
        envsetter.read_config(self.config)
        self.build_env =  envsetter.get_build_env()

        # List of objects of type qibuild.project.Project,
        # this is updated using WorkTree.buildable_projects
        self.projects          = list()

        # Set cmake generator if user has not set if in Toc ctor:
        if not self.cmake_generator:
            self.cmake_generator = self.config.cmake.generator
            if not self.cmake_generator:
                self.cmake_generator = "Unix Makefiles"

        # Read the current config, create toolchain and pacakges object
        # if necessary
        self.packages = list()
        self.toolchain = None
        if self.active_config is not None:
            if self.active_config in qitoolchain.get_tc_names():
                self.toolchain = qitoolchain.Toolchain(self.active_config)
                self.packages  = self.toolchain.packages
            else:
                # The config does not match a toolchain
                local_dir = os.path.join(self.worktree.root, ".qi")
                local_cmake = os.path.join(local_dir, "%s.cmake" % self.active_config)
                if not os.path.exists(local_cmake):
                    mess  = """Invalid configuration {active_config}
 * No toolchain named {active_config}. Known toolchains are:
    {tc_names}
 * No custom cmake file for config {active_config} found.
   (looked in {local_cmake})
"""
                    mess =  mess.format(active_config=self.active_config,
                                local_cmake = local_cmake,
                                tc_names = qitoolchain.get_tc_names())
                    if self.active_config == self.config.local.defaults.config:
                        mess += """Note: this is your default config
You may want to run:

  qibuild init --force -w {worktree.root}
(to re-initialize your worktree and not use any toolchain)

  qibuild init --force -w {worktree.root} --config=<config>
(to use a different toolchain by default)
 """
                        mess = mess.format(worktree=self.worktree)
                        raise WrongDefaultException(mess)
                    else:
                        raise Exception(mess)
        if self.toolchain:
            self.packages = self.toolchain.packages
        else:
            self.packages = list()

        # Useful vars to cope with Visual Studio quirks
        self.using_visual_studio = "Visual Studio" in self.cmake_generator
        self.vc_version = self.cmake_generator.split()[-1]

        # The actual list of cmake flags we are going to use
        # will be computed during self.update_projects
        # Right now, we will just store the flags passed in ctor
        # in self.user_cmake_flags, to be sure they are always added
        # at the end of the list of flags
        if cmake_flags:
            self.user_cmake_flags = cmake_flags[:]
        else:
            self.user_cmake_flags = list()

        self.profiles = list()
        self.apply_profiles(profiles)

        # Finally, update the build configuration of all the projects
        # (this way we are sure that the build configuration is the same for
        # every project)
        self.update_projects()
Ejemplo n.º 21
0
 def test_create_new_env(self):
     # Check that envsetter is able to create new env vars
     envsetter = qisys.envsetter.EnvSetter()
     envsetter.set_env_var("WITH_SPAM", "ON")
     build_env = envsetter.get_build_env()
     self.assertTrue(build_env.get("WITH_SPAM", "ON"))
Ejemplo n.º 22
0
 def test_create_new_env(self):
     # Check that envsetter is able to create new env vars
     envsetter = qisys.envsetter.EnvSetter()
     envsetter.set_env_var("WITH_SPAM", "ON")
     build_env = envsetter.get_build_env()
     self.assertTrue(build_env.get("WITH_SPAM", "ON"))