Skip to content

Commit

Permalink
Create build directories automatically and unify directory and file o…
Browse files Browse the repository at this point in the history
…ptions handling

Signed-off-by: Krzysztof Obłonczek <[email protected]>
  • Loading branch information
koblonczek committed Feb 12, 2024
1 parent 9c79403 commit 5c0943e
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions fpga_topwrap/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,24 @@
from .verilog_parser import VerilogModuleGenerator, ipcore_desc_from_verilog_module
from .vhdl_parser import VHDLModule, ipcore_desc_from_vhdl_module

click_dir = click.Path(exists=True, file_okay=False, dir_okay=True, readable=True)
click_opt_dir = click.Path(exists=False, file_okay=False, dir_okay=True, readable=True)
click_file = click.Path(exists=True, file_okay=True, dir_okay=False, readable=True)
click_r_dir = click.Path(exists=True, file_okay=False, dir_okay=True, readable=True)
click_opt_rw_dir = click.Path(
exists=False, file_okay=False, dir_okay=True, readable=True, writable=True
)
click_r_file = click.Path(exists=True, file_okay=True, dir_okay=False, readable=True)

main = click.Group(help="FPGA Topwrap")


@main.command("build", help="Generate top module")
@click.option(
"--sources", "-s", type=click_dir, help="Specify directory to scan for additional sources"
"--sources", "-s", type=click_r_dir, help="Specify directory to scan for additional sources"
)
@click.option("--design", "-d", type=click_file, required=True, help="Specify top design file")
@click.option("--design", "-d", type=click_r_file, required=True, help="Specify top design file")
@click.option(
"--build-dir",
"-b",
type=click_opt_dir,
type=click_opt_rw_dir,
default="build",
help="Specify directory name for output files",
)
Expand All @@ -51,6 +53,8 @@ def build_main(sources, design, build_dir, part, iface_compliance):
"and thus your implamentation may fail."
)

# following function does make sure that build directory exists
# so we don't explicitly create build directory here
build_design_from_yaml(design, build_dir, sources, part)


Expand All @@ -73,21 +77,22 @@ def build_main(sources, design, build_dir, part, iface_compliance):
@click.option(
"--dest-dir",
"-d",
type=click_dir,
type=click_opt_rw_dir,
default="./",
help="Destination directory for generated yamls",
)
@click.argument("files", type=click_file, nargs=-1)
@click.argument("files", type=click_r_file, nargs=-1)
def parse_main(use_yosys, iface_deduce, iface, files, dest_dir):
logging.basicConfig(level=logging.INFO)
dest_dir = os.path.dirname(dest_dir)
dest_dir = Path(dest_dir)
dest_dir.mkdir(exist_ok=True, parents=True)

for filename in list(filter(lambda name: os.path.splitext(name)[-1] == ".v", files)): # noqa
modules = VerilogModuleGenerator().get_modules(filename)
iface_grouper = InterfaceGrouper(use_yosys, iface_deduce, iface)
for verilog_mod in modules:
ipcore_desc = ipcore_desc_from_verilog_module(verilog_mod, iface_grouper)
yaml_path = os.path.join(dest_dir, f"gen_{ipcore_desc.name}.yaml")
yaml_path = dest_dir / f"gen_{ipcore_desc.name}.yaml"
ipcore_desc.save(yaml_path)
logging.info(
f"Verilog module '{verilog_mod.get_module_name()}'" f"saved in file '{yaml_path}'"
Expand All @@ -100,7 +105,7 @@ def parse_main(use_yosys, iface_deduce, iface, files, dest_dir):
vhdl_mod = VHDLModule(filename)
iface_grouper = InterfaceGrouper(False, iface_deduce, iface)
ipcore_desc = ipcore_desc_from_vhdl_module(vhdl_mod, iface_grouper)
yaml_path = os.path.join(dest_dir, f"gen_{ipcore_desc.name}.yaml")
yaml_path = dest_dir / f"gen_{ipcore_desc.name}.yaml"
ipcore_desc.save(yaml_path)
logging.info(f"VHDL Module '{vhdl_mod.get_module_name()}'" f"saved in file '{yaml_path}'")

Expand All @@ -117,26 +122,28 @@ def parse_main(use_yosys, iface_deduce, iface, files, dest_dir):
@main.command("kpm_client", help="Run a client app, that connects to" "a running KPM server")
@click.option("--host", "-h", default=DEFAULT_SERVER_ADDR, help="KPM server address")
@click.option("--port", "-p", default=DEFAULT_SERVER_PORT, help="KPM server listening port")
@click.argument("yamlfiles", type=click_file, nargs=-1)
@click.argument("yamlfiles", type=click_r_file, nargs=-1)
def kpm_client_main(host, port, yamlfiles):
kpm_run_client(host, port, yamlfiles)


@main.command("kpm_build_server", help="Build KPM server")
@click.option(
"--workspace-directory",
type=click.Path(),
type=click_opt_rw_dir,
default=DEFAULT_WORKSPACE_DIR,
help="Directory where the frontend sources should be stored",
)
@click.option(
"--output-directory",
type=click.Path(),
type=click_opt_rw_dir,
default=DEFAULT_FRONTEND_DIR,
help="Directory where the built frontend should be stored",
)
@click.pass_context
def kpm_build_server(ctx, workspace_directory, output_directory):
Path(workspace_directory).mkdir(exist_ok=True, parents=True)
Path(output_directory).mkdir(exist_ok=True, parents=True)
args = ["pipeline_manager", "build", "server-app"]
for k, v in ctx.params.items():
args += [f"--{k}".replace("_", "-"), f"{v}"]
Expand All @@ -146,7 +153,7 @@ def kpm_build_server(ctx, workspace_directory, output_directory):
@main.command("kpm_run_server", help="Run a KPM server")
@click.option(
"--frontend-directory",
type=click.Path(),
type=click_r_dir,
default=DEFAULT_FRONTEND_DIR,
help="Location of the built frontend",
)
Expand Down

0 comments on commit 5c0943e

Please sign in to comment.