docstr: Pre-build emscripten ports.
docstr_tok: ["Pre-build","emscripten","ports","."]
code: def build_emports(self, force: bool = False) -> None:
      """Pre-build emscripten ports."""
      platform = self.host.platform
      if platform.ports is None or platform.cc is None:
          raise ValueError("Need ports and CC command")
  
      embuilder_cmd = [os.fspath(platform.ports)]
      embuilder_cmd.extend(self.host.embuilder_args)
      if force:
          embuilder_cmd.append("--force")
  
      ports_cmd = [os.fspath(platform.cc)]
      ports_cmd.extend(self.host.emport_args)
      if self.target:
          ports_cmd.extend(self.target.emport_args)
  
      if self.dynamic_linking:
          # Trigger PIC build.
          ports_cmd.append("-sMAIN_MODULE")
          embuilder_cmd.append("--pic")
  
      if self.pthreads:
          # Trigger multi-threaded build.
          ports_cmd.append("-sUSE_PTHREADS")
  
      # Pre-build libbz2, libsqlite3, libz, and some system libs.
      ports_cmd.extend(["-sUSE_ZLIB", "-sUSE_BZIP2", "-sUSE_SQLITE3"])
      # Multi-threaded sqlite3 has different suffix
      embuilder_cmd.extend(
          [
              "build",
              "bzip2",
              "sqlite3-mt" if self.pthreads else "sqlite3",
              "zlib",
          ]
      )
  
      self._run_cmd(embuilder_cmd, cwd=SRCDIR)
  
      with tempfile.TemporaryDirectory(suffix="-py-emport") as tmpdir:
          tmppath = pathlib.Path(tmpdir)
          main_c = tmppath / "main.c"
          main_js = tmppath / "main.js"
          with main_c.open("w") as f:
              f.write("int main(void) { return 0; }\n")
          args = [
              os.fspath(main_c),
              "-o",
              os.fspath(main_js),
          ]
          self._run_cmd(ports_cmd, args, cwd=tmppath)
  
imports: import argparse
  import enum
  import dataclasses
  import logging
  import os
  import pathlib
  import re
  import shlex
  import shutil
  import socket
  import subprocess
  import sys
  import sysconfig
  import tempfile
  import time
  import warnings
  import webbrowser
  from typing import cast, Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
label_desc: Use image node_id 18 for calling the BuildProfile obj's underlying member method code with example usage: obj.build_emports(force) without return types