Coverage for apio/commands/apio_build.py: 100%
22 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-06 10:20 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-06 10:20 +0000
1# -*- coding: utf-8 -*-
2# -- This file is part of the Apio project
3# -- (C) 2016-2024 FPGAwars
4# -- Authors
5# -- * Jesús Arroyo (2016-2019)
6# -- * Juan Gonzalez (obijuan) (2019-2024)
7# -- License GPLv2
8"""Implementation of 'apio build' command"""
10import sys
11from typing import Optional
12from pathlib import Path
13import click
14from apio.utils import cmd_util
15from apio.managers.scons_manager import SConsManager
16from apio.commands import options
17from apio.common.proto.apio_pb2 import Verbosity
18from apio.apio_context import (
19 ApioContext,
20 PackagesPolicy,
21 ProjectPolicy,
22 RemoteConfigPolicy,
23)
25# ------------ apio build
27# -- Text in the rich-text format of the python rich library.
28APIO_BUILD_HELP = """
29The command 'apio build' processes the project’s synthesis source files and \
30generates a bitstream file, which can then be uploaded to your FPGA.
32Examples:[code]
33 apio build # Typical usage
34 apio build -e debug # Set the apio.ini env.
35 apio build -v # Verbose info (all)
36 apio build --verbose-synth # Verbose synthesis info
37 apio build --verbose-pnr # Verbose place and route info[/code]
39NOTES:
40* The files are sorted in a deterministic lexicographic order.
41* You can specify the name of the top module in apio.ini.
42* The build command ignores testbench files (*_tb.v, and *_tb.sv).
43* It is unnecessary to run 'apio build' before 'apio upload'.
44* To force a rebuild from scratch use the command 'apio clean' first.
45"""
48@click.command(
49 name="build",
50 cls=cmd_util.ApioCommand,
51 short_help="Synthesize the bitstream.",
52 help=APIO_BUILD_HELP,
53)
54@click.pass_context
55@options.env_option_gen()
56@options.project_dir_option
57@options.verbose_option
58@options.verbose_synth_option
59@options.verbose_pnr_option
60def cli(
61 _: click.Context,
62 # Options
63 env: Optional[str],
64 project_dir: Optional[Path],
65 verbose: bool,
66 verbose_synth: bool,
67 verbose_pnr: bool,
68):
69 """Implements the apio build command. It invokes the toolchain
70 to synthesize the source files into a bitstream file.
71 """
73 # -- Create the apio context.
74 apio_ctx = ApioContext(
75 project_policy=ProjectPolicy.PROJECT_REQUIRED,
76 remote_config_policy=RemoteConfigPolicy.CACHED_OK,
77 packages_policy=PackagesPolicy.ENSURE_PACKAGES,
78 project_dir_arg=project_dir,
79 env_arg=env,
80 )
82 # -- Create the scons manager.
83 scons = SConsManager(apio_ctx)
85 # -- Build the project with the given parameters
86 exit_code = scons.build(
87 Verbosity(all=verbose, synth=verbose_synth, pnr=verbose_pnr)
88 )
90 # -- Done!
91 sys.exit(exit_code)
94# Advanced notes: https://github.com/FPGAwars/apio/wiki/Commands#apio-build