Esempio n. 1
0
        def run(self):
            project_dir = self.extensions[0].project_dir

            cmake_config = 'Debug' if self.debug else 'Release'
            cmake_args = [
                '-DCMAKE_INSTALL_PREFIX=' + envvar.PYOMO_CONFIG_DIR,
                '-DBUILD_AMPLMP_IF_NEEDED=ON',
                #'-DCMAKE_BUILD_TYPE=' + cmake_config,
            ] + user_args

            try:
                # Redirect all stderr to stdout (to prevent powershell
                # from inadvertently failing builds)
                sys.stderr.flush()
                sys.stdout.flush()
                old_stderr = os.dup(sys.stderr.fileno())
                os.dup2(sys.stdout.fileno(), sys.stderr.fileno())
                old_environ = dict(os.environ)
                if parallel:
                    # --parallel was only added in cmake 3.12.  Use an
                    # environment variable so that we don't have to bump
                    # the minimum cmake version.
                    os.environ['CMAKE_BUILD_PARALLEL_LEVEL'] = str(parallel)

                cmake = find_executable('cmake')
                if cmake is None:
                    raise IOError("cmake not found in the system PATH")
                self.spawn([cmake, project_dir] + cmake_args)
                if not self.dry_run:
                    # Skip build and go straight to install: the build
                    # harness should take care of dependencies and this
                    # will prevent repeated builds in MSVS
                    #
                    #self.spawn(['cmake', '--build', '.',
                    #            '--config', cmake_config])
                    self.spawn([
                        cmake, '--build', '.', '--target', 'install',
                        '--config', cmake_config
                    ])
            finally:
                # Restore stderr
                sys.stderr.flush()
                sys.stdout.flush()
                os.dup2(old_stderr, sys.stderr.fileno())
                os.environ = old_environ
Esempio n. 2
0
    def test_find_executable(self):
        self.tmpdir = os.path.abspath(tempfile.mkdtemp())
        os.chdir(self.tmpdir)

        config.PYOMO_CONFIG_DIR = self.tmpdir
        config_libdir = os.path.join(self.tmpdir, 'lib')
        os.mkdir(config_libdir)
        config_bindir = os.path.join(self.tmpdir, 'bin')
        os.mkdir(config_bindir)

        ldlibdir_name = 'in_ld_lib'
        ldlibdir = os.path.join(self.tmpdir, ldlibdir_name)
        os.mkdir(ldlibdir)
        os.environ['LD_LIBRARY_PATH'] = os.pathsep + ldlibdir + os.pathsep

        pathdir_name = 'in_path'
        pathdir = os.path.join(self.tmpdir, pathdir_name)
        os.mkdir(pathdir)
        os.environ['PATH'] = os.pathsep + pathdir + os.pathsep

        exeExt = _exeExt[_system()] or ''

        f_in_cwd_notexe = 'f_in_cwd_notexe'
        open(os.path.join(self.tmpdir, f_in_cwd_notexe), 'w').close()
        f_in_cwd_ldlib_path = 'f_in_cwd_ldlib_path'
        self._make_exec(os.path.join(self.tmpdir, f_in_cwd_ldlib_path))
        self._make_exec(os.path.join(ldlibdir, f_in_cwd_ldlib_path))
        self._make_exec(os.path.join(pathdir, f_in_cwd_ldlib_path))
        f_in_path_extension = 'f_in_path_extension'
        self._make_exec(os.path.join(pathdir, f_in_path_extension + exeExt))
        f_in_path = 'f_in_path'
        self._make_exec(os.path.join(pathdir, f_in_path))

        f_in_configlib = 'f_in_configlib'
        self._make_exec(os.path.join(config_libdir, f_in_configlib))
        f_in_configbin = 'f_in_configbin'
        self._make_exec(os.path.join(config_libdir, f_in_path_extension))
        self._make_exec(os.path.join(config_bindir, f_in_configbin))

        self.assertEqual((os.path.join(self.tmpdir, f_in_cwd_notexe)
                          if _system() in ('windows', 'cygwin') else None),
                         find_executable(f_in_cwd_notexe))
        self.assertEqual(os.path.join(self.tmpdir, f_in_cwd_ldlib_path),
                         find_executable(f_in_cwd_ldlib_path))
        self.assertEqual(os.path.join(pathdir, f_in_cwd_ldlib_path),
                         find_executable(f_in_cwd_ldlib_path, cwd=False))
        self.assertEqual(
            os.path.join(pathdir, f_in_path_extension) + exeExt,
            find_executable(f_in_path_extension))
        self.assertEqual(os.path.join(pathdir, f_in_path),
                         find_executable(f_in_path))
        self.assertEqual(None, find_executable(f_in_path, include_PATH=False))
        self.assertEqual(
            os.path.join(pathdir, f_in_path),
            find_executable(f_in_path,
                            pathlist=os.pathsep + pathdir + os.pathsep))
        # test an explicit pathlist overrides PATH
        self.assertEqual(
            os.path.join(ldlibdir, f_in_cwd_ldlib_path),
            find_executable(f_in_cwd_ldlib_path,
                            cwd=False,
                            pathlist=[ldlibdir]))
        # test that the PYOMO_CONFIG_DIR 'bin' dir is included
        self.assertEqual(os.path.join(config_bindir, f_in_configbin),
                         find_executable(f_in_configbin))
        # ... but only if the pathlist is not specified
        self.assertEqual(None, find_executable(f_in_configbin,
                                               pathlist=pathdir))
