(sigil build module-deps)
(sigil build module-deps) - Module Dependency Tracking
This library provides dependency tracking for .sgl modules to enable:
- Correct build ordering (dependencies compiled before dependents)
- Incremental builds (skip unchanged modules via mtime checks)
- Future tree-shaking support for bundles
Example usage: (define source-files (glob "src/**/*.sgl")) (define lib-paths '("build/lib" "~/.sigil/lib")) (compile-modules-incremental source-files "build/lib" lib-paths)
Exports
extract-module-importsprocedureExtract import declarations from a .sgl source file. Returns a list of library names (each is a list of symbols). Example: ((sigil io) (sigil path) (srfi srfi-9))
read-file-formsprocedureRead all s-expressions from a file. Returns #f if file cannot be read.
extract-imports-from-formsprocedureExtract imports from a list of top-level forms. Looks for (define-library ...) or (library ...) forms.
extract-imports-from-libraryprocedureExtract imports from a define-library form. Handles: (define-library (name) (import ...) (export ...) ...)
extract-import-setsprocedureExtract library names from import sets. Handles import set modifiers: only, except, prefix, rename
unwrap-import-setprocedureUnwrap import set modifiers to get the base library name. (only (lib name) ...) -> (lib name) (except (lib name) ...) -> (lib name) (prefix (lib name) ...) -> (lib name) (rename (lib name) ...) -> (lib name)
extract-library-nameprocedureExtract library name from a define-library form. Returns the library name as a list of symbols.
library-name-to-pathprocedureConvert a library name to a relative file path. (sigil io) -> "sigil/io" (srfi srfi-9) -> "srfi/srfi-9"
resolve-module-pathprocedureResolve a library name to a file path. First searches source-files for .sgl, then lib-paths for .sgb. Returns: (cons 'source path) | (cons 'compiled path) | #f
find-source-fileprocedureFind a source file matching the library path. Checks for .sgl extension.
find-compiled-fileprocedureFind a compiled file in lib-paths. Checks each path for <lib-path>/<rel-path>.sgb
build-module-graphprocedureBuild a dependency graph for source files. Returns an alist of (source-path . (list of dependency paths)) Dependencies can be source paths or compiled paths.
resolve-dependenciesprocedureResolve a list of imports to dependency paths. Filters out external dependencies that can't be resolved.
topological-sort-modulesprocedureTopologically sort source files by dependencies. Returns files in order: dependencies before dependents. Only sorts source files; compiled dependencies are not included in output.
sort-modules-by-depsprocedureSort source files by their dependencies. Simple wrapper that builds the graph and returns sorted file list. source-files: list of .sgl file paths lib-paths: list of paths to search for compiled dependencies Returns: source files in dependency order (dependencies first)
filter-source-depsprocedureFilter graph to only include source file dependencies. Removes compiled (.sgb) dependencies.
kahn-process-modulesprocedureKahn's algorithm main loop (module-specific version).
decrement-in-degrees-modulesprocedureDecrement in-degrees for a list of nodes.
detect-module-cyclesprocedureDetect cycles in module dependency graph. Returns list of nodes involved in cycles, or empty list.
module-needs-compile?procedureCheck if a module needs to be recompiled. Returns #t if:
- Output .sgb doesn't exist
- Source .sgl is newer than output .sgb
- Any dependency (source or compiled) is newer than output
- Any source dependency was recompiled this session
any-recompiled?procedureCheck if any dependency was recompiled this session.
any-dep-newer?procedureCheck if any compiled dependency is newer than output.
compile-modules-incrementalprocedureCompile modules in dependency order with incremental support. source-files: list of .sgl file paths output-dir: directory for .sgb output files lib-paths: list of paths to search for compiled dependencies glob-base: base directory for computing relative paths (optional) force?: if #t, recompile everything regardless of mtime
Returns: (list compiled-files skipped-files)
ensure-directoryprocedureEnsure directory exists