40 lines
1.8 KiB
Text
40 lines
1.8 KiB
Text
|
|
// SPDX-License-Identifier: LGPL-3.0-only
|
||
|
|
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||
|
|
|
||
|
|
export module Crafter.Build:Script;
|
||
|
|
import std;
|
||
|
|
import :Clang;
|
||
|
|
|
||
|
|
export namespace Crafter {
|
||
|
|
struct RunScriptOptions {
|
||
|
|
// The script to run; read only when `named` is set.
|
||
|
|
std::string name;
|
||
|
|
// A name was given. Kept apart from `name` because an empty string
|
||
|
|
// is a name someone can type (`run ""`): it has to be looked up and
|
||
|
|
// refused, not read as a bare `run`, which lists.
|
||
|
|
bool named = false;
|
||
|
|
// What followed the name on the command line, handed to the script
|
||
|
|
// as ScriptContext::args.
|
||
|
|
std::vector<std::string> args;
|
||
|
|
// Print the script names instead of running one.
|
||
|
|
bool listOnly = false;
|
||
|
|
// Absolute path of the loaded project.cpp; its directory becomes
|
||
|
|
// ScriptContext::projectDir. Empty => fall back to cfg.path.
|
||
|
|
std::filesystem::path projectFile;
|
||
|
|
};
|
||
|
|
|
||
|
|
// Backs `crafter-build run`. Runs the script `opts` names out of
|
||
|
|
// `projectCfg.scripts` and returns what it returned, which the CLI uses
|
||
|
|
// as the process exit code. Without a name, or with listOnly, prints the
|
||
|
|
// names and returns 0.
|
||
|
|
//
|
||
|
|
// Returns 1, with the reason on stderr and without running anything,
|
||
|
|
// when the project defines no scripts, when a script is declared under a
|
||
|
|
// name that could never be typed (empty, or starting with '-') or under
|
||
|
|
// one name twice, and when no script has the requested name. A script
|
||
|
|
// that throws also yields 1, as does one that returns a nonzero value
|
||
|
|
// outside 1..255: an exit status is eight bits, and a value such as 256
|
||
|
|
// (a raw wait status passed along by mistake) would otherwise wrap to
|
||
|
|
// success.
|
||
|
|
std::int32_t RunScript(Configuration& projectCfg, const RunScriptOptions& opts);
|
||
|
|
}
|