Beispiel #1
0
def main():
    """
    Parse command line options and launch the RSL interpreter.
    """
    parser = optparse.OptionParser(
        usage="%prog [options] script.arc",
        version=rsl.version.complete_string,
        formatter=optparse.TitledHelpFormatter(),
    )
    parser.add_option(
        "-i",
        "--import",
        dest="imports",
        metavar="PATH",
        help="import model information from PATH",
        action="append",
        default=[],
    )
    parser.add_option(
        "-I",
        "--include",
        dest="includes",
        metavar="PATH",
        help="add PATH to list of dirs to search for include files",
        action="append",
        default=["./"],
    )
    parser.add_option(
        "-e",
        "--emit",
        dest="emit",
        metavar="WHEN",
        choices=["never", "change", "always"],
        action="store",
        help="choose when to emit (never, change, always)",
        default="change",
    )
    parser.add_option(
        "-f", "--force", dest="force", action="store_true", help="make read-only emit files writable", default=False
    )
    parser.add_option(
        "-d",
        "--diff",
        dest="diff",
        metavar="PATH",
        action="store",
        help="save a diff of all emits to PATH",
        default=None,
    )
    parser.add_option(
        "-v", "--verbosity", dest="verbosity", action="count", help="increase debug logging level", default=1
    )

    (opts, args) = parser.parse_args()
    if len(args) == 0:
        parser.print_help()
        sys.exit(1)

    levels = {0: logging.ERROR, 1: logging.WARNING, 2: logging.INFO, 3: logging.DEBUG}
    logging.basicConfig(level=levels.get(opts.verbosity, logging.DEBUG))

    loader = xtuml.load.ModelLoader()
    loader.build_parser()

    for filename in opts.imports:
        loader.filename_input(filename)

    id_generator = xtuml.IntegerGenerator()
    metamodel = loader.build_metamodel(id_generator)

    if opts.diff:
        with open(opts.diff, "w") as f:
            f.write(" ".join(sys.argv))
            f.write("\n")

    rt = rsl.Runtime(metamodel, opts.emit, opts.force, opts.diff)
    for filename in args:
        ast = rsl.parse_file(filename)
        rsl.evaluate(rt, ast, opts.includes)
Beispiel #2
0
 def eval_text(self, text, filename=''):
     ast = rsl.parse_text(text + '\n', filename)
     try:
         rsl.evaluate(self.runtime, ast, self.includes)
     except SystemExit as e:
         return e.code
