Skip to content
Snippets Groups Projects
__main__.py 5.18 KiB
Newer Older
# -*- coding: utf-8 -*-
#
# Copyright (c) 2011 Pawel Szostek (pawel.szostek@cern.ch)
#
#    This source code is free software; you can redistribute it
#    and/or modify it in source code form under the terms of the GNU
#    General Public License as published by the Free Software
#    Foundation; either version 2 of the License, or (at your option)
#    any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
#

from connection import Connection
Pawel Szostek's avatar
Pawel Szostek committed
import optparse
Pawel Szostek's avatar
Pawel Szostek committed
from module import Module
from fetch import ModulePool
Pawel Szostek's avatar
Pawel Szostek committed
    parser = optparse.OptionParser()
Pawel Szostek's avatar
Pawel Szostek committed

    parser.add_option("--manifest-help", action="store_true",
    dest="manifest_help", help="print manifest file variables description")

    parser.add_option("--make-sim", dest="make_sim", action="store_true",
    default=None, help="generate a simulation Makefile")
    parser.add_option("--make-fetch", dest="make_fetch", action="store_true",
    default=None, help="generate a makefile for modules' fetching")
    parser.add_option("--make-ise", dest="make_ise", action="store_true",
    default=None, help="generate a makefile for local ISE synthesis")

    parser.add_option("--make-remote", dest="make_remote", action="store_true",
    default=None, help="generate a makefile for remote synthesis")
Pawel Szostek's avatar
Pawel Szostek committed
    parser.add_option("-f", "--fetch", action="store_true", dest="fetch",
Paweł Szostek's avatar
Paweł Szostek committed
    default=None, help="fetch and/or update remote modules listed in Manifet")
    parser.add_option("--clean", action="store_true", dest="clean",
Paweł Szostek's avatar
Paweł Szostek committed
    default=None, help="remove all modules fetched for this one")
    parser.add_option("--list", action="store_true", dest="list",
    default=None, help="List all modules together with their files")
    
    parser.add_option("--list-files", action="store_true", dest="list_files",
    default=None, help="List all files in a from of a space-separated string")
    parser.add_option("--ise-proj", action="store_true", dest="ise_proj",
Pawel Szostek's avatar
Pawel Szostek committed
    default=None, help="create/update an ise project including list of project"
        "files")
Pawel Szostek's avatar
Pawel Szostek committed
    parser.add_option("-l", "--synthesize-locally", dest="local",
Paweł Szostek's avatar
Paweł Szostek committed
    default=None, action="store_true", help="perform a local synthesis")
Pawel Szostek's avatar
Pawel Szostek committed

    parser.add_option("-r", "--synthesize-remotelly", dest="remote",
Paweł Szostek's avatar
Paweł Szostek committed
    default=None, action="store_true", help="perform a remote synthesis")
Pawel Szostek's avatar
Pawel Szostek committed

    parser.add_option("--synth-server", dest="synth_server",
Pawel Szostek's avatar
Pawel Szostek committed
    default=None, help="use given SERVER for remote synthesis",
        metavar="SERVER")
Pawel Szostek's avatar
Pawel Szostek committed

    parser.add_option("--synth-user", dest="synth_user",
    default=None, help="use given USER for remote synthesis", metavar="USER")

    parser.add_option("--force-ise", dest="force_ise",
Pawel Szostek's avatar
Pawel Szostek committed
    default=None, type=float, help="Force given ISE version to be used in"
        " synthesis,use 0 for current version", metavar="ISE")
    parser.add_option("--py", dest="arbitrary_code",
    default="", help="add arbitrary code to all manifests' evaluation")

    parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
    default="false", help="verbose mode")
Pawel Szostek's avatar
Pawel Szostek committed
    (options, _) = parser.parse_args()
    global_mod.options = options
    if options.manifest_help == True:
        from helper_classes import ManifestParser
        ManifestParser().help()
        quit()
Pawel Szostek's avatar
Pawel Szostek committed
    p.vprint("LoadTopManifest")
    pool = ModulePool()
Pawel Szostek's avatar
Pawel Szostek committed
    top_module = Module(parent=None, url=os.getcwd(), source="local",
        fetchto=".", pool=pool)
    pool.set_top_module(top_module)
Pawel Szostek's avatar
Pawel Szostek committed
    if top_module.manifest == None:
        p.echo("No manifest found. At least an empty one is needed")
Pawel Szostek's avatar
Pawel Szostek committed
    global_mod.top_module = top_module
    global_mod.top_module.parse_manifest()
    global_mod.global_target = global_mod.top_module.target
Pawel Szostek's avatar
Pawel Szostek committed
    ssh = Connection(ssh_user=options.synth_user,
        ssh_server=options.synth_server)
    from hdlmake_kernel import HdlmakeKernel
    kernel = HdlmakeKernel(modules_pool=pool, connection=ssh, options=options)
Pawel Szostek's avatar
Pawel Szostek committed

    options_kernel_mapping = {
        "fetch" : "fetch",
        "make_sim" : "generate_modelsim_makefile",
        "ise_proj" : "generate_ise_project",
        "local" : "run_local_synthesis",
        "remote": "run_remote_synthesis",
        "make_fetch": "generate_fetch_makefile",
        "make_ise" : "generate_ise_makefile",
        "make_remote" : "generate_remote_synthesis_makefile",
        "list" : "list_modules",
        "clean" : "clean_modules"
    }
    sth_chosen = False
    for option, function in options_kernel_mapping.items():
        try:
Pawel Szostek's avatar
Pawel Szostek committed
            is_set = getattr(options, option)
                sth_chosen = True
Paweł Szostek's avatar
Paweł Szostek committed
                getattr(kernel, function)()
Pawel Szostek's avatar
Pawel Szostek committed
        except Exception, unknown_error :
            print unknown_error
        kernel.run()
if __name__ == "__main__":
    main()