Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions notes/adding-a-port.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ In the new worktree, on `docs-site`:

Haskell's [Haddock exporter](../packages/api-model/scripts/export-haskell.py)
builds a selected committed source archive. Its
[adapter](../packages/api-model/src/languages/haskell.ts) accepts three qualified
[adapter](../packages/api-model/src/languages/haskell.ts) accepts four qualified
profiles with the port's pinned GHC/Haddock toolchain:

- Scalar v1 covers `LibTmux.Id`, `LibTmux.Value` and `LibTmux.Version`.
Expand All @@ -167,8 +167,11 @@ profiles with the port's pinned GHC/Haddock toolchain:
- Query v3 adds `LibTmux.Query` and its typed field/relationship modules. Its
[native fixture](../packages/api-model/test/fixtures/haskell-query-native/README.md)
preserves opaque type parameters and constrained signatures.
- Mutation v4 retains the query modules and adds checked rename, pane-title and
recovery declarations. Its [native fixture](../packages/api-model/test/fixtures/haskell-mutations-native/README.md)
qualifies the private defining source of the opaque recovery receipt.

Both retain native signatures, opaque data heads, constructors, record labels,
All profiles retain native signatures, opaque data heads, constructors, record labels,
instance heads and authored export groups. Observation field identities include
their record owner; displayed Haskell names and field types remain native.
Source links use the actual defining files, including private files behind a
Expand Down Expand Up @@ -228,6 +231,12 @@ declaration bounds for the shared evidence audit; it does not infer queued
execution from function names. A changed source, public export or claim fails
qualification until the profile is reviewed again.

Set `LIBTMUX_DOCS_PORT=haskell` and bind `LIBTMUX_DOCS_SOURCE_SHA` and
`LIBTMUX_DOCS_SOURCE_REF` to the selected commit when regenerating this model.
Qualify native command usage against that generated model. An unselected
authoring build can cite the public default branch and produce a different
full-model digest.

Capture selects `ReadSnapshot`, whose fixed queue reaches the native spawner.
It sends `display-message` and `if-shell`; `list-clients` runs when sessions
exist. Graph enumeration uses tmux format loops. The older private scalar and
Expand Down
42 changes: 37 additions & 5 deletions packages/api-model/scripts/export-haskell.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"LibTmux.Internal." + name
for name in ["Capture", "Field", "Graph", "Query", "Runtime", "Scheduler", "Scope", "TmuxText"]
]
MUTATION_ORIGINS = [*QUERY_ORIGINS, "LibTmux.Internal.Mutation"]


def _source_file(module):
Expand Down Expand Up @@ -167,13 +168,22 @@ def extract_modules(pages, installed, exposed, locations, revision):
if observations and exposed not in [OBSERVATION_MODULES, QUERY_MODULES]:
msg = "Unqualified observation module profile"
raise ValueError(msg)
mutations = "LibTmux.Internal.Mutation" in interfaces
if mutations and exposed != QUERY_MODULES:
msg = "Unqualified mutation module profile"
raise ValueError(msg)
source_modules = (
QUERY_ORIGINS
MUTATION_ORIGINS
if mutations
else QUERY_ORIGINS
if exposed == QUERY_MODULES
else OBSERVATION_ORIGINS
if observations
else exposed
)
if set(locations) != set(source_modules):
msg = "Native source inputs differ from the qualified source profile"
raise ValueError(msg)

documents = {module: _Document(pages[module]).root for module in exposed}
page_modules = {module.replace(".", "-") + ".html": module for module in exposed}
Expand Down Expand Up @@ -778,10 +788,20 @@ def field(name):
if modules not in [SCALAR_MODULES, OBSERVATION_MODULES, QUERY_MODULES]:
msg = "Unqualified configured public module profile"
raise ValueError(msg)
mutations = "LibTmux.Internal.Mutation" in field("hidden-modules").split()
if mutations and modules != QUERY_MODULES:
msg = "Unqualified configured mutation module profile"
raise ValueError(msg)
queries = modules == QUERY_MODULES
observations = queries or modules == OBSERVATION_MODULES
source_modules = (
QUERY_ORIGINS if queries else OBSERVATION_ORIGINS if observations else modules
MUTATION_ORIGINS
if mutations
else QUERY_ORIGINS
if queries
else OBSERVATION_ORIGINS
if observations
else modules
)
shown = _command([tools["haddock"], f"--show-interface={interface}"], source_root)
if bool(shown.stdout.strip()) == bool(shown.stderr.strip()):
Expand Down Expand Up @@ -840,12 +860,24 @@ def field(name):
target.parent.mkdir(parents=True, exist_ok=True)
target.write_bytes(data)
return {
"schema": "libtmux.haskell-api/3"
"schema": "libtmux.haskell-api/4"
if mutations
else "libtmux.haskell-api/3"
if queries
else "libtmux.haskell-api/2"
if observations
else "libtmux.haskell-api/1",
**({"profile": "queries/1" if queries else "observations/1"} if observations else {}),
**(
{
"profile": "mutations/1"
if mutations
else "queries/1"
if queries
else "observations/1"
}
if observations
else {}
),
"port": "haskell",
"repo": "libtmux/libtmux-haskell",
"revision": revision,
Expand All @@ -864,7 +896,7 @@ def field(name):
],
"exporter": {
"name": "Haddock public interface export",
"version": 3 if queries else 2 if observations else 1,
"version": 4 if mutations else 3 if queries else 2 if observations else 1,
"build": {
"compiler": plan["compiler-id"],
"cabal": plan["cabal-version"],
Expand Down
8 changes: 5 additions & 3 deletions packages/api-model/src/languages/haskell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const QUERY_MODULES = [...OBSERVATION_MODULES, 'LibTmux.Query',
const QUERY_ORIGINS = [...QUERY_MODULES,
...['Capture', 'Field', 'Graph', 'Query', 'Runtime', 'Scheduler', 'Scope', 'TmuxText']
.map((name) => `LibTmux.Internal.${name}`)]
const MUTATION_ORIGINS = [...QUERY_ORIGINS, 'LibTmux.Internal.Mutation']
const VERSION = /^(?:0|[1-9]\d*)(?:\.(?:0|[1-9]\d*))+$/

function check(condition: unknown, reason: string): asserts condition {
Expand Down Expand Up @@ -110,7 +111,8 @@ function validateSignature(signature: Signature, symbol: NativeSymbol, byId: Map
export function extractHaskellArtifact(input: unknown, expectedRevision?: string): ApiModel {
check(input && typeof input === 'object', 'missing document')
const artifact = structuredClone(input) as HaskellArtifact
const queries = artifact.schema === 'libtmux.haskell-api/3' && artifact.profile === 'queries/1'
const mutations = artifact.schema === 'libtmux.haskell-api/4' && artifact.profile === 'mutations/1'
const queries = mutations || (artifact.schema === 'libtmux.haskell-api/3' && artifact.profile === 'queries/1')
const observations = queries || (artifact.schema === 'libtmux.haskell-api/2' && artifact.profile === 'observations/1')
check((artifact.schema === 'libtmux.haskell-api/1' || observations) && artifact.port === 'haskell' &&
artifact.repo === 'libtmux/libtmux-haskell' && typeof artifact.revision === 'string' && COMMIT.test(artifact.revision),
Expand Down Expand Up @@ -139,14 +141,14 @@ export function extractHaskellArtifact(input: unknown, expectedRevision?: string
}
}
const exporter = artifact.nativeProvenance?.exporter
check(exporter?.name === 'Haddock public interface export' && exporter.version === (queries ? 3 : observations ? 2 : 1) && exporter.repository === 'libtmux/docs' &&
check(exporter?.name === 'Haddock public interface export' && exporter.version === (mutations ? 4 : queries ? 3 : observations ? 2 : 1) && exporter.repository === 'libtmux/docs' &&
typeof exporter.revision === 'string' && COMMIT.test(exporter.revision) &&
exporter.path === 'packages/api-model/scripts/export-haskell.py' && HASH.test(exporter.sha256), 'missing committed producer identity')
check(exporter.build?.compiler === `ghc-${artifact.compiler}` && exporter.build.cabal === '3.18.2.0' &&
exporter.build.unit === `${artifact.package.name}-${artifact.package.version}-inplace` &&
typeof exporter.build.platform === 'string' && /^[\w]+-[\w]+$/.test(exporter.build.platform) &&
['stdout', 'stderr'].includes(exporter.interfaceStream), 'invalid configured native build')
const origins = queries ? QUERY_ORIGINS : observations ? OBSERVATION_ORIGINS : modules
const origins = mutations ? MUTATION_ORIGINS : queries ? QUERY_ORIGINS : observations ? OBSERVATION_ORIGINS : modules
const sourceFile = (module: string) => `${module.startsWith('LibTmux.Internal.') ? 'internal' : 'src'}/${module.replaceAll('.', '/')}.hs`
const sourceFiles = origins.map(sourceFile)
hashedInputs(artifact.nativeProvenance.files, ['.tool-versions', 'cabal.project', 'libtmux-haskell.cabal', ...sourceFiles], 'source inputs')
Expand Down
Loading
Loading