Skip to main content

LuaSource

Struct LuaSource 

Source
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>

Source

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: Clone> Clone for LuaSource<I>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<I: Debug> Debug for LuaSource<I>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I: IgnoreRules + Clone + Send + 'static> DeclarationSource for LuaSource<I>

Source§

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.

Source§

impl<I: Eq> Eq for LuaSource<I>

Source§

impl<I: PartialEq> PartialEq for LuaSource<I>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<I: PartialEq> StructuralPartialEq for LuaSource<I>

Auto Trait Implementations§

§

impl<I> Forget for LuaSource<I>

§

impl<I> Freeze for LuaSource<I>

§

impl<I> Move for LuaSource<I>

§

impl<I> RefUnwindSafe for LuaSource<I>

§

impl<I> Send for LuaSource<I>
where I: Send, RawVecInner: Send, NonZero<u64>: Send, NodeRef<Owned, PluginName, PathBuf, LeafOrInternal>: Send, BoxRaw<(PluginName, PathBuf)>: Send,

§

impl<I> Sync for LuaSource<I>
where I: Sync, RawVecInner: Sync, NonZero<u64>: Sync, NodeRef<Owned, PluginName, PathBuf, LeafOrInternal>: Sync, BoxRaw<(PluginName, PathBuf)>: Sync,

§

impl<I> Unpin for LuaSource<I>
where I: Unpin, *const u8 is !null: Unpin, NonZero<u64>: Unpin, *const LeafNode<PluginName, PathBuf> is !null: Unpin, Box<(PluginName, PathBuf)>: Unpin,

§

impl<I> UnsafeUnpin for LuaSource<I>

§

impl<I> UnwindSafe for LuaSource<I>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.