Beispiel #1
0
def literate(args):
    # Redirect stdout to stderr for `literate`
    real_stdout = sys.stdout
    sys.stdout = sys.stderr

    debug = os.environ.get('C2RUST_MANUAL_DEBUG_REFACTOR') == '1'

    # Make sure the c2rust binary we're about to run is up to date
    print('building c2rust...', file=sys.stderr)
    with local.cwd(os.path.join(ROOT_DIR)):
        if debug:
            cargo['build']()
        else:
            cargo['build', '--release']()

    if debug:
        args = ['-d'] + args

    if 'C2RUST_MANUAL_LITERATE_ARGS' in os.environ:
        args = shlex.split(os.environ['C2RUST_MANUAL_LITERATE_ARGS']) + args

    sys.path.append(os.path.join(ROOT_DIR, 'c2rust-refactor/doc'))
    with tempfile.TemporaryDirectory() as td:
        cmd_args = ['render'] + args + [os.path.join(td, 'out.md')]
        import literate
        literate.main(cmd_args)
        with open(os.path.join(td, 'out.md')) as f:
            result = f.read()

    sys.stdout = real_stdout
    return result
Beispiel #2
0
import os
import sys

if __name__ == '__main__':
    sys.path.append(os.path.dirname(__file__))
    from literate import main
    main(sys.argv[1:])