Esempio n. 3
0
    def test_find_executable(self):
        self.tmpdir = os.path.abspath(tempfile.mkdtemp())
        os.chdir(self.tmpdir)

        config.PYOMO_CONFIG_DIR = self.tmpdir
        config_libdir = os.path.join(self.tmpdir, 'lib')
        os.mkdir(config_libdir)
        config_bindir = os.path.join(self.tmpdir, 'bin')
        os.mkdir(config_bindir)

        ldlibdir_name = 'in_ld_lib'
        ldlibdir = os.path.join(self.tmpdir, ldlibdir_name)
        os.mkdir(ldlibdir)
        os.environ['LD_LIBRARY_PATH'] = os.pathsep + ldlibdir + os.pathsep

        pathdir_name = 'in_path'
        pathdir = os.path.join(self.tmpdir, pathdir_name)
        os.mkdir(pathdir)
        os.environ['PATH'] = os.pathsep + pathdir + os.pathsep

        exeExt = _exeExt[_system()] or ''

        f_in_cwd_notexe = 'f_in_cwd_notexe'
        open(os.path.join(self.tmpdir,f_in_cwd_notexe), 'w').close()
        f_in_cwd_ldlib_path = 'f_in_cwd_ldlib_path'
        self._make_exec(os.path.join(self.tmpdir,f_in_cwd_ldlib_path))
        self._make_exec(os.path.join(ldlibdir,f_in_cwd_ldlib_path))
        self._make_exec(os.path.join(pathdir,f_in_cwd_ldlib_path))
        f_in_path_extension = 'f_in_path_extension'
        self._make_exec(os.path.join(pathdir,f_in_path_extension + exeExt))
        f_in_path = 'f_in_path'
        self._make_exec(os.path.join(pathdir,f_in_path))

        f_in_configlib = 'f_in_configlib'
        self._make_exec(os.path.join(config_libdir, f_in_configlib))
        f_in_configbin = 'f_in_configbin'
        self._make_exec(os.path.join(config_libdir, f_in_path_extension))
        self._make_exec(os.path.join(config_bindir, f_in_configbin))


        self.assertEqual(
            ( os.path.join(self.tmpdir,f_in_cwd_notexe)
              if _system() in ('windows','cygwin')
              else None ),
            find_executable(f_in_cwd_notexe)
        )
        self.assertEqual(
            os.path.join(self.tmpdir, f_in_cwd_ldlib_path),
            find_executable(f_in_cwd_ldlib_path)
        )
        self.assertEqual(
            os.path.join(pathdir, f_in_cwd_ldlib_path),
            find_executable(f_in_cwd_ldlib_path, cwd=False)
        )
        self.assertEqual(
            os.path.join(pathdir, f_in_path_extension) + exeExt,
            find_executable(f_in_path_extension)
        )
        self.assertEqual(
            os.path.join(pathdir, f_in_path),
            find_executable(f_in_path)
        )
        self.assertEqual(
            None,
            find_executable(f_in_path, include_PATH=False)
        )
        self.assertEqual(
            os.path.join(pathdir, f_in_path),
            find_executable(f_in_path, pathlist=os.pathsep+pathdir+os.pathsep)
        )
        # test an explicit pathlist overrides PATH
        self.assertEqual(
            os.path.join(ldlibdir, f_in_cwd_ldlib_path),
            find_executable(f_in_cwd_ldlib_path, cwd=False, pathlist=[ldlibdir])
        )
        # test that the PYOMO_CONFIG_DIR 'bin' dir is included
        self.assertEqual(
            os.path.join(config_bindir, f_in_configbin),
            find_executable(f_in_configbin)
        )
        # ... but only if the pathlist is not specified
        self.assertEqual(
            None,
            find_executable(f_in_configbin, pathlist=pathdir)
        )