def get_coq_output(coqc_prog, coqc_prog_args, contents, timeout_val, verbose_base=1, **kwargs):
    """Returns the coqc output of running through the given
    contents."""
    global TIMEOUT
    if timeout_val < 0 and TIMEOUT is not None:
        return get_coq_output(coqc_prog, coqc_prog_args, contents, TIMEOUT, verbose_base=verbose_base, **kwargs)

    key = (coqc_prog, tuple(coqc_prog_args), contents, timeout_val)
    if key in COQ_OUTPUT.keys():
        file_name = COQ_OUTPUT[key][0]
    else:
        with tempfile.NamedTemporaryFile(suffix='.v', delete=False) as f:
            f.write(contents)
            file_name = f.name

    cmds = [coqc_prog] + list(coqc_prog_args) + [file_name, "-q"]
    if kwargs['verbose'] >= verbose_base:
        kwargs['log']('\nRunning command: "%s"' % '" "'.join(cmds))

    if key in COQ_OUTPUT.keys(): return COQ_OUTPUT[key][1]

    start = time.time()
    (stdout, stderr) = memory_robust_timeout_Popen_communicate(cmds, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, timeout=(timeout_val if timeout_val > 0 else None))
    finish = time.time()
    if TIMEOUT is None:
        TIMEOUT = 2 * max((1, int(math.ceil(finish - start))))
    clean_v_file(file_name)
    ## remove instances of the file name
    #stdout = stdout.replace(os.path.basename(file_name[:-2]), 'Top')
    COQ_OUTPUT[key] = (file_name, (clean_output(stdout), tuple(cmds)))
    return COQ_OUTPUT[key][1]
Exemple #2
0
def get_coq_output(coqc_prog,
                   coqc_prog_args,
                   contents,
                   timeout_val,
                   cwd=None,
                   is_coqtop=False,
                   pass_on_stdin=False,
                   verbose_base=1,
                   **kwargs):
    """Returns the coqc output of running through the given
    contents.  Pass timeout_val = None for no timeout."""
    global TIMEOUT
    if timeout_val is not None and timeout_val < 0 and TIMEOUT is not None:
        return get_coq_output(coqc_prog,
                              coqc_prog_args,
                              contents,
                              TIMEOUT,
                              cwd=cwd,
                              is_coqtop=is_coqtop,
                              pass_on_stdin=pass_on_stdin,
                              verbose_base=verbose_base,
                              **kwargs)

    key, file_name, cmds, input_val = prepare_cmds_for_coq_output(
        coqc_prog,
        coqc_prog_args,
        contents,
        cwd=cwd,
        timeout_val=timeout_val,
        is_coqtop=is_coqtop,
        pass_on_stdin=pass_on_stdin,
        verbose_base=verbose_base,
        **kwargs)

    if key in COQ_OUTPUT.keys(): return COQ_OUTPUT[key][1]

    start = time.time()
    ((stdout, stderr), returncode) = memory_robust_timeout_Popen_communicate(
        kwargs['log'],
        cmds,
        stderr=subprocess.STDOUT,
        stdout=subprocess.PIPE,
        stdin=subprocess.PIPE,
        timeout=(timeout_val
                 if timeout_val is not None and timeout_val > 0 else None),
        input=input_val,
        cwd=cwd)
    finish = time.time()
    if kwargs['verbose'] >= verbose_base + 1:
        kwargs['log']('\nretcode: %d\nstdout:\n%s\n\nstderr:\n%s\n\n' %
                      (returncode, util.s(stdout), util.s(stderr)))
    if TIMEOUT is None and timeout_val is not None:
        TIMEOUT = 3 * max((1, int(math.ceil(finish - start))))
    clean_v_file(file_name)
    ## remove instances of the file name
    #stdout = stdout.replace(os.path.basename(file_name[:-2]), 'Top')
    COQ_OUTPUT[key] = (file_name, (clean_output(util.s(stdout)), tuple(cmds),
                                   returncode))
    return COQ_OUTPUT[key][1]
Exemple #3
0
def get_coq_accepts_top(coqc):
    temp_file = tempfile.NamedTemporaryFile(suffix='.v', dir='.', delete=True)
    temp_file_name = temp_file.name
    p = subprocess.Popen([coqc, "-top", "Top", temp_file_name], stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
    (stdout, stderr) = p.communicate()
    temp_file.close()
    clean_v_file(temp_file_name)
    return '-top: no such file or directory' not in stdout
Exemple #4
0
def get_coq_accepts_top(coqc):
    temp_file = tempfile.NamedTemporaryFile(suffix='.v', dir='.', delete=True)
    temp_file_name = temp_file.name
    p = subprocess.Popen([coqc, "-q", "-top", "Top", temp_file_name], stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
    (stdout, stderr) = p.communicate()
    temp_file.close()
    clean_v_file(temp_file_name)
    return '-top: no such file or directory' not in stdout
Exemple #5
0
def get_coq_output(coqc_prog,
                   coqc_prog_args,
                   contents,
                   timeout_val,
                   verbose_base=1,
                   **kwargs):
    """Returns the coqc output of running through the given
    contents."""
    global TIMEOUT
    if timeout_val < 0 and TIMEOUT is not None:
        return get_coq_output(coqc_prog,
                              coqc_prog_args,
                              contents,
                              TIMEOUT,
                              verbose_base=verbose_base,
                              **kwargs)

    key = (coqc_prog, tuple(coqc_prog_args), contents, timeout_val)
    if key in COQ_OUTPUT.keys():
        file_name = COQ_OUTPUT[key][0]
    else:
        with tempfile.NamedTemporaryFile(suffix='.v', delete=False) as f:
            f.write(contents)
            file_name = f.name

    cmds = [coqc_prog] + list(coqc_prog_args) + [file_name, "-q"]
    if kwargs['verbose'] >= verbose_base:
        kwargs['log']('\nRunning command: "%s"' % '" "'.join(cmds))

    if key in COQ_OUTPUT.keys(): return COQ_OUTPUT[key][1]

    start = time.time()
    (stdout, stderr) = memory_robust_timeout_Popen_communicate(
        cmds,
        stderr=subprocess.STDOUT,
        stdout=subprocess.PIPE,
        timeout=(timeout_val if timeout_val > 0 else None))
    finish = time.time()
    if TIMEOUT is None:
        TIMEOUT = 2 * max((1, int(math.ceil(finish - start))))
    clean_v_file(file_name)
    ## remove instances of the file name
    #stdout = stdout.replace(os.path.basename(file_name[:-2]), 'Top')
    COQ_OUTPUT[key] = (file_name, (clean_output(stdout), tuple(cmds)))
    return COQ_OUTPUT[key][1]
def get_coq_output(coqc_prog, coqc_prog_args, contents, timeout_val, is_coqtop=False, pass_on_stdin=False, verbose_base=1, **kwargs):
    """Returns the coqc output of running through the given
    contents."""
    global TIMEOUT
    if timeout_val < 0 and TIMEOUT is not None:
        return get_coq_output(coqc_prog, coqc_prog_args, contents, TIMEOUT, is_coqtop=is_coqtop, pass_on_stdin=pass_on_stdin, verbose_base=verbose_base, **kwargs)

    key = (coqc_prog, tuple(coqc_prog_args), pass_on_stdin, contents, timeout_val)
    if key in COQ_OUTPUT.keys():
        file_name = COQ_OUTPUT[key][0]
    else:
        with tempfile.NamedTemporaryFile(suffix='.v', delete=False) as f:
            f.write(contents)
            file_name = f.name

    file_name_root = os.path.splitext(file_name)[0]

    cmds = [coqc_prog] + list(coqc_prog_args)
    pseudocmds = ''
    input_val = None
    if is_coqtop:
        if pass_on_stdin:
            input_val = contents
            cmds.extend(['-q'])
            pseudocmds = '" < "%s' % file_name
        else:
            cmds.extend(['-load-vernac-source', file_name_root, '-q'])
    else:
        cmds.extend([file_name, '-q'])
    if kwargs['verbose'] >= verbose_base:
        kwargs['log']('\nRunning command: "%s%s"' % ('" "'.join(cmds), pseudocmds))

    if key in COQ_OUTPUT.keys(): return COQ_OUTPUT[key][1]

    start = time.time()
    ((stdout, stderr), returncode) = memory_robust_timeout_Popen_communicate(cmds, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, stdin=subprocess.PIPE, timeout=(timeout_val if timeout_val > 0 else None), input=input_val)
    finish = time.time()
    if TIMEOUT is None:
        TIMEOUT = 2 * max((1, int(math.ceil(finish - start))))
    clean_v_file(file_name)
    ## remove instances of the file name
    #stdout = stdout.replace(os.path.basename(file_name[:-2]), 'Top')
    COQ_OUTPUT[key] = (file_name, (clean_output(stdout), tuple(cmds), returncode))
    return COQ_OUTPUT[key][1]
Exemple #7
0
                    i += 2
                elif i+1 < len(statements) and 'Axioms:' in statements[i+1].replace('\n', ' '):
                    last, ctype = get_constant_name_from_locate(statements[i])
                    open_idents.append((last, ctype, statements[i+1]))
                    if env['verbose'] >= 1: env['log']('OPEN: %s (%s)' % (last, ctype))
                    if env['verbose'] >= 3: env['log'](statements[i+1])
                    i += 2
                elif not statements[i].strip():
                    i += 1
                else:
                    found_ignore, found_error = False, False
                    for header in ignore_header:
                        if statements[i].strip()[:len(header)] == header:
                            found_ignore = True
                            if env['verbose'] >= 3: env['log']('Ignoring: %s' % statements[i])
                    for header in ignore_header:
                        if statements[i].strip()[:len(header)] == header:
                            found_error = True
                    if not found_ignore:
                        if found_error:
                            errors.append(statements[i])
                            if env['verbose'] >= 1: env['log']('ERROR: %s' % statements[i])
                        else:
                            if env['verbose'] >= 1: env['log']('UNKNOWN: %s' % statements[i])
                            unknown.append(statements[i])
                    i += 1
        env['log']('Identifiers which are not closed under the global context:\n%s' % '\n'.join(ident[0] for ident in open_idents))
    finally:
        if env['remove_temp_file']:
            clean_v_file(env['temp_file_name'])
Exemple #8
0
def get_coq_output_iterable(coqc_prog,
                            coqc_prog_args,
                            contents,
                            cwd=None,
                            is_coqtop=False,
                            pass_on_stdin=False,
                            verbose_base=1,
                            sep='\nCoq <',
                            **kwargs):
    """Returns the coqc output of running through the given
    contents."""

    key, file_name, cmds, input_val = prepare_cmds_for_coq_output(
        coqc_prog,
        coqc_prog_args,
        contents,
        cwd=cwd,
        timeout_val=None,
        is_coqtop=is_coqtop,
        pass_on_stdin=pass_on_stdin,
        verbose_base=verbose_base,
        **kwargs)

    if key in COQ_OUTPUT.keys():
        for i in COQ_OUTPUT[key][1].split(sep):
            yield i

    p = Popen_async(cmds,
                    stderr=subprocess.STDOUT,
                    stdout=subprocess.PIPE,
                    stdin=subprocess.PIPE,
                    cwd=cwd)

    so_far = []
    cur = ''
    yielded = True
    completed = False
    while True:
        if yielded and not completed:
            if input_val:
                i = input_val.index('\n') + 1 if '\n' in input_val else len(
                    input_val)
                if kwargs['verbose'] >= 3: print(input_val[:i], end='')
                p.stdin.write(input_val[:i])
                input_val = input_val[i:]
                p.stdin.flush()
                yielded = False
            else:
                completed = True
                p.stdin.close()
        curv = p.stdout.get(True)
        if kwargs['verbose'] >= 3: print(curv, end='')
        cur += curv
        if sep in cur:
            vals = cur.split(sep)
            for val in vals[:-1]:
                yield val
                yielded = True
                so_far.append(val)
            cur = vals[-1]
    if cur != '':
        yield cur
        so_far.append(cur)
    clean_v_file(file_name)
    ## remove instances of the file name
    #stdout = stdout.replace(os.path.basename(file_name[:-2]), 'Top')
    COQ_OUTPUT[key] = (file_name, (clean_output(sep.join(so_far)), tuple(cmds),
                                   None))
def get_coq_output_iterable(coqc_prog,
                            coqc_prog_args,
                            contents,
                            is_coqtop=False,
                            pass_on_stdin=False,
                            verbose_base=1,
                            sep='\nCoq <',
                            **kwargs):
    """Returns the coqc output of running through the given
    contents."""

    key = (coqc_prog, tuple(coqc_prog_args), pass_on_stdin, contents, 0)
    if key in COQ_OUTPUT.keys():
        file_name = COQ_OUTPUT[key][0]
    else:
        with tempfile.NamedTemporaryFile(suffix='.v', delete=False) as f:
            f.write(contents)
            file_name = f.name

    file_name_root = os.path.splitext(file_name)[0]

    cmds = [coqc_prog] + list(coqc_prog_args)
    pseudocmds = ''
    input_val = None
    if is_coqtop:
        if pass_on_stdin:
            input_val = contents
            cmds.extend(['-q'])
            pseudocmds = '" < "%s' % file_name
        else:
            cmds.extend(['-load-vernac-source', file_name_root, '-q'])
    else:
        cmds.extend([file_name, '-q'])
    if kwargs['verbose'] >= verbose_base:
        kwargs['log']('\nRunning command: "%s%s"' %
                      ('" "'.join(cmds), pseudocmds))

    if key in COQ_OUTPUT.keys():
        for i in COQ_OUTPUT[key][1].split(sep):
            yield i

    p = Popen_async(cmds,
                    stderr=subprocess.STDOUT,
                    stdout=subprocess.PIPE,
                    stdin=subprocess.PIPE)

    so_far = []
    cur = ''
    yielded = True
    completed = False
    while True:
        if yielded and not completed:
            if input_val:
                i = input_val.index('\n') + 1 if '\n' in input_val else len(
                    input_val)
                if kwargs['verbose'] >= 3: print(input_val[:i], end='')
                p.stdin.write(input_val[:i])
                input_val = input_val[i:]
                p.stdin.flush()
                yielded = False
            else:
                completed = True
                p.stdin.close()
        curv = p.stdout.get(True)
        if kwargs['verbose'] >= 3: print(curv, end='')
        cur += curv
        if sep in cur:
            vals = cur.split(sep)
            for val in vals[:-1]:
                yield val
                yielded = True
                so_far.append(val)
            cur = vals[-1]
    if cur != '':
        yield cur
        so_far.append(cur)
    clean_v_file(file_name)
    ## remove instances of the file name
    #stdout = stdout.replace(os.path.basename(file_name[:-2]), 'Top')
    COQ_OUTPUT[key] = (file_name, (clean_output(sep.join(so_far)), tuple(cmds),
                                   None))
Exemple #10
0
def get_coq_output(coqc_prog,
                   coqc_prog_args,
                   contents,
                   timeout_val,
                   is_coqtop=False,
                   pass_on_stdin=False,
                   verbose_base=1,
                   **kwargs):
    """Returns the coqc output of running through the given
    contents."""
    global TIMEOUT
    if timeout_val < 0 and TIMEOUT is not None:
        return get_coq_output(coqc_prog,
                              coqc_prog_args,
                              contents,
                              TIMEOUT,
                              is_coqtop=is_coqtop,
                              pass_on_stdin=pass_on_stdin,
                              verbose_base=verbose_base,
                              **kwargs)

    key = (coqc_prog, tuple(coqc_prog_args), pass_on_stdin, contents,
           timeout_val)
    if key in COQ_OUTPUT.keys():
        file_name = COQ_OUTPUT[key][0]
    else:
        with tempfile.NamedTemporaryFile(suffix='.v', delete=False) as f:
            f.write(contents)
            file_name = f.name

    file_name_root = os.path.splitext(file_name)[0]

    cmds = [coqc_prog] + list(coqc_prog_args)
    pseudocmds = ''
    input_val = None
    if is_coqtop:
        if pass_on_stdin:
            input_val = contents
            cmds.extend(['-q'])
            pseudocmds = '" < "%s' % file_name
        else:
            cmds.extend(['-load-vernac-source', file_name_root, '-q'])
    else:
        cmds.extend([file_name, '-q'])
    if kwargs['verbose'] >= verbose_base:
        kwargs['log']('\nRunning command: "%s%s"' %
                      ('" "'.join(cmds), pseudocmds))

    if key in COQ_OUTPUT.keys(): return COQ_OUTPUT[key][1]

    start = time.time()
    ((stdout, stderr), returncode) = memory_robust_timeout_Popen_communicate(
        cmds,
        stderr=subprocess.STDOUT,
        stdout=subprocess.PIPE,
        stdin=subprocess.PIPE,
        timeout=(timeout_val if timeout_val > 0 else None),
        input=input_val)
    finish = time.time()
    if TIMEOUT is None:
        TIMEOUT = 2 * max((1, int(math.ceil(finish - start))))
    clean_v_file(file_name)
    ## remove instances of the file name
    #stdout = stdout.replace(os.path.basename(file_name[:-2]), 'Top')
    COQ_OUTPUT[key] = (file_name, (clean_output(stdout), tuple(cmds),
                                   returncode))
    return COQ_OUTPUT[key][1]
                    i += 2
                elif i+1 < len(statements) and 'Axioms:' in statements[i+1].replace('\n', ' '):
                    last, ctype = get_constant_name_from_locate(statements[i])
                    open_idents.append((last, ctype, statements[i+1]))
                    if env['verbose'] >= 1: env['log']('OPEN: %s (%s)' % (last, ctype))
                    if env['verbose'] >= 3: env['log'](statements[i+1])
                    i += 2
                elif not statements[i].strip():
                    i += 1
                else:
                    found_ignore, found_error = False, False
                    for header in ignore_header:
                        if statements[i].strip()[:len(header)] == header:
                            found_ignore = True
                            if env['verbose'] >= 3: env['log']('Ignoring: %s' % statements[i])
                    for header in ignore_header:
                        if statements[i].strip()[:len(header)] == header:
                            found_error = True
                    if not found_ignore:
                        if found_error:
                            errors.append(statements[i])
                            if env['verbose'] >= 1: env['log']('ERROR: %s' % statements[i])
                        else:
                            if env['verbose'] >= 1: env['log']('UNKNOWN: %s' % statements[i])
                            unknown.append(statements[i])
                    i += 1
        env['log']('Identifiers which are not closed under the global context:\n%s' % '\n'.join(ident[0] for ident in open_idents))
    finally:
        if env['remove_temp_file']:
            clean_v_file(env['temp_file_name'])
def get_coq_output_iterable(coqc_prog, coqc_prog_args, contents, is_coqtop=False, pass_on_stdin=False, verbose_base=1, sep='\nCoq <', **kwargs):
    """Returns the coqc output of running through the given
    contents."""

    key = (coqc_prog, tuple(coqc_prog_args), pass_on_stdin, contents, 0)
    if key in COQ_OUTPUT.keys():
        file_name = COQ_OUTPUT[key][0]
    else:
        with tempfile.NamedTemporaryFile(suffix='.v', delete=False) as f:
            f.write(contents)
            file_name = f.name

    file_name_root = os.path.splitext(file_name)[0]

    cmds = [coqc_prog] + list(coqc_prog_args)
    pseudocmds = ''
    input_val = None
    if is_coqtop:
        if pass_on_stdin:
            input_val = contents
            cmds.extend(['-q'])
            pseudocmds = '" < "%s' % file_name
        else:
            cmds.extend(['-load-vernac-source', file_name_root, '-q'])
    else:
        cmds.extend([file_name, '-q'])
    if kwargs['verbose'] >= verbose_base:
        kwargs['log']('\nRunning command: "%s%s"' % ('" "'.join(cmds), pseudocmds))

    if key in COQ_OUTPUT.keys():
        for i in COQ_OUTPUT[key][1].split(sep): yield i

    p = Popen_async(cmds, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, stdin=subprocess.PIPE)

    so_far = []
    cur = ''
    yielded = True
    completed = False
    while True:
        if yielded and not completed:
            if input_val:
                i = input_val.index('\n') + 1 if '\n' in input_val else len(input_val)
                if kwargs['verbose'] >= 3: print(input_val[:i], end='')
                p.stdin.write(input_val[:i])
                input_val = input_val[i:]
                p.stdin.flush()
                yielded = False
            else:
                completed = True
                p.stdin.close()
        curv = p.stdout.get(True)
        if kwargs['verbose'] >= 3: print(curv, end='')
        cur += curv
        if sep in cur:
            vals = cur.split(sep)
            for val in vals[:-1]:
                yield val
                yielded = True
                so_far.append(val)
            cur = vals[-1]
    if cur != '':
        yield cur
        so_far.append(cur)
    clean_v_file(file_name)
    ## remove instances of the file name
    #stdout = stdout.replace(os.path.basename(file_name[:-2]), 'Top')
    COQ_OUTPUT[key] = (file_name, (clean_output(sep.join(so_far)), tuple(cmds), None))