pub struct LuaSource<I> { /* 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. Nor does it list a path the source’s
IgnoreRules report ignored, an ignore file included.
§Examples
use std::collections::BTreeMap;
use std::fs;
use std::path::PathBuf;
use buildl_core::{
BuildFile, DeclarationSource, Directory, Discovered, Evaluated, NothingIgnored, 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,
NothingIgnored,
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<I: IgnoreRules + Clone + Send + 'static> LuaSource<I>
impl<I: IgnoreRules + Clone + Send + 'static> LuaSource<I>
Sourcepub fn new(
root: impl Into<PathBuf>,
limits: DeclarationLimits,
skipped: impl IntoIterator<Item = Directory>,
ignore: I,
plugins: BTreeMap<PluginName, PathBuf>,
) -> Self
pub fn new( root: impl Into<PathBuf>, limits: DeclarationLimits, skipped: impl IntoIterator<Item = Directory>, ignore: I, plugins: BTreeMap<PluginName, PathBuf>, ) -> Self
A source for the workspace at root, evaluating under limits, whose buildl.sources
stays out of skipped and of every path ignore reports ignored, 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.
ignore is asked about each entry the walk meets, by its workspace-relative path and
kind, after the skipped directories are ruled out; an entry whose workspace-relative path
is not UTF-8 is not asked. The walk neither lists, enters nor counts an entry it reports
ignored, and a build file whose own directory is ignored gets an empty list. An error from
ignore stops the walk and refuses the buildl.sources call with the error’s text. Pass NothingIgnored for a workspace
with no ignore files.
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<I: IgnoreRules + Clone + Send + 'static> DeclarationSource for LuaSource<I>
impl<I: IgnoreRules + Clone + Send + 'static> DeclarationSource for LuaSource<I>
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<I: Eq> Eq for LuaSource<I>
impl<I: PartialEq> StructuralPartialEq for LuaSource<I>
Auto Trait Implementations§
impl<I> Forget for LuaSource<I>
impl<I> Freeze for LuaSource<I>where
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
NonZero<u64>: Freeze,
PhantomData<Directory>: Freeze,
I: Freeze,
*const LeafNode<PluginName, PathBuf> is !null: Freeze,
PhantomData<(Owned, LeafOrInternal)>: Freeze,
PhantomData<Box<(PluginName, PathBuf)>>: Freeze,
impl<I> Move for LuaSource<I>
impl<I> RefUnwindSafe for LuaSource<I>
impl<I> Send for LuaSource<I>
impl<I> Sync for LuaSource<I>
impl<I> Unpin for LuaSource<I>
impl<I> UnsafeUnpin for LuaSource<I>where
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
NonZeroU64Inner: UnsafeUnpin,
PhantomData<Directory>: UnsafeUnpin,
I: UnsafeUnpin,
*const LeafNode<PluginName, PathBuf> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(PluginName, PathBuf)>>: UnsafeUnpin,
impl<I> UnwindSafe for LuaSource<I>where
RawVecInner: UnwindSafe,
NonZero<u64>: UnwindSafe,
I: UnwindSafe,
BTreeMap<PluginName, PathBuf>: UnwindSafe,
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<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