From 958c18ca0d5cfd9d118400098c90ea41e10f3a9a Mon Sep 17 00:00:00 2001 From: R Date: Fri, 20 Nov 2026 06:48:55 -0300 Subject: [PATCH] tools: a directory of the build is made on Windows as idempotently as mkdir -p, so that two spellings of one directory made at once no longer fail the second The asio lane openssl-upstream-msvc-14.5 of CI run 44690351573 failed its first action, `...failed common.mkdir bin\third_party...`, and skipped everything under it, the two upstream suites among them; its 14.3 twin, the same commands, passed. b2 makes each directory of a target's path once per spelling of it (common.MkDir), and the lane names bin\third_party by two: absolute, for each OpenSSL configuration's own directory (webcpp-third-party.directory), and relative, for the consumers' selections in their variant directories; likewise bin\libs\asio\test\tls, relative for the programs and absolute for the oracle's node-modules.stamp. A dry run of a fresh tree lists both spellings of each. The two mkdirs are independent, so b2 -j runs them at once, and b2's action on Windows, `if not exist "d" mkdir "d"`, fails when the other one makes the directory between its test and its mkdir; elsewhere b2 runs mkdir -p, which does not. tools/webcpp-mkdir.jam, which webcpp.jam loads, gives Windows's action a last line that decides by the directory alone, `if exist "d\" (exit /b 0) else (exit /b 1)`: a mkdir that lost the race is a success, and a directory that cannot be made is still a failure. Under Wine's cmd, b2's own action with the directory already made exits 1 and the new one 0; b2.exe under Wine builds 400 directories each made under both spellings with -j64. The new tools/test/mkdir_test.py dry-runs a project that imports webcpp with b2 believing it is on Windows and checks the action of each directory; without the module it fails. AGENTS.md's b2 facts record the race. --- AGENTS.md | 13 +++++++++ tools/test/mkdir_test.py | 59 ++++++++++++++++++++++++++++++++++++++++ tools/webcpp-mkdir.jam | 37 +++++++++++++++++++++++++ tools/webcpp.jam | 4 +++ 4 files changed, 113 insertions(+) create mode 100644 tools/test/mkdir_test.py create mode 100644 tools/webcpp-mkdir.jam diff --git a/AGENTS.md b/AGENTS.md index d5a268f..d2c58bd 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -122,6 +122,8 @@ webcpp/ webcpp.jam the Jamfile API (chapter 4): webcpp.targets, webcpp.run, ... target.jam the targets, and the target a toolset builds for, which webcpp.jam and component.jam both read + webcpp-mkdir.jam the action that makes a directory of the build on Windows, which + webcpp.jam loads: as idempotent as b2's mkdir -p elsewhere (chapter 6) throw_exception.cpp what Boost calls in place of a throw, in a user's build without exceptions boost_json.cpp Boost.JSON's definitions, built as /webcpp//boost_json @@ -2181,6 +2183,17 @@ Each of these was measured; each has cost time. program with that value. - **A checkout path that holds a space** builds: every path b2 hands to an action is quoted, and the tests of the build run in such a path. +- **b2 makes a directory once per spelling of it,** relative or absolute + (`common.MkDir`), and a build names some by both: `bin/third_party`, a + configuration's own directory absolute and a consumer's selection + relative, and a library's test directory under `bin/libs`, the oracle's + `node-modules.stamp` absolute. Under `-j` the two actions run at once. + b2's action on Windows, `if not exist "d" mkdir "d"`, then fails when the + other one makes the directory between its test and its mkdir, and every + target under it is skipped (CI run 44690351573, `...failed common.mkdir + bin\third_party...`); `mkdir -p`, elsewhere, does not. + `tools/webcpp-mkdir.jam` makes Windows's action succeed whenever the + directory is there after it, and `tools/test/mkdir_test.py` checks it. - **A target named `release-` is no target.** b2 reads it as the variant `release` with a subfeature and stops before it builds anything (`"release-check" is not a known value of feature `); `debug-` diff --git a/tools/test/mkdir_test.py b/tools/test/mkdir_test.py new file mode 100644 index 0000000..247c932 --- /dev/null +++ b/tools/test/mkdir_test.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +"""Checks tools/webcpp-mkdir.jam: on Windows, the action that makes a directory of the build +succeeds when another action made the directory between its test and its mkdir, which happens +when b2 -j makes one directory under two spellings, relative and absolute, at once (CI run +44690351573: `...failed common.mkdir bin\\third_party...`). A dry run of a project that imports +webcpp, whose b2 believes it is on Windows, prints for each directory b2's test and mkdir, then a +last line that decides by the directory alone: a mkdir that found it made fails, and the action +still succeeds. Run with the names of some cases to run only those.""" + +from __future__ import annotations + +import sys +from pathlib import Path + +import harness + +# A project of one file in out/made, from a superproject that imports webcpp as a library's Jamfile +# does. +JAMFILE = '''import webcpp ; +make made.txt : : @touch : out/made ; +actions touch +{ + echo made > "$(<)" +} +''' + +# The action's last line, for a directory. +DECIDES = 'if exist "{}\\" (exit /b 0) else (exit /b 1)' + + +def test_the_action_on_windows_decides_by_the_directory(root: Path) -> None: + # The user-config makes b2 believe it runs on Windows and leaves it so, for webcpp to choose + # Windows's action; a dry run executes nothing. + harness.configure(root, harness.user_config(root).read_text() + + '\nimport modules ;\nmodules.poke os : .name : NT ;\n') + # Boost's version is read with Windows's findstr, which a dry run on another host has not. + harness.replace(root / 'Jamroot', '@boost-check', 'off') + (root / 'libs/demo/test/mkdir').mkdir(parents=True) + (root / 'libs/demo/test/mkdir/Jamfile').write_text(JAMFILE) + result = harness.run_b2(root, '-n', '-a', '-d+2', 'libs/demo/test/mkdir//made.txt') + harness.expect(result, True, 'common.mkdir') + made = [line for line in result.stdout.splitlines() if line.startswith('common.mkdir ')] + assert made, result.stdout + for line in made: + directory = line[len('common.mkdir '):].strip() + assert DECIDES.format(directory) in result.stdout, (directory, result.stdout) + assert f'if not exist "{directory}\\" mkdir "{directory}"' in result.stdout, result.stdout + + +CASES = [test_the_action_on_windows_decides_by_the_directory] + +if __name__ == '__main__': + sys.exit(harness.run_cases('mkdir_test', CASES, sys.argv[1:])) diff --git a/tools/webcpp-mkdir.jam b/tools/webcpp-mkdir.jam new file mode 100644 index 0000000..c7f81b6 --- /dev/null +++ b/tools/webcpp-mkdir.jam @@ -0,0 +1,37 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) +# +# The action that makes a directory of the build on Windows, as idempotent +# as `mkdir -p`, b2's own on every other system. b2 makes each directory of +# a target's path once per spelling of it (common.MkDir), and a build names +# some of its directories by two: bin/third_party, relative, for a +# consumer's selection of a configuration, and absolute for the +# configuration's own directory (tools/webcpp-third-party.jam); a +# library's test directory under bin/libs, relative for its programs, and +# absolute for the oracle's node-modules.stamp (tools/oracle/oracle.jam). +# The two actions are independent, so b2 -j runs them at once, and b2's +# action on Windows, `if not exist "d" mkdir "d"`, fails when the other one +# makes the directory between its test and its mkdir; the targets under it +# are then skipped (CI run 44690351573, the asio lane openssl-upstream on +# MSVC 14.5: `...failed common.mkdir bin\third_party...`, and the two +# upstream suites not run). Here a mkdir that finds the directory made in +# the meantime is a success, and the action fails only when no directory is +# there after it. tools/webcpp.jam loads this module, so every build that +# imports webcpp has it. +import common ; +import os ; + +if [ os.name ] = NT +{ + module common + { + actions quietly mkdir + { + if not exist "$(<)\" mkdir "$(<)" + if exist "$(<)\" (exit /b 0) else (exit /b 1) + } + } +} diff --git a/tools/webcpp.jam b/tools/webcpp.jam index 89e204e..0d5c5ce 100644 --- a/tools/webcpp.jam +++ b/tools/webcpp.jam @@ -235,6 +235,10 @@ modules.load webcpp-target : target.jam : [ path.native $(.tools) ] ; import webcpp-target ; .known = [ webcpp-target.known ] ; +# The action that makes a directory of the build on Windows, idempotent as +# `mkdir -p` is elsewhere (tools/webcpp-mkdir.jam). +modules.load webcpp-mkdir : webcpp-mkdir.jam : [ path.native $(.tools) ] ; + # The documentation's rules, loaded as the module webcpp-doc: b2 has a # module named doc of its own, the one of --help, which an import of # tools/doc/doc would find in its place.