#! @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; #! The libraries it reads, by name, `std` among them or not. pub var srcs: vector; #! Its files, folders, and globs, relative to the project. pub var opts: vector; #! 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; #! What a test is given. pub var line: u32; #! Where it's written. } #! 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; #! The values it's given for its options. pub var line: u32; #! Where it's written. } #! 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 `. 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 options: vector; #! Its options' values, in the order declared. pub var requires: vector; pub var targets: vector; pub var tests: vector; pub var exports: vector; #! The libraries other projects may read. pub var install: vector; 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/` 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 { 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]; } #! 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; }