Initial Commit
This commit is contained in:
28 files changed
+6914
No files matched your search
@@ -0,0 +1,186 @@
|
||||
#! @file project.sakura
|
||||
#! @author John Christman (sorakatadzuma@gmail.com)
|
||||
#! @copyright Malunal Studios, LLC.
|
||||
#! @license MIT
|
||||
#!
|
||||
#! Contains what a blossomfile says of a project: who it is, its options, what
|
||||
#! it requires, its targets and tests, what it exports, how it installs, and how
|
||||
#! it is packaged.
|
||||
import std::io;
|
||||
|
||||
module blossom::models;
|
||||
|
||||
#! An option of a project, and the value it has, as the text written.
|
||||
pub struct setting {
|
||||
pub var name: string;
|
||||
pub var value: string;
|
||||
}
|
||||
|
||||
#! What a target is.
|
||||
pub enum target_kind: u8 {
|
||||
program, #! A program, built into an executable.
|
||||
library, #! A folder of modules, which programs read through `--lib`.
|
||||
}
|
||||
|
||||
#! Where a test runs.
|
||||
pub enum runner: u8 {
|
||||
machine, #! On the machine, by `sakura run`.
|
||||
native, #! Built into an executable, which is then run.
|
||||
}
|
||||
|
||||
#! A target or a test of a project.
|
||||
pub struct target {
|
||||
pub var name: string;
|
||||
pub var kind: target_kind;
|
||||
pub var level: u32 = 2; #! `-O`, from 0 to 2.
|
||||
pub var petal: bool; #! Whether it's built with `-g`.
|
||||
pub var system: string; #! What it's built for, as `windows-x86_64`, or empty for the system blossom runs on.
|
||||
pub var deps: vector<string>; #! The libraries it reads, by name, `std` among them or not.
|
||||
pub var srcs: vector<string>; #! Its files, folders, and globs, relative to the project.
|
||||
pub var opts: vector<string>; #! What's given to `sakura` as written.
|
||||
pub var root: string; #! A library's folder, relative to the project.
|
||||
pub var runs: runner; #! Where a test runs.
|
||||
pub var checks: bool; #! Whether a test's memory is checked as it runs.
|
||||
pub var args: vector<string>; #! What a test is given.
|
||||
pub var title: string; #! What a program is called where it's shown, or empty for its name.
|
||||
pub var icons: vector<string>; #! The PNG, SVG, and icon files a program is shown by, relative to the project.
|
||||
pub var windowed: bool; #! Whether a program runs in windows of its own, with no console or terminal.
|
||||
pub var member: string; #! The folder of the member it's written in, relative to the project, as its `members` writes it, or empty for the project's own blossomfile.
|
||||
pub var file: path; #! The blossomfile it's written in: the project's, or a member's.
|
||||
pub var line: u32; #! Where it's written.
|
||||
}
|
||||
|
||||
#! Whether a program is shown as a desktop's program: it gives a `title`, an
|
||||
#! `icon`, or `windowed: true`, as a tool run in a terminal gives none of them.
|
||||
#! @param this The target.
|
||||
#! @returns Whether it is.
|
||||
pub val target::shown: bool {
|
||||
get => this.title.length != 0 || this.icons.length != 0 || this.windowed;
|
||||
}
|
||||
|
||||
#! A project another requires.
|
||||
pub struct requirement {
|
||||
pub var remote: string; #! A remote's address, or a folder relative to the blossomfile.
|
||||
pub var branch: string; #! The branch or tag cloned, `main` unless written.
|
||||
pub var local: bool; #! Whether it's a folder rather than a remote.
|
||||
pub var options: vector<setting>; #! The values it's given for its options.
|
||||
pub var file: path; #! The blossomfile it's written in: the project's, or a member's.
|
||||
pub var line: u32; #! Where it's written.
|
||||
}
|
||||
|
||||
#! A member of a project: a folder within it holding a blossomfile of its own,
|
||||
#! which says it's the project's member, and whose targets, tests, and
|
||||
#! requirements are the project's, as though its own blossomfile wrote them.
|
||||
pub struct member {
|
||||
pub var folder: string; #! Its folder, relative to the project, with `/` between names and none at its end, as `engine` or `editor/modeling`.
|
||||
pub var file: path; #! Its blossomfile.
|
||||
}
|
||||
|
||||
#! A step of installing, beside what's installed by default.
|
||||
pub struct step {
|
||||
pub var tag: string; #! What it does, as `!include`.
|
||||
pub var source: string; #! What it takes, relative to the project.
|
||||
pub var dest: string; #! Where it goes under the prefix, or empty for the source's own place.
|
||||
pub var line: u32; #! Where it's written.
|
||||
}
|
||||
|
||||
#! How a project is described in its packages.
|
||||
pub struct package_info {
|
||||
pub var lic: string; #! Its license, as `MIT`.
|
||||
pub var desc: string; #! What it is, in a line.
|
||||
pub var auth: string; #! Who made it, as `Name <mail>`.
|
||||
pub var url: string; #! Where it lives.
|
||||
}
|
||||
|
||||
#! A project, as its blossomfile says it.
|
||||
pub struct project {
|
||||
pub var name: string;
|
||||
pub var gpid: string;
|
||||
pub var semv: string;
|
||||
pub var folder: path; #! The folder holding its blossomfile, absolute.
|
||||
pub var file: path; #! Its blossomfile.
|
||||
pub var members: vector<member>; #! The folders whose blossomfiles are its members', in the order `members` lists them.
|
||||
pub var options: vector<setting>; #! Its options' values, in the order declared.
|
||||
pub var requires: vector<requirement>;
|
||||
pub var targets: vector<target>;
|
||||
pub var tests: vector<target>;
|
||||
pub var exports: vector<string>; #! The libraries other projects may read.
|
||||
pub var install: vector<step>;
|
||||
pub var package: package_info;
|
||||
pub var key: string; #! Its output folder's name in `.blossom`.
|
||||
}
|
||||
|
||||
#! Who the project is, as `malunal/hello@1.0.0`.
|
||||
#! @param this The project.
|
||||
#! @returns Its group, name, and version.
|
||||
pub val project::identity: string {
|
||||
get => $"{this.gpid}/{this.name}@{this.semv}";
|
||||
}
|
||||
|
||||
#! The folder its outputs for these option values go to.
|
||||
#! @param this The project.
|
||||
#! @returns `.blossom/<key>` within its folder.
|
||||
pub val project::output: path {
|
||||
get => this.folder.join(".blossom").join(this.key.span);
|
||||
}
|
||||
|
||||
#! Finds a target or test by its name.
|
||||
#! @param this The project.
|
||||
#! @param name The name.
|
||||
#! @returns Where it is among the targets, then the tests after them, or
|
||||
#! `nothing` where neither has it.
|
||||
pub def project::find(&this, name: strview): maybe<u64> {
|
||||
for k in 0..this.targets.length {
|
||||
return k if this.targets[k].name.span == name;
|
||||
}
|
||||
for k in 0..this.tests.length {
|
||||
return this.targets.length + k if this.tests[k].name.span == name;
|
||||
}
|
||||
return nothing {};
|
||||
}
|
||||
|
||||
#! A target, or a test after the targets, by where `find` says it is.
|
||||
#! @param this The project.
|
||||
#! @param index Where it is.
|
||||
#! @returns It.
|
||||
pub def project::at(&this, index: u64): &target {
|
||||
if index < this.targets.length {
|
||||
return &this.targets[index];
|
||||
}
|
||||
return &this.tests[index - this.targets.length];
|
||||
}
|
||||
|
||||
#! The member a file of the project belongs to: the one whose folder holds it
|
||||
#! most nearly, as `editor/modeling` rather than `editor` where both are.
|
||||
#! @param this The project.
|
||||
#! @param file The file, relative to the project's folder, with `/` or `\`
|
||||
#! between its names.
|
||||
#! @returns The member's folder, or empty where no member holds it.
|
||||
pub def project::member_holding(&this, file: strview): strview {
|
||||
var best := strview::blank();
|
||||
for &each in this.members {
|
||||
val folder := each.folder.span;
|
||||
continue if folder.length >= file.length || folder.length <= best.length;
|
||||
continue if file[folder.length] != '/' && file[folder.length] != '\\';
|
||||
var same := true;
|
||||
for k in 0..folder.length {
|
||||
val a := file[k] == '\\' ? '/' as u8 : file[k];
|
||||
same = same && a == folder[k];
|
||||
}
|
||||
if same {
|
||||
best = folder;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
#! Whether the project lets others read a library.
|
||||
#! @param this The project.
|
||||
#! @param name The library's name.
|
||||
#! @returns Whether `exports` names it.
|
||||
pub def project::exported(&this, name: strview): bool {
|
||||
for &each in this.exports {
|
||||
return true if each.span == name;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in new issue
Block a user