Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 3
0
    def __init__(self, targets, options):
        super(diff, self).__init__(targets, options)
        if isinstance(self._listed, tuple):
            moresh.pushd()
            dirc = self._listed[0]
            test_name = self._listed[1]
            assert (test_name.find(',') == -1)

            Test.restrictTo(test_name)
            self.build_tests((options, []), dirc, os.listdir(dirc))

            assert (len(Test._instances_map) == 1)
            test = Test._instances_map[test_name]

        elif isinstance(self._listed, type([])):
            assert (len(self._listed) == 1)
            test = self._listed[0]

        else:
            raise TypeError, type(self._listed)

        expected = test.resultsDirectory(EXPECTED_RESULTS)
        run_results = test.resultsDirectory(RUN_RESULTS)
        os.system("kdiff3 %s %s >& /dev/null" % (expected, run_results))
Ejemplo n.º 4
0
    def __init__(self, targets, options):
        super(diff, self).__init__(targets, options)
        if isinstance(self._listed, tuple):
            moresh.pushd()
            dirc = self._listed[0]
            test_name = self._listed[1]
            assert( test_name.find(',') == -1 )

            Test.restrictTo(test_name)
            self.build_tests((options, []), dirc, os.listdir(dirc))

            assert( len(Test._instances_map)==1 )
            test = Test._instances_map[test_name]
            
        elif isinstance(self._listed, type([])):
            assert( len(self._listed)==1 )            
            test = self._listed[0]

        else:
            raise TypeError, type(self._listed)

        expected = test.resultsDirectory(EXPECTED_RESULTS)
        run_results = test.resultsDirectory(RUN_RESULTS)
        os.system("kdiff3 %s %s >& /dev/null"%(expected, run_results))
Ejemplo n.º 5
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