Build, test and release (Mac version)

Requirements

Building and running

Run all commands in macos/.

cd macos
swift build                        # debug build (.build/debug/TeraMac)
./scripts/bundle.sh                # makes "build/Tera Term Mac.app" (for this Mac only; fast)
open "build/Tera Term Mac.app"
./scripts/bundle.sh --universal    # Apple Silicon and Intel
./scripts/bundle.sh --dmg          # universal build, distribution DMG, notarization

When you run a plain swift build binary, UI languages and help are read from the source tree (macos/Resources and upstream installer/release/lang_utf8). Automatic updates only start when Info.plist has SUFeedURL (that is, in an app made by bundle.sh).

What bundle.sh does

  1. Builds with swift build -c release (with --arch arm64 --arch x86_64 for --universal / --dmg) and shrinks the executable with strip -x.
  2. Creates build/Tera Term Mac.app and copies in:
    • Sparkle.framework (without headers and XPC services)
    • the icon (Resources/AppIcon.icns) and LICENSE
    • upstream installer/release/TERATERM.INI (default settings)
    • upstream installer/release/lang_utf8/*.lng and Resources/lang/mac_*.lng (UI languages)
    • upstream installer/release/theme (sample themes)
    • the help in Resources/help-mac/{ja,en} (html/, teraterm.hhp, modern-toc.json) and upstream teraterm/common/helpid.h. Images (*.png) are left out (see help images)
  3. Writes Info.plist. The version is VERSION in bundle.sh (it can also be set with the VERSION environment variable); the bundle ID can be changed with BUNDLE_ID. The .ttl document type and the Sparkle settings (SUFeedURL, public key and so on) are written here too.
  4. Signs the app. If the keychain has a "Developer ID Application" certificate, it is used (Sparkle's parts first, with hardened runtime and timestamp); otherwise the app is ad-hoc signed. The SIGN_ID environment variable selects a certificate.
  5. With --dmg, creates a DMG (build/TeraTermMac-<version>.dmg) containing the app and a link to Applications. The background is drawn by scripts/make_dmg_bg.swift, and Finder is scripted to set the window size and icon positions.
  6. When signed with Developer ID, the DMG is signed as well, notarized with xcrun notarytool and stapled. Store notarytool credentials in the keychain beforehand with xcrun notarytool store-credentials and pass the profile name in the NOTARY_PROFILE environment variable. Notarization is skipped if no stored credentials are found or SKIP_NOTARY=1 is set.

Tests

swift test                                  # all tests
swift test --filter TTLTests                # one test class
swift test --filter TerminalTests/testXxx   # one test

The tests are in Tests/TeraCoreTests and cover TeraCore (terminal emulator, TTL macros, file transfer, TEK, key maps, INI files, connection settings and more).

Self-test environment variables

Starting the app executable ("build/Tera Term Mac.app/Contents/MacOS/TeraMac") with these environment variables makes it check its own appearance or behavior.

VariableBehavior
TERAMAC_SNAPSHOT=<folder>Writes windows and dialogs as PNG files and quits (term.png, about.png, credits.png, connect.png, setup.png, schemes.png, menu_editor.png, menu_details.png and others). Along the way it runs a macro (test.ttl) that connects to the local shell and writes the screen text to shell.txt. The TeraTerm Menu windows are captured with sample entries, and the user's entries are restored at the end. Automatic updates and the offer to move to Applications are suppressed
TERAMAC_TCPPORT=<port>In the TERAMAC_SNAPSHOT macro, connects to that port on 127.0.0.1 as raw TCP and checks that the sent text comes back (provide an echo server)
TERAMAC_SERIAL=<device>In the TERAMAC_SNAPSHOT macro, opens that serial port at 115200 bps, sends serial-ping and waits for serial-pong
TERAMAC_LOGINPORT=<port>With TERAMAC_SNAPSHOT, actually runs a TeraTerm Menu auto login (connects to that port on 127.0.0.1 with /T=0) and writes the screen text to menu_login.txt
TERAMAC_TABSNAP=1Used with TERAMAC_SNAPSHOT. Opens two tabs and captures the whole window (tabs.png), the setup sheet, a live font preview and whether Cancel restores it
TERAMAC_SETUP_SNAPSHOT=<folder>When the Additional settings sheet opens, writes every tab as setup-<number>-<name>.png, plus the TTSSH / TTProxy dialogs
TERAMAC_DEBUG_WINDOWS=<file>Two seconds after launch, writes the visible windows (class, title, size) and the application menu items to the file
TERAMAC_MENUBAR_TEST=<log>Opens the in-window menu bar, moves the mouse to the next title and logs whether the menu switches
TERAMAC_INI_DRYRUN=<ini>Writes the result of importing a TERATERM.INI (applied and skipped settings, hosts, font and more) and quits, without changing settings. Output goes to TERAMAC_INI_OUT (default: standard output)
TERAMAC_TTMENU_TEST=<ttpmenu.ini>Reads ttpmenu.ini, writes it back (<ini>.written.ini), reads it again, writes the result to <ini>.out.txt and quits. Nothing is saved
TERAMAC_FEED_URL=<URL>Changes the appcast.xml that automatic updates check (file:// URLs work)
TERAMAC_UPDATE_TEST=<log>Without UI, checks for an update, downloads it and installs it, logging the steps

In addition, TERAMAC_PROXY_* variables are how the app passes proxy settings to its ssh ProxyCommand (TeraMac --proxy-connect <host> <port>). --purge-keychain is an argument used by the uninstaller; it deletes saved passwords and quits.

Generators

ScriptOutput
scripts/gen_charwidth_tables.pyGenerates Sources/TeraCore/CharWidthTables.swift from upstream unicode_asian_width.tbl, unicode_combine.tbl and unicode_emoji.tbl in teraterm/teraterm.
python3 scripts/gen_charwidth_tables.py [teraterm/teraterm folder]
scripts/gen_sbcs_tables.pyGenerates Sources/TeraCore/SBCSTables.swift from upstream teraterm/teraterm/mapping/*.map.
python3 scripts/gen_sbcs_tables.py [mapping folder]
scripts/notes2html.pyConverts release notes (the same Markdown as on GitHub Releases) into HTML for Sparkle's update window. Only paragraphs, headings, bullet lists, code, bold and links are supported. Called by appcast.sh.
python3 scripts/notes2html.py notes.md > notes.html
scripts/make_icon.swiftMakes AppIcon.iconset from the upstream icon (teraterm/common/teraterm.ico)
scripts/make_dmg_bg.swiftDraws the DMG background (called by bundle.sh)

Do not edit the generated .swift files by hand; run the scripts again instead.

Release flow

  1. Bump VERSION in scripts/bundle.sh.
  2. Build the DMG with ./scripts/bundle.sh --dmg (signed and notarized).
  3. Create v<version> on GitHub Releases and upload TeraTermMac-<version>.dmg.
  4. Run ./scripts/appcast.sh <version> build/TeraTermMac-<version>.dmg [notes.md] to rewrite macos/appcast.xml, and push it to main. The app watches this appcast.xml (SUFeedURL in Info.plist) to find new versions.

appcast.sh signs the DMG with an EdDSA (ed25519) signature using Sparkle's sign_update (default tools/sparkle/sign_update, taken from bin/ of a Sparkle release; override with SIGN_UPDATE). The private key is read from a key file rather than the keychain; its location can be set with the SPARKLE_KEY environment variable. The matching public key is SUPublicEDKey in Info.plist, so losing the private key means updates can no longer be delivered to existing installs. Keep a safe backup.

appcast.xml lists only the latest version. If release notes are given, they appear as the update's notes in the update window (.md is converted with notes2html.py; .html is used as is).