Beispiel #3
0
def run_build(working_directory='.',
              gen_workspace='code_generation',
              output_directory='src',
              variant='c',
              model_inputs=[]):

    # setup build
    print('MC-3020: Setting up build environment...')
    working_directory = os.path.abspath(
        working_directory)  # resolve working directory path
    gen_workspace = os.path.abspath(
        gen_workspace)  # resolve gen workspace path
    os.environ['ROX_MC_ARC_DIR'] = os.path.join(
        gen_workspace, 'arc')  # set archetype directory
    output_directory = os.path.abspath(output_directory)  # resolve output path
    if not os.path.exists(output_directory):
        os.makedirs(output_directory)

    # prepare gen workspace
    print('MC-3020: Preparing generation workspace...')
    if os.path.exists(gen_workspace):
        shutil.rmtree(gen_workspace)
    if not os.path.exists(gen_workspace):
        os.makedirs(gen_workspace)

    # copy archetypes
    print('MC-3020: Installing model compiler archetypes...')
    if not os.path.exists(os.path.join(gen_workspace, 'arc')):
        os.makedirs(os.path.join(gen_workspace, 'arc'))
    for arcfile in filter(
            lambda path: not os.path.isdir(os.path.join(ARCDIR, path)),
            os.listdir(ARCDIR)):
        shutil.copyfile(os.path.join(ARCDIR, arcfile),
                        os.path.join(gen_workspace, 'arc', arcfile))
    if os.path.exists(os.path.join(ARCDIR, variant)) and os.path.isdir(
            os.path.join(ARCDIR, variant)):
        for arcfile in filter(
                lambda path: not os.path.isdir(
                    os.path.join(ARCDIR, variant, path)),
                os.listdir(os.path.join(ARCDIR, variant))):
            shutil.copyfile(os.path.join(ARCDIR, variant, arcfile),
                            os.path.join(gen_workspace, 'arc', arcfile))

    # copy marking files
    print('MC-3020: Installing user marks...')
    for markfile in filter(lambda path: os.path.splitext(path)[1] == '.mark',
                           os.listdir(os.path.join(SCHEMADIR, 'colors'))):
        shutil.copyfile(os.path.join(SCHEMADIR, 'colors', markfile),
                        os.path.join(gen_workspace, markfile))
    shutil.copyfile(os.path.join(SCHEMADIR, 'colors', 'sys_functions.arc'),
                    os.path.join(gen_workspace, 'sys_functions.arc'))
    for user_markfile in filter(
            lambda path: os.path.splitext(path)[1] == '.mark',
            os.listdir(working_directory)):
        shutil.copyfile(os.path.join(working_directory, user_markfile),
                        os.path.join(gen_workspace, user_markfile))

    # execute pre-build
    print('MC-3020: Pre-building...')
    model = bridgepoint.load_metamodel(model_inputs)
    bridgepoint.prebuild_model(model)
    xtuml.persist_instances(model, os.path.join(gen_workspace, 'a.sql'))

    # execute code generation
    print('MC-3020: Generating code...')
    os.chdir(gen_workspace)
    id_generator = xtuml.IntegerGenerator()
    model = xtuml.MetaModel(id_generator)
    loader = xtuml.ModelLoader()
    loader.filename_input(os.path.join(SCHEMADIR, 'sql', 'xtumlmc_schema.sql'))
    loader.filename_input(os.path.join(gen_workspace, 'a.sql'))
    loader.populate(model)
    rt = rsl.Runtime(model, 'change', True, None)
    ast = rsl.parse_file(os.path.join(gen_workspace, 'arc', 'sys.arc'))
    rsl.evaluate(rt, ast, ['.'])

    # copy generated sources to output directory
    print('MC-3020: Installing generated sources...')
    custom_implementations = []
    try:
        with open(os.path.join(working_directory, 'custom.txt')) as f:
            custom_implementations = list(
                map(lambda s: s.strip(), f.readlines()))
    except:
        print('MC-3020: No custom sources found...')
    for src_file in filter(
            lambda path: os.path.splitext(path)[1] in ['.h', '.c'],
            os.listdir(os.path.join(gen_workspace, '_ch'))):
        if src_file in custom_implementations:
            shutil.copyfile(os.path.join(gen_workspace, '_ch', src_file),
                            os.path.join(output_directory, src_file + '.orig'))
        else:
            shutil.copyfile(os.path.join(gen_workspace, '_ch', src_file),
                            os.path.join(output_directory, src_file))

    print('MC-3020: Done.')
Beispiel #4
0
 def eval_text(self, text, filename=''):
     ast = rsl.parse_text(text + '\n', filename)
     try:
         rsl.evaluate(self.runtime, ast, self.includes)
     except SystemExit as e:
         return e.code
Beispiel #5
0
def main():
    '''
    Parse command line options and launch mc3020.
    '''
    usage_example = 'Example: %s -o %s %s' % (
        sys.argv[0], 'src', 'gen/code_generation/MicrowaveOven.sql')

    parser = optparse.OptionParser(usage="%prog [options] model.sql",
                                   formatter=optparse.TitledHelpFormatter(),
                                   epilog=usage_example)

    parser.set_description(__doc__.strip())

    parser.add_option("-m",
                      "--markings",
                      dest="markings",
                      metavar="PATH",
                      help="use markings from PATH",
                      action="store",
                      default=None)

    parser.add_option("-e",
                      "--emit",
                      dest='emit',
                      metavar="WHEN",
                      choices=['never', 'change', 'always'],
                      action="store",
                      help="choose when to emit (never, change, always)",
                      default='change')

    parser.add_option("-f",
                      "--force",
                      dest='force',
                      action="store_true",
                      help="make read-only emit files writable",
                      default=False)

    parser.add_option("-o",
                      "--output",
                      dest='output',
                      metavar="PATH",
                      action="store",
                      help="emit source code to PATH",
                      default='.')

    parser.add_option("-d",
                      "--diff",
                      dest='diff',
                      metavar="PATH",
                      action="store",
                      help="save a diff of all emits to PATH",
                      default=None)

    parser.add_option("-l",
                      "--lang",
                      dest='lang',
                      metavar="LANG",
                      choices=['c', 'sysc'],
                      action="store",
                      help="choose language to generate in (c, sysc)",
                      default='c')

    (opts, args) = parser.parse_args()
    if len(args) == 0:
        parser.print_help()
        sys.exit(1)

    logging.basicConfig(level=logging.INFO)

    dirname = os.path.dirname(__file__) + '/..'
    dirname = os.path.abspath(dirname)

    sqlfiles = list(args)
    sqlfiles.append(dirname + '/schema/sql/xtumlmc_schema.sql')

    metamodel = xtuml.load_metamodel(sqlfiles)
    fix_incorrect_phrases(metamodel)

    langdir = dirname + '/arc/' + opts.lang
    includes = [dirname + '/arc', langdir, dirname + '/schema/colors']

    if opts.markings:
        includes.insert(0, opts.markings)

    if opts.diff:
        with open(opts.diff, 'w') as f:
            f.write(' '.join(sys.argv))
            f.write('\n')

    if not os.path.exists(opts.output):
        os.mkdir(opts.output)

    rsl.runtime.put_env_var('.', 'ROX_MC_ARC_DIR')
    rt = rsl.Runtime(metamodel, opts.emit, opts.force, opts.diff)
    ast = rsl.parse_file(langdir + '/sys.arc')

    os.chdir(opts.output)
    rsl.evaluate(rt, ast, includes)
def run_rsl(m, filename):
    rt = rsl.Runtime(m)
    tree = rsl.parse_file(filename)
    res = rsl.evaluate(rt, tree, [arcdir])
    return rt.buffer.getvalue()
Beispiel #7
0
def main():
    '''
    Parse command line options and launch mc3020.
    '''
    usage_example = 'Example: %s -o %s %s' % (sys.argv[0], 'src',
                                              'gen/code_generation/MicrowaveOven.sql')
    
    parser = optparse.OptionParser(usage="%prog [options] model.sql",
                                   formatter=optparse.TitledHelpFormatter(),
                                   epilog=usage_example)

    parser.set_description(__doc__.strip())
    
    parser.add_option("-m", "--markings", dest="markings", metavar="PATH",
                      help="use markings from PATH", action="store", default=None)

    parser.add_option("-e", "--emit", dest='emit', metavar="WHEN",
                      choices=['never', 'change', 'always'], action="store",
                      help="choose when to emit (never, change, always)", default='change')
    
    parser.add_option("-f", "--force", dest='force', action="store_true",
                      help="make read-only emit files writable", default=False)

    parser.add_option("-o", "--output", dest='output', metavar="PATH", action="store",
                      help="emit source code to PATH", default='.')
    
    parser.add_option("-d", "--diff", dest='diff', metavar="PATH", action="store",
                      help="save a diff of all emits to PATH", default=None)

    parser.add_option("-l", "--lang", dest='lang', metavar="LANG",
                      choices=['c', 'sysc'], action="store",
                      help="choose language to generate in (c, sysc)", default='c')
    
    (opts, args) = parser.parse_args()
    if len(args) == 0:
        parser.print_help()
        sys.exit(1)

    logging.basicConfig(level=logging.INFO)

    dirname = os.path.dirname(__file__) + '/..'
    dirname = os.path.abspath(dirname)

    sqlfiles = list(args)
    sqlfiles.append(dirname + '/schema/sql/xtumlmc_schema.sql')

    metamodel = xtuml.load_metamodel(sqlfiles)
    fix_incorrect_phrases(metamodel)

    langdir = dirname + '/arc/' + opts.lang
    includes = [dirname + '/arc',
                langdir,
                dirname + '/schema/colors']
    
    if opts.markings:
        includes.insert(0, opts.markings)
        
    if opts.diff:
        with open(opts.diff, 'w') as f:
            f.write(' '.join(sys.argv))
            f.write('\n')

    if not os.path.exists(opts.output):
        os.mkdir(opts.output)
    
    rsl.runtime.put_env_var('.', 'ROX_MC_ARC_DIR')
    rt = rsl.Runtime(metamodel, opts.emit, opts.force, opts.diff)
    ast = rsl.parse_file(langdir + '/sys.arc')

    os.chdir(opts.output)
    rsl.evaluate(rt, ast, includes)