|
root / src / types.reef
types.reef Reef 400 lines 9.6 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
/******************************************************************************
               __               ____                __
              / /   ___  ____ _/ __/_____________ _/ /__
             / /   / _ \/ __ `/ /_/ ___/ ___/ __ `/ / _ \
            / /___/  __/ /_/ / __(__  ) /__/ /_/ / /  __/
           /_____/\___/\__,_/_/ /____/\___/\__,_/_/\___/

   (C)opyright 2025, Leafscale, LLC -  https://www.leafscale.com

   Project: Zygaena
  Filename: types.reef
   Authors: Chris Tusa <chris.tusa@leafscale.com>
   License: <see LICENSE file included with this source code>
Description: Shared type definitions for Coral package manager

******************************************************************************/

module types

export
    // Path getter functions (constants can't be exported across modules)
    fn get_ports_dir(): string
    fn get_sources_dir(): string
    fn get_packages_dir(): string
    fn get_build_dir(): string
    fn get_db_dir(): string
    fn get_index_dir(): string
    fn get_repos_dir(): string
    fn get_config_file(): string
    fn get_groups_dir(): string
    // Legacy (for compatibility)
    fn get_work_dir(): string
    fn get_pkg_dir(): string

    // Types
    type PackageInfo
    type Dependencies
    type Source
    type SourceInfo
    type PatchInfo
    type ConfigInfo
    type ScriptsInfo
    type BuildConfig
    type Port
    type InstalledPackage
    type BuildResult
    type GlobalOptions
    type PackageGroup
    type PortResult

    // Factory functions
    fn new_package_info(): PackageInfo
    fn new_dependencies(): Dependencies
    fn new_global_options(): GlobalOptions
    fn new_source(): Source
    fn new_source_info(): SourceInfo
    fn new_patch_info(): PatchInfo
    fn new_config_info(): ConfigInfo
    fn new_scripts_info(): ScriptsInfo
    fn new_build_config(): BuildConfig
    fn new_port(): Port
    fn new_port_result(ok: bool, p: Port, err: string): PortResult
    fn new_installed_package(): InstalledPackage
    fn new_package_group(): PackageGroup
end export

// Zygaena/Coral filesystem paths
// Ports tree and build artifacts
const PORTS_DIR: string = "/usr/zports"
const GROUPS_DIR: string = "/usr/zports/groups"
const SOURCES_DIR: string = "/usr/zports/pkgs/sources"
const PACKAGES_DIR: string = "/usr/zports/pkgs/packages"
const BUILD_DIR: string = "/usr/zports/pkgs/build"

// System state (in /var/lib)
const DB_DIR: string = "/var/lib/coral/installed"
const INDEX_DIR: string = "/var/lib/coral/db"
const REPOS_DIR: string = "/var/lib/coral/repos"

// Configuration
const CONFIG_FILE: string = "/etc/coral/coral.conf"

// Legacy aliases (for compatibility during transition)
const WORK_DIR: string = "/usr/zports/pkgs/build"
const PKG_DIR: string = "/usr/zports/pkgs/build"

// Package metadata from package.toml
type PackageInfo = struct
    name: string
    version: string
    release: int
    description: string
    url: string
    license: string
    maintainer: string
    arch: string
    alternatives: [string]
    alternatives_count: int
    conflicts: [string]
    conflicts_count: int
    runtime_deps: [string]
    build_deps: [string]
    runtime_deps_count: int
    build_deps_count: int
end PackageInfo

// Dependencies
type Dependencies = struct
    runtime: [string]
    build: [string]
    runtime_count: int
    build_count: int
end Dependencies

// Individual source file with mirror support
type Source = struct
    file: string        // Output filename (what to save as)
    urls: [string]      // Mirror URLs (tried in order)
    url_count: int      // Number of URLs
    checksum: string    // SHA256 checksum (or "SKIP")
    extract: bool       // Whether to extract archive (default: true)
end Source

// Collection of source files to download
type SourceInfo = struct
    sources: [Source]   // Array of Source structs
    count: int          // Number of sources
end SourceInfo

// Patch configuration
type PatchInfo = struct
    files: [string]
    strip: int
    count: int
end PatchInfo

// Config file protection
type ConfigInfo = struct
    files: [string]
    count: int
end ConfigInfo

// Install/remove scripts
type ScriptsInfo = struct
    pre_install: string
    post_install: string
    pre_remove: string
    post_remove: string
end ScriptsInfo

// Build configuration
type BuildConfig = struct
    parallel: bool
    jobs: int
end BuildConfig

// Complete port definition
type Port = struct
    info: PackageInfo
    deps: Dependencies
    sources: SourceInfo
    patches: PatchInfo
    config: ConfigInfo
    scripts: ScriptsInfo
    build_cfg: BuildConfig
    port_dir: string
    category: string
    // Per-package path overrides (from package.toml [paths] section)
    prefix: string
    sysconfdir: string
end Port

// Installed package record
type InstalledPackage = struct
    info: PackageInfo
    install_date: string
    install_reason: string
    files: [string]
    files_count: int
end InstalledPackage

// Build result
type BuildResult = struct
    success: bool
    package_path: string
    error_message: string
end BuildResult

// Global CLI options
type GlobalOptions = struct
    yes: bool
    force: bool
    verbose: bool
    dry_run: bool
    quiet: bool
    root: string
    prefix: string
    no_chroot: bool  // --no-chroot-scripts: run maintainer scripts on the host, not chrooted
    cmd_index: int  // Index of the command in args (for subcommand parsing)
end GlobalOptions

// Package group (meta-package)
type PackageGroup = struct
    name: string
    description: string
    members: [string]
    members_count: int
end PackageGroup

// Parse result wrapper
type PortResult = struct
    success: bool
    port: Port
    error: string
end PortResult

// Initialize empty PackageInfo
fn new_package_info(): PackageInfo
    return PackageInfo{
        name: "",
        version: "",
        release: 1,
        description: "",
        url: "",
        license: "",
        maintainer: "",
        arch: "x86_64",
        alternatives: new [string](0),
        alternatives_count: 0,
        conflicts: new [string](0),
        conflicts_count: 0,
        runtime_deps: new [string](64),
        build_deps: new [string](64),
        runtime_deps_count: 0,
        build_deps_count: 0
    }
end new_package_info

// Initialize empty Dependencies
fn new_dependencies(): Dependencies
    return Dependencies{
        runtime: new [string](0),
        build: new [string](0),
        runtime_count: 0,
        build_count: 0
    }
end new_dependencies

// Initialize empty GlobalOptions with defaults
fn new_global_options(): GlobalOptions
    return GlobalOptions{
        yes: false,
        force: false,
        verbose: false,
        dry_run: false,
        quiet: false,
        root: "",
        prefix: "",
        no_chroot: false,
        cmd_index: 1
    }
end new_global_options

// Initialize empty Source
fn new_source(): Source
    return Source{
        file: "",
        urls: new [string](16),
        url_count: 0,
        checksum: "SKIP",
        extract: true
    }
end new_source

// Initialize empty SourceInfo
fn new_source_info(): SourceInfo
    return SourceInfo{
        sources: new [Source](16),
        count: 0
    }
end new_source_info

// Initialize empty PatchInfo
fn new_patch_info(): PatchInfo
    return PatchInfo{
        files: new [string](0),
        strip: 1,
        count: 0
    }
end new_patch_info

// Initialize empty ConfigInfo
fn new_config_info(): ConfigInfo
    return ConfigInfo{
        files: new [string](0),
        count: 0
    }
end new_config_info

// Initialize empty ScriptsInfo
fn new_scripts_info(): ScriptsInfo
    return ScriptsInfo{
        pre_install: "",
        post_install: "",
        pre_remove: "",
        post_remove: ""
    }
end new_scripts_info

// Initialize default BuildConfig
fn new_build_config(): BuildConfig
    return BuildConfig{
        parallel: true,
        jobs: 0
    }
end new_build_config

// Initialize empty Port
fn new_port(): Port
    return Port{
        info: new_package_info(),
        deps: new_dependencies(),
        sources: new_source_info(),
        patches: new_patch_info(),
        config: new_config_info(),
        scripts: new_scripts_info(),
        build_cfg: new_build_config(),
        port_dir: "",
        category: "",
        prefix: "",
        sysconfdir: ""
    }
end new_port

// Create a PortResult
fn new_port_result(ok: bool, p: Port, err: string): PortResult
    return PortResult{
        success: ok,
        port: p,
        error: err
    }
end new_port_result

// Path getter functions
fn get_ports_dir(): string
    return PORTS_DIR
end get_ports_dir

fn get_sources_dir(): string
    return SOURCES_DIR
end get_sources_dir

fn get_packages_dir(): string
    return PACKAGES_DIR
end get_packages_dir

fn get_build_dir(): string
    return BUILD_DIR
end get_build_dir

fn get_db_dir(): string
    return DB_DIR
end get_db_dir

fn get_index_dir(): string
    return INDEX_DIR
end get_index_dir

fn get_repos_dir(): string
    return REPOS_DIR
end get_repos_dir

fn get_config_file(): string
    return CONFIG_FILE
end get_config_file

fn get_groups_dir(): string
    return GROUPS_DIR
end get_groups_dir

// Legacy aliases (for compatibility during transition)
fn get_work_dir(): string
    return BUILD_DIR
end get_work_dir

fn get_pkg_dir(): string
    return BUILD_DIR
end get_pkg_dir

// Initialize empty InstalledPackage
fn new_installed_package(): InstalledPackage
    return InstalledPackage{ info: new_package_info(), install_date: "", install_reason: "", files: new [string](0), files_count: 0 }
end new_installed_package

fn new_package_group(): PackageGroup
    return PackageGroup{ name: "", description: "", members: new [string](256), members_count: 0 }
end new_package_group

end module