refactor: route an executable's outputs through ProgramDir()
Build() put an executable and the files it reads at run time (its shaders, cfg.files, assets, and what its dependencies forward to it) in BinDir() directly, and ExpectedOutput(), -r and the wasm variant copies each spelled the same directory again. A Flatpak keeps its program in files/bin of the build directory instead, so those places now ask Configuration::ProgramDir(), which for every configuration is still its bin dir. Nothing moves yet.
This commit is contained in:
parent
3044ac34a1
commit
5a63dd81b8
3 changed files with 15 additions and 7 deletions
|
|
@ -118,7 +118,7 @@ Beyond the rules:
|
|||
- Comments explain why: the failure mode, the constraint, the rejected alternative. The codebase carries long comments on purpose. Do not strip them, and write them for new non-obvious code. Commit bodies follow the same rule.
|
||||
- There is no host-platform preprocessor split: the host is Linux. Target differences (mingw, wasm) branch on `cfg.target` strings at runtime, in the library as well as in `project.cpp` and tests.
|
||||
- A build step fails when its command exits nonzero, never because it printed. Use `RunBuildCommand` or `RunCommandChecked`; warnings go to `Progress::Diagnostic`.
|
||||
- Every output path goes through `Configuration::BinDir()`, `BuildDir()` and `PcmDir()`. Hand-rolled `path / "bin" / ...` clobbered variants before; do not add new ones.
|
||||
- Every output path goes through `Configuration::BinDir()`, `BuildDir()`, `PcmDir()` and `ProgramDir()`. Hand-rolled `path / "bin" / ...` clobbered variants before; do not add new ones. `ProgramDir()` is where an executable and the files it reads at run time land, and the directory `-r` runs a host executable in and serves a browser build from; `ExpectedOutput()` names the executable in it.
|
||||
- Anything that changes what gets compiled or bundled belongs in `VariantId()`. It already hashes type, debug, sysroot, defines, compile flags, the wasm baseline and variant flags, the std module the units import (`StdPcmKey`), uninterpreted project args and the toolchain (`Toolchain::Key()`).
|
||||
|
||||
## Design rules
|
||||
|
|
|
|||
|
|
@ -301,7 +301,7 @@ std::string Crafter::WasmCompileFlags(const Configuration& config) {
|
|||
}
|
||||
|
||||
fs::path Crafter::ExpectedOutput(const Configuration& config) {
|
||||
const fs::path dir = config.BinDir();
|
||||
const fs::path dir = config.ProgramDir();
|
||||
const bool mingwTarget = config.target == "x86_64-w64-mingw32";
|
||||
if (config.type == ConfigurationType::Executable) {
|
||||
if (config.target.starts_with("wasm32")) return dir / std::format("{}.wasm", config.outputName);
|
||||
|
|
@ -630,7 +630,9 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
|||
}
|
||||
|
||||
fs::path buildDir = config.BuildDir();
|
||||
fs::path outputDir = config.BinDir();
|
||||
// Everything this configuration produces lands here: a library's archive
|
||||
// and module PCMs, an executable and the files it reads at run time.
|
||||
fs::path outputDir = config.ProgramDir();
|
||||
|
||||
if (!fs::exists(buildDir)) {
|
||||
fs::create_directories(buildDir);
|
||||
|
|
@ -1061,7 +1063,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
|||
std::unordered_set<Configuration*> seen;
|
||||
std::function<void(Configuration*)> forwardDepArtifacts = [&](Configuration* dep) {
|
||||
if (!seen.insert(dep).second) return;
|
||||
fs::path depBinDir = dep->BinDir();
|
||||
fs::path depBinDir = dep->ProgramDir();
|
||||
for (const Shader& shader : dep->shaders) {
|
||||
fs::path src = depBinDir / shader.OutputName();
|
||||
if (!fs::exists(src)) continue;
|
||||
|
|
@ -1406,7 +1408,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
|||
// (deps leave it empty) and never on a variant pass itself (those carry
|
||||
// wasmVariantFlags), so there's no recursion. Skipped on build error.
|
||||
if (buildResult.result.empty() && config.target.starts_with("wasm32") && config.type == ConfigurationType::Executable && !config.wasmVariants.empty() && config.wasmVariantFlags.empty()) {
|
||||
fs::path baselineBin = config.BinDir();
|
||||
fs::path baselineBin = config.ProgramDir();
|
||||
|
||||
// The whole transitive graph, so the variant flags reach every TU.
|
||||
std::vector<Configuration*> graph;
|
||||
|
|
@ -1428,7 +1430,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
|||
Progress::Task task(std::format("Building wasm variant {} ({})", variant.label, config.outputName));
|
||||
|
||||
for (Configuration* c : graph) c->wasmVariantFlags = variant.flags;
|
||||
fs::path variantBin = config.BinDir();
|
||||
fs::path variantBin = config.ProgramDir();
|
||||
|
||||
std::unordered_map<fs::path, std::shared_future<BuildResult>> variantDeps;
|
||||
std::mutex variantMutex;
|
||||
|
|
@ -2087,7 +2089,7 @@ std::int32_t Crafter::Run(std::int32_t argc, char** argv) {
|
|||
std::println(std::cerr, "-r: cannot run a library");
|
||||
return 1;
|
||||
}
|
||||
fs::path dir = config.BinDir();
|
||||
fs::path dir = config.ProgramDir();
|
||||
fs::path artifact = fs::absolute(ExpectedOutput(config));
|
||||
fs::path absDir = fs::absolute(dir);
|
||||
|
||||
|
|
|
|||
|
|
@ -660,6 +660,12 @@ export namespace Crafter {
|
|||
}
|
||||
fs::path BuildDir() const { return path / "build" / VariantId(); }
|
||||
fs::path BinDir() const { return path / "bin" / VariantId(); }
|
||||
// Where an executable and the files it reads at run time land, and
|
||||
// the directory `-r` runs a host executable in and serves a browser
|
||||
// build from: its shaders, cfg.files and assets, and those its
|
||||
// dependencies forward to it. For now that is the bin
|
||||
// dir of every configuration.
|
||||
fs::path ProgramDir() const { return BinDir(); }
|
||||
fs::path PcmDir() const {
|
||||
return type == ConfigurationType::Executable ? BuildDir() : BinDir();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue