code: def build_main(argv: Sequence[str]) -> int:
      """Sphinx build "main" command-line entry."""
      parser = get_parser()
      args = _parse_arguments(parser, argv)
      args.confdir = _parse_confdir(
          args.noconfig, args.confdir, args.sourcedir
      )
      args.doctreedir = _parse_doctreedir(
          args.doctreedir, args.outputdir
      )
      _validate_filenames(parser, args.force_all, args.filenames)
      _validate_colour_support(args.color)
      args.status, args.warning, args.error, warnfp = _parse_logging(
          parser, args.quiet, args.really_quiet, args.warnfile
      )
      args.confoverrides = _parse_confoverrides(
          parser, args.define, args.htmldefine, args.nitpicky
      )
  
      app = None
      try:
          confdir = args.confdir or args.sourcedir
          with patch_docutils(confdir), docutils_namespace():
              app = Sphinx(
                  args.sourcedir,
                  args.confdir,
                  args.outputdir,
                  args.doctreedir,
                  args.builder,
                  args.confoverrides,
                  args.status,
                  args.warning,
                  args.freshenv,
                  args.warningiserror,
                  args.tags,
                  args.verbosity,
                  args.jobs,
                  args.keep_going,
                  args.pdb,
              )
              app.build(args.force_all, args.filenames)
              return app.statuscode
      except (Exception, KeyboardInterrupt) as exc:
          handle_exception(app, args, exc, args.error)
          return 2
      finally:
          if warnfp is not None:
              # close the file descriptor for the warnings file opened by Sphinx
              warnfp.close()
  
imports: from __future__ import annotations
  import argparse
  import bdb
  import contextlib
  import locale
  import multiprocessing
  import os
  import pdb
  import sys
  import traceback
  from os import path
  from typing import TYPE_CHECKING, Any, TextIO
  from docutils.utils import SystemMessage
  import sphinx.locale
  from sphinx import __display_version__
  from sphinx.application import Sphinx
  from sphinx.errors import SphinxError, SphinxParallelError
  from sphinx.locale import __
  from sphinx.util._io import TeeStripANSI
  from sphinx.util.console import color_terminal, nocolor, red, terminal_safe
  from sphinx.util.docutils import docutils_namespace, patch_docutils
  from sphinx.util.exceptions import format_exception_cut_frames, save_traceback
  from sphinx.util.osutil import ensuredir
label_desc: Use image node_id 12 for calling a global function with example usage: build_main(argv) and returns: app, int