Пример #1
0
    def __first_compilation_attempt(self):

        #######  First compilation attempt  ####################################
        
        targetdir, exec_name = os.path.split(self.getInternalExecPath())
        sanity_check, log_fname = os.path.split(self.__log_file_path)
        assert sanity_check == targetdir

        if sys.platform == 'win32':
            # When there are characters like '=' in a filenme, Windows can get
            # confused if the filename is not quoted.
            log_fname = '"%s"' % log_fname
                                 
        # Remove outdated log file
        assert not os.path.exists(exec_name)
        if os.path.exists(log_fname):
            os.remove(log_fname)
            
        elif not os.path.exists(targetdir):
            os.makedirs(targetdir)

        # Actual compilation
        moresh.pushd(targetdir)
        logging.debug("\nIn %s:"%os.getcwd())
        
        if sys.platform == 'win32':
            # We assume the compiler is pymake.
            if self.compiler != "pymake":
                raise Not_Implemented
            the_compiler = "python " + \
                os.path.join(ppath.ppath('PLEARNDIR'), 'scripts', 'pymake')
        else:
            the_compiler = self.compiler

        compile_options = ""
        if self.compile_options is not None:
            compile_options = self.compile_options

        compile_cmd= self.getCompileCommand(the_compiler, compile_options)

        logging.debug(compile_cmd)
        p= subprocess.Popen(compile_cmd, 
                            shell= True,
                            stdout= open(log_fname, 'w'),
                            stderr= subprocess.STDOUT)
        compile_exit_code= p.wait()
        logging.debug("compile_exit_code <- %d\n"%compile_exit_code)

        moresh.popd()

        # Report success of fail and remember that compilation was attempted
        self.__attempted_to_compile = True
        if compile_exit_code!=0 and os.path.exists(self.getInternalExecPath()):
            os.remove(self.getInternalExecPath())

        # Strip C++ execs
        if self.isCompilable() and self.compilationSucceeded():
            os.system("strip %s"%self.getInternalExecPath())
            
        return compile_exit_code==0
Пример #2
0
def psavediff(former_file, later_file, precision=1e-06):
    """Special manipulation of psave files.
    
    The psave files are meant to change over time which additions of
    new options to the various class of the library. To avoid a diff to
    fail on the addition of a new option, the psave files are canonized
    through the read_and_write command prior to the diff call.
    """
    # Absolute path to the original files
    former_abspath = os.path.abspath(former_file)
    later_abspath = os.path.abspath(later_file)

    # Creating and changing to a temporary directory meant for comparison
    tmpdir = 'PSAVEDIFF/%s'%os.path.basename(later_file)
    if not os.path.exists(tmpdir):
        os.makedirs(tmpdir)
    moresh.pushd( tmpdir )
    logging.debug("--- pushd to %s"%os.getcwd())

    # Names for the files resulting from read_and_write
    former_rw = "rw_former_%s"%os.path.basename(former_file)
    later_rw = "rw_later_%s"%os.path.basename(later_file)

    # Creating the canonized files
    rw_cmd = plearn_cmd("read_and_write %s %s")
    os.system( rw_cmd%(former_abspath, former_rw) )
    assert os.path.exists(former_rw), "Error generating %s"%former_rw
    logging.debug(rw_cmd%(former_abspath, former_rw)+' succeeded.')

    os.system( rw_cmd%(later_abspath, later_rw) )
    assert os.path.exists(later_rw), "Error generating %s"%later_rw
    logging.debug(rw_cmd%(later_abspath, later_rw)+' succeeded.')

    ## Actual comparison
    report = []
    diff = toolkit.command_output(plearn_cmd("diff %s %s %s") \
                          % (former_rw, later_rw, precision))
    diff = "".join(diff)
    # diff = toldiff(former_rw, later_rw, precision)

    if diff:
        report = [ "--- %s and %s\n  Processed through read_and_write (%s)\n     %s"
                   % (former_file, later_file, tmpdir, diff) ]
    logging.debug('Report: %s'%report)

    ## Move back to original directory.
    moresh.popd( )
    logging.debug("--- popd to %s\n"%os.getcwd())
    return report
Пример #3
0
    def __first_compilation_attempt(self):

        #######  First compilation attempt  ####################################

        targetdir, exec_name = os.path.split(self.getInternalExecPath())
        sanity_check, log_fname = os.path.split(self.__log_file_path)
        assert sanity_check == targetdir

        if sys.platform == 'win32':
            # When there are characters like '=' in a filenme, Windows can get
            # confused if the filename is not quoted.
            log_fname = '"%s"' % log_fname

        # Remove outdated log file
        assert not os.path.exists(exec_name)
        if os.path.exists(log_fname):
            os.remove(log_fname)

        elif not os.path.exists(targetdir):
            os.makedirs(targetdir)

        # Actual compilation
        moresh.pushd(targetdir)
        logging.debug("\nIn %s:" % os.getcwd())

        if sys.platform == 'win32':
            # We assume the compiler is pymake.
            if self.compiler != "pymake":
                raise Not_Implemented
            the_compiler = "python " + \
                os.path.join(ppath.ppath('PLEARNDIR'), 'scripts', 'pymake')
        else:
            the_compiler = self.compiler

        compile_options = ""
        if self.compile_options is not None:
            compile_options = self.compile_options

        compile_cmd = self.getCompileCommand(the_compiler, compile_options)

        logging.debug(compile_cmd)
        p = subprocess.Popen(compile_cmd,
                             shell=True,
                             stdout=open(log_fname, 'w'),
                             stderr=subprocess.STDOUT)
        compile_exit_code = p.wait()
        logging.debug("compile_exit_code <- %d\n" % compile_exit_code)

        moresh.popd()

        # Report success of fail and remember that compilation was attempted
        self.__attempted_to_compile = True
        if compile_exit_code != 0 and os.path.exists(
                self.getInternalExecPath()):
            os.remove(self.getInternalExecPath())

        # Strip C++ execs
        if self.isCompilable() and self.compilationSucceeded():
            os.system("strip %s" % self.getInternalExecPath())

        return compile_exit_code == 0