Пример #1
0
    def setUpClass(cls):
        """
        Sets up a little test Xpkg environment and builds the test toolset
        packages.
        """

        # Get all the basics setup
        TestBase.setUpClass()

        # Create a toolset repo directory
        cls.toolset_repo_dir = os.path.join(cls.storage_dir, 'toolset-repo')

        util.ensure_dir(cls.toolset_repo_dir)

        # Build our packages into it
        root_tree = os.path.join(root_dir, 'pkgs')

        for pkg_name in ['busybox', 'tcc', 'uclibc']:
            xpd_path = os.path.join(root_tree, pkg_name + '.xpd')

            args = ['build', xpd_path, '--dest', cls.toolset_repo_dir]

            cmd = [sys.executable, '-m', 'xpkg.main'] + args

            # Run build inside toolset dir so that the build logs don't pollute
            # Anything
            cwd = os.getcwd()
            with util.cd(cls.toolset_repo_dir):
                with util.save_env():
                    os.environ['PYTHONPATH'] = cwd

                    output = util.shellcmd(cmd, shell=False, stream=False)
Пример #2
0
    def setUpClass(cls):
        """
        Sets up a little test Xpkg environment and builds the test toolset
        packages.
        """

        # Get all the basics setup
        TestBase.setUpClass()

        # Create a toolset repo directory
        cls.toolset_repo_dir = os.path.join(cls.storage_dir, 'toolset-repo')

        util.ensure_dir(cls.toolset_repo_dir)

        # Build our packages into it
        root_tree = os.path.join(root_dir, 'pkgs')

        for pkg_name in ['busybox', 'tcc', 'uclibc']:
            xpd_path = os.path.join(root_tree, pkg_name + '.xpd')

            args = ['build', xpd_path, '--dest', cls.toolset_repo_dir]

            cmd = [sys.executable, '-m', 'xpkg.main'] + args

            # Run build inside toolset dir so that the build logs don't pollute
            # Anything
            cwd = os.getcwd()
            with util.cd(cls.toolset_repo_dir):
                with util.save_env():
                    os.environ['PYTHONPATH'] = cwd

                    output = util.shellcmd(cmd, shell=False, stream=False)
Пример #3
0
    def build(self, target_dir, environment = None, output_to_file=True):
        """
        Right now this just executes instructions inside the XPD, but in the
        future we can make this a little smarter.

        It returns the info structure for the created package.  See the XPA
        class for the structure of the data returned.
        """

        # Create our temporary directory
        self._work_dir = tempfile.mkdtemp(suffix = '-xpkg-' + self._xpd.name)

        # TODO: LOG THIS
        print 'Working in:',self._work_dir

        # Create our output
        if output_to_file:
            # Form a hopefully unique name for the output file
            args = (self._xpd.name, self._xpd.version)
            output_file = '%s-%s_build.log' % args

            # Put the file in our environment if we have, or the current
            # directory
            if environment:
                # Find out log dir
                log_dir = environment.log_dir(environment.root)

                # Make sure it exists
                util.ensure_dir(log_dir)

                # Now finally commit to our path
                output_path = os.path.join(log_dir, output_file)
            else:
                output_path = os.path.abspath(os.path.join('.', output_file))

            # TODO: LOG THIS
            print 'Log file:',output_path

            # Open our file for writing
            self._output = open(output_path, 'w')
        else:
            self._output = None

        # Store our target dir
        self._target_dir = target_dir
        util.ensure_dir(self._target_dir)

        # Determine our environment directory
        if environment:
            self._env_dir = environment._env_dir
        else:
            self._env_dir = ''

        # Setup the ld.so symlink in the target dir pointing to either
        # the system ld.so, or the current environments
        ld_target_dir = self._target_dir
        update_root = self._env_dir if len(self._env_dir) else self._target_dir

        linux.update_ld_so_symlink(update_root, ld_target_dir)

        try:
            # Store the current environment
            env_vars = util.EnvStorage(store = True)

            # If we have an environment apply it's variables so the build can
            # reference the libraries installed in it
            if environment:
                environment.apply_env_variables()

            # Fetches and unpacks all the required sources for the package
            self._get_sources()

            # Determine what directory we have to do the build in
            dirs = [d for d in os.listdir(self._work_dir) if
                    os.path.isdir(os.path.join(self._work_dir, d))]

            if 'build-dir' in self._xpd._data:
                # If the user specifies a build directory use it
                rel_build_dir = self._xpd._data['build-dir']
                build_dir = os.path.join(self._work_dir, rel_build_dir)

                # Make sure the directory exists
                util.ensure_dir(build_dir)
            elif len(dirs) == 1:
                build_dir = os.path.join(self._work_dir, dirs[0])
            else:
                build_dir = self._work_dir

            with util.cd(build_dir):
                # Standard build configure install
                self._configure()

                self._build()

                new_paths = self._install()
        finally:
            # Put back our environment
            env_vars.restore()

            self._env_dir = ''

            # Close our output file if it exists
            if self._output:
                self._output.close()
                self._output = None

            # Make sure we cleanup after we are done
            shutil.rmtree(self._work_dir)


        return self._create_info(new_paths)