pub struct LuaSource { /* private fields */ }Expand description
Evaluates build files on the airsl embedded runtime, one fresh engine per file.
A build file runs on airsl’s minimal Lua surface with no grants, under limits. It sees
the buildl module table as both buildl and airsstack.buildl, and the curated modules
json, path, regex, hash and glob under airsstack.
buildl.use(name) loads the plugin the source was built with a directory for under that name,
and refuses any other name. A plugin runs under its own environment, narrowed from the build
file’s, and every declaration it makes carries the plugin as its origin.
buildl.discover declares a discovery target. buildl.discovered(label) returns, as a Lua
string, the bytes the map handed to evaluate holds for that
target, or nil; a relative label resolves against the build file’s directory.
buildl.sources never lists a file under a directory the source was built to skip. A source
built with the workspace’s output and state directories therefore keeps a build file at the
workspace root from seeing what the build wrote.
§Examples
use std::collections::BTreeMap;
use std::fs;
use std::path::PathBuf;
use buildl_core::{BuildFile, DeclarationSource, Directory, Discovered, Evaluated, Provenance};
use buildl_lua::{DeclarationLimits, LuaSource};
let workspace = tempfile::tempdir()?;
let root = fs::canonicalize(workspace.path())?;
fs::write(root.join("build.lua"), "buildl.alias('default', 'app')")?;
let skipped = [Directory::parse("out")?, Directory::parse(".buildl")?];
let source = LuaSource::new(&root, DeclarationLimits::default(), skipped, BTreeMap::new());
let file = BuildFile::new(Provenance::new(PathBuf::from("build.lua"), Directory::root()));
assert!(matches!(
source.evaluate(&file, &Discovered::empty())?,
Evaluated::Staged(staged) if staged.declarations.len() == 1
));Implementations§
Source§impl LuaSource
impl LuaSource
Sourcepub fn new(
root: impl Into<PathBuf>,
limits: DeclarationLimits,
skipped: impl IntoIterator<Item = Directory>,
plugins: BTreeMap<PluginName, PathBuf>,
) -> Self
pub fn new( root: impl Into<PathBuf>, limits: DeclarationLimits, skipped: impl IntoIterator<Item = Directory>, plugins: BTreeMap<PluginName, PathBuf>, ) -> Self
A source for the workspace at root, evaluating under limits, whose buildl.sources
stays out of skipped and whose buildl.use loads the plugins in plugins.
root must be the workspace root’s canonical, absolute path. buildl.sources walks
beneath it and refuses any directory that resolves outside it.
skipped names workspace-relative directories. The walk neither lists, enters nor counts
anything inside one. Each is matched by its whole path from the workspace root, so out
skips <root>/out and not <root>/lib/out. A build file whose own directory is a skipped
directory, or lies inside one, gets an empty list from buildl.sources. An empty skipped
skips nothing: the walk then lists the workspace’s own output and state directories too.
plugins maps each plugin name a build file may use to the directory holding its
extension.toml. The caller has already checked the directories, so this source reads
them as given. A plugin’s require stays inside its own directory, however that directory
is reached.
Trait Implementations§
Source§impl DeclarationSource for LuaSource
impl DeclarationSource for LuaSource
Source§fn evaluate(
&self,
file: &BuildFile,
discovered: &Discovered,
) -> Result<Evaluated>
fn evaluate( &self, file: &BuildFile, discovered: &Discovered, ) -> Result<Evaluated>
Evaluates file; buildl.discovered reads discovered.
A file that does not exist is Evaluated::Absent.
§Errors
Returns Error::Evaluation when the file cannot be read, is not UTF-8, does not parse,
raises, is refused an operation, reaches a ceiling, calls a buildl primitive with
arguments it does not accept, or uses a plugin that is unknown, cyclic, malformed or
raises. A refusal from a primitive is reported even when the build
file caught it with pcall and carried on.
impl Eq for LuaSource
impl StructuralPartialEq for LuaSource
Auto Trait Implementations§
impl Freeze for LuaSource
impl RefUnwindSafe for LuaSource
impl Send for LuaSource
impl Sync for LuaSource
impl Unpin for LuaSource
impl UnsafeUnpin for LuaSource
impl UnwindSafe for LuaSource
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more