# blossom blossom builds Sakura projects, as chinook builds C ones. A `blossomfile` in a project's folder says who the project is, what it requires, and its targets and tests. blossom reads it and those of what it requires, then runs `sakura` for each step: one command a program. ```sh blossom build # check the project's libraries, then build its programs blossom check # check each target, writing nothing blossom run -- 3 4 # run the project's program on the machine, given `3 4` blossom test --suite geometry # build, then run the suites whose names hold `geometry` blossom test --test cubes # build, then run the tests whose names hold `cubes` blossom clean --all # remove .blossom blossom install --prefix ~/.local blossom package -f tar,deb # write packages into .blossom//dist blossom pull binary # clone a requirement, or with no name, all of them blossom libraries # print the --lib of each library the project reads ``` ## Building blossom Until blossom has built itself once, the compiler builds it, given the standard library it reads, checked out beside this repository: ```sh sakurac build -O2 -o blossom --lib std=../std \ entry.sakura models/*.sakura management/*.sakura pipeline/*.sakura ``` After that, `blossom build` builds it from its blossomfile, and `blossom test` runs its tests: those of its parts, and those of its commands, which run the blossom just built on projects made in a folder of each test's own. The command tests run `git`, `sh`, and `tar`, so they run on Linux. ## Commands | Command | Does | |---|---| | `build [PROJECT]` | Checks the project's libraries, then builds each program into `.blossom//bin`, where it isn't up to date | | `check [PROJECT]` | Checks each target, libraries and programs, writing nothing | | `run [TARGET] [-- ARG...]` | Runs a program on the machine, `sakura run`: the one named, or the project's only one | | `test [PROJECT] [--suite TEXT] [--test TEXT]` | Builds, then runs each suite, the project's `tests`, or those whose names hold the suite's text, showing what they write; of each, only the tests whose names hold the test's text | | `clean [PROJECT] [--all]` | Removes the outputs of these option values, `.blossom/`, or with `--all`, all of `.blossom` | | `install [PROJECT] [--prefix DIR] [--destdir DIR]` | Builds, then installs into `~/.local` or the prefix, under the destination folder where given | | `package [PROJECT] [-f FORMAT[,FORMAT]] [--prefix DIR]` | Installs into `.blossom//stage`, then writes `tar`, `zip`, `deb`, `arch`, or `rpm` packages into `dist` | | `pull [REQUIREMENT...] [--project DIR] [--update]` | Clones what the project requires, or the requirements named, and what their libraries read, where the store is missing them; with `--update`, clones them again | | `libraries [PROJECT]` | Prints the `--lib` of each library the project holds or reads, a line each, with its folder absolute, then `--missing` for each requirement the store is missing | Each takes: - `-o NAME=VALUE`, giving the project's option a value; - `--target linux-x86_64|windows-x86_64`, building every target for that system; - `-j N`, given to `sakura`; - `-v`, printing each command run. Each step says how it went, a line each, with what `sakura` and the tests write passed on as they write it: ``` [1/3] Checked hello.geometry [2/3] Built hello (.blossom/3f2a9c01d4e5b677/bin/hello) 3 passed, 0 failed, 0 skipped [3/3] Tested hello.tests (3 passed) Tested malunal/hello@1.0.0 ``` A step that fails says `Failed NAME`, and a program reading a library that failed to check says `Skipped NAME`. blossom ends with 0 where everything worked, 1 where a build, a test, or a clone failed, and 2 where the command or a blossomfile is wrong, with the file and the line. `run` ends with the program's own status. **`pull`** clones what a project requires, as a build would, without building anything. A requirement is named as its blossomfile writes it, with or without `@REF`, or by the last part of its path: - `binary` names `https://git.malunal.studio/sakura/binary@v1.0.0`; - `shapes` names `../shapes`. What a requirement's libraries read is pulled with it. It says where each requirement is, whether it was there already, cloned, or with `--update` cloned again, which a branch that moved wants. A tag doesn't move. A clone made again takes the old one's place only once it's whole: ``` $ blossom pull Cloning https://git.malunal.studio/sakura/binary@v1.0.0 [1/2] Present https://git.malunal.studio/sakura/std@v1.0.0 (/home/me/.cache/blossom/...) [2/2] Cloned https://git.malunal.studio/sakura/binary@v1.0.0 (/home/me/.cache/blossom/...) Pulled what malunal/hello@1.0.0 requires ``` **`libraries`** is for tools, as the Sakura extension for VS Code, which gives each library to its language server. Each line is a `--lib` as `sakura` takes it: - the project's own libraries come first; - then those its targets and tests read through `deps`, each followed by what it reads in turn. It clones nothing. Each remote the store is missing gets a line `--missing REMOTE@REF` after them, and the libraries it holds are left out until `pull` clones it. It needs no `sakura`, since it runs none, and otherwise refuses what a build refuses: ``` $ blossom libraries --lib hello::geometry=/home/me/hello/geometry --lib std::io=/home/me/.cache/blossom/git.malunal.studio/sakura/std@v1.0.0/io --missing https://git.malunal.studio/sakura/binary@v1.0.0 ``` ## The blossomfile YAML, in the project's folder: ```yaml name: hello # required; the identity is gpid/name@semv gpid: malunal # required semv: 1.0.0 # required; a version, as 1.2.0 or 1.2.0-alpha options: # NAME: value, any scalar; ${NAME} anywhere after; -o NAME=VALUE level: 2 # ${bin} is given too: this option set's .blossom//bin debug: false members: # folders of the project, each holding a member's blossomfile - shapes requires: - https://git.malunal.studio/sakura/std@v1.0.0 # REMOTE@REF; `main` without a ref - ../shapes # a folder, relative to this file - remote: https://git.malunal.studio/sakura/binary # a block, where it's given options branch: v1.0.0 options: strict: true targets: - name: hello # a program type: program level: ${level} # -O: 0, 1, or 2; 2 unless given petal: ${debug} # -g, writing hello.petal beside it target: windows-x86_64 # --target; the system blossom runs on unless given deps: [std.io, std.yaml, hello.geometry] # libraries it reads; `std` alone is what the compiler finds srcs: [main.sakura, util/**/*.sakura] # files, folders (each .sakura in them), globs opts: [--inline, "24"] # given to `sakura build` as written title: Hello # how a desktop's program is shown: its name, icon: [hello.png, hello.svg] # its icon's files, .png, .svg, or .ico, windowed: true # and in windows of its own, not a console - name: hello.geometry # a library: the module hello::geometry type: library root: ./hello.geometry # ./ unless given deps: [std.math] # libraries its modules import tests: - name: hello.tests # the keys of targets, and these type: program runs: machine # machine, by `sakura run`, unless native: built, then run checks: true # `--checks`; on unless given, on the machine deps: [hello.geometry] srcs: [tests/**/*.sakura] # tests/**/*.sakura unless given args: [--only, geometry] # what the test is given exports: # the libraries other projects may read - hello.geometry install: # beside the programs and the exported libraries - !include ./share # to /share - !include ./docs:share/doc/hello # to /share/doc/hello package: lic: MIT desc: Says hello. auth: Me url: https://example.com/hello ``` - **Every key is checked:** one blossom doesn't know, or one written twice in a mapping, which YAML would keep only one of, is refused by its line. - **A library's name is its module's,** with `.` for `::`. Its folder is given to `sakura` with `--lib`, as `--lib hello::geometry=hello.geometry`, and the compiler reads only the modules a program imports. Two projects giving a library one name is refused, as is a program reading a library another project doesn't export. - **A program shown as a desktop's program** gives a `title`, an `icon`, or `windowed: true`; one run in a terminal, as a tool, gives none of them and is built as ever. - `title` is its name where it's shown, its own `name` unless given. - `icon` names its icon's files, relative to the project: a file, a list of them, or several in one text with `,` between them, as an option's value names them, since `${NAME}` is replaced in a value's text once the YAML is read, so `-o icon=[a.png,b.png]` is one text, never a list. Each is a PNG, of any size, an SVG, or an icon file, `.ico`; an empty text names none. - `windowed` is `true` or `false`, as written or as an option gives it. - Built for Windows, the program holds them itself: blossom gives `sakura build` its `--title`, the project's `semv` as `--semv`, each PNG and icon file as `--icon`, and `--windowed`, so Explorer, its shortcuts, and its windows show its icon, Task Manager and its properties its title and version, and no console opens for it. A PNG wider or taller than 256 pixels, as one meant for Linux, is left out there. - Built for Linux, `install` and `package` put them beside it, as [Installing and packaging](#installing-and-packaging) says. - Each may be an option, so what builds the program, as an editor exporting a game, gives them with `-o`: `title: ${title}`, `icon: ${icon}`, `windowed: ${windowed}`. An empty title or icon is none. - **`install`'s steps** are each tagged with what they do. `!include SOURCE` copies a file or folder to its own place under the prefix, and `!include SOURCE:DEST` to `DEST`. A step without a tag, with one blossom doesn't know, or reaching outside the project or the prefix, is refused. ## Members A project too large for one blossomfile is split among members: folders within it, each holding a blossomfile of its own that says what that part holds, what it needs, and what tests it. The project's blossomfile lists them in `members`, and each says whose member it is, so a blossomfile is clearly a member's from either side: ```yaml # shapes/blossomfile member: hello # required: the project whose `members` lists this folder requires: # as a project's; a folder relative to this file - ../../extra targets: - name: hello.shapes # paths are the member's: this library's root is shapes/ type: library root: . deps: [extra.numbers] tests: - name: hello.shapes.tests # srcs: tests/**/*.sakura, within shapes/ type: program deps: [hello.shapes] ``` - **A member's blossomfile** takes `member`, `requires`, `targets`, and `tests`, and nothing else: the project's name, version, options, exports, installing, and packaging are the project's. A member's own `${NAME}` are the project's options, and `-o` reaches them. - **Members are merged into the project,** as though its own blossomfile wrote them: one name for each target and test across them all, `build`, `check`, and `test` covering every member, `--suite` and `--test` choosing among them, `exports` naming their libraries, and a project requiring this one reading every member's. Their paths are their own folders', but their programs and tests run in the project's folder, as every target's do, and their outputs are the project's, in its `.blossom`. - **Run in a member's folder,** blossom finds the project above it whose `members` lists it, and `build`, `check`, `run`, and `test` keep to that member's targets and tests; `clean`, `install`, `package`, `pull`, and `libraries` take the whole project. - **A library's files** are those within its root, but those within another member's folder, and those its member's tests and programs list in their `srcs`, which are theirs, so a member's tests sit beside its library in its folder. - **A member's blossomfile changing** builds its project again, as the project's does. ## Requirements - **A remote** is what `git` clones, as `https://host/path`, `git@host:path`, or `file:///path`, and is cloned once, `git clone -b REF --depth 1`, into the store: `~/.cache/blossom//@`, or `$XDG_CACHE_HOME/blossom/...`, and `%LOCALAPPDATA%\blossom\...` on Windows. A clone stopped halfway is never taken for one, and where git fails, what it says is shown. The store can be removed at any time: what's missing is cloned again. `pull` clones without building, and `pull --update` clones again what the store holds. - **A folder** is read where it is, relative to the blossomfile naming it. - **One project, two sets of option values,** is refused, since each set builds outputs of its own. - **What a requirement requires** is read only where its libraries read what it doesn't hold itself, so what only its tests or programs need is never fetched for those requiring it. ## Outputs and building again Each project's outputs go to `.blossom/`, the key being the hash of its identity, its option values, and `--target`, so each set builds apart. A program is built again only where: - its executable is missing; - the command building it changed, which is kept beside it in `.command`, with the `sakura` that ran it and when that was written; - a file `sakura` read building it, as `--deps` lists them in `.deps`, or the blossomfile, is newer than it. A library's check is kept the same way, in `.blossom//check`. ## Tests A suite, each of the project's `tests`, runs on the machine, `sakura run --checks ... -- ARGS`, unless it says `runs: native`, where it's built, then run. It passes where it ends with 0. Each runs in the project's folder, with `SAKURA` naming the `sakura` blossom runs, so a test can run the compiler as blossom does. - **`--suite TEXT`** runs only the suites whose names hold the text; none holding it is a mistake in the command, ending with 2. - **`--test TEXT`** gives each suite run `--only TEXT` after its own `args`, so a suite of `std::testing`'s runs only the tests whose names hold the text, as `std::testing` reads it; a later `--only` takes the place of one its `args` gave. A suite that says it ran none is said as `Tested NAME (none named with `TEXT`)`, and none of them running one is a mistake in the command, ending with 2, as a suite named by none is. A suite of its own runner is given the same, and reads it or not. ## Installing and packaging `install` builds, then copies each program to `/bin`, with its `.petal`, each exported library to `/share/sakura/`, as source another project's `--lib` reads, then does each step of `install`. A program built for Linux and shown as a desktop's program, by its `title`, `icon`, or `windowed`, is installed as Linux's desktops find one, by the freedesktop.org specifications, its file's name its own: - each PNG of its `icon` goes into the icon theme every desktop reads, `/share/icons/hicolor/x/apps/.png`, by the size its header says, and an SVG into `.../hicolor/scalable/apps/.svg`; an icon file is Windows' alone; - its desktop entry, `/share/applications/.desktop`, names it by its title, runs `/bin/`, the prefix and not `--destdir`, quoted where it must be, and shows its icon, in a terminal unless it's `windowed`: ```ini [Desktop Entry] Type=Application Name=Hello Exec=/usr/bin/hello Icon=hello Terminal=false StartupWMClass=hello ``` A window naming itself by the program's name, as its `app_id` on Wayland or its `WM_CLASS` on X11, is matched with the entry, so a desktop's dock and task switcher show its icon. A program built for Windows holds its icon, title, and version itself, so nothing's put beside it. `package` installs into `.blossom//stage`, then writes each package into `dist`, dating every entry `SOURCE_DATE_EPOCH`, where it's set, so the same stage writes the same bytes: - `tar`, compressed by `gzip`, and `zip`, its files stored, each under a folder of the project's name, version, and target. `tar` unless asked, or `zip` for Windows; - `deb` and `arch`, under `--prefix`, `/usr` unless given, compressed by `gzip`, `xz`, and `zstd`, with the digests each lists; - `rpm`, built by `rpmbuild` from a spec blossom writes. A desktop entry in a package runs its program where the package installs it, `--prefix`'s `bin`, `/usr/bin` unless given, whichever package it's in. ## The config `config` in `~/.config/blossom`, or `$XDG_CONFIG_HOME/blossom`, and `%APPDATA%\blossom` on Windows, is optional: ```yaml sakura: /opt/sakura/bin/sakurac # the sakura to run std: /opt/sakura/std # the standard library it's given, as --lib std=DIR ``` Without `sakura`, blossom runs the `sakurac` beside it, or else the first on `PATH`. Without `std`, `sakura` finds its own.