From c5cf04a09ad8fcca4eb7022596cdbfc2d45bde09 Mon Sep 17 00:00:00 2001 From: Zhe Feng Date: Sat, 28 Nov 2026 04:05:36 +0000 Subject: [PATCH 1/3] exports: boost::dll::fs follows boost::filesystem (policy republish) boost/dll/config.hpp spells boost::dll::fs as `using namespace boost::filesystem;`. The generator follows a using-directive only in the ADL-barrier shape, so #5 re-declared 33 filesystem names by hand; 28 non-operator spellings of main before #1 (symlink_status, space, permissions, unique_path, ...) stayed unreachable. A [[.republish]] policy entry names the directive's namespace: every name the owning module emitted directly in the target namespace (after its drops, with its guards) is re-exported through it, and the owner becomes a .deps edge. dll::fs now carries filesystem's 138 names under !defined(BOOST_DLL_USE_STD_FS); the std::filesystem branch stays an extra, completed to the standard's 54 names. Cached entries hold only while the owner's emitted names are unchanged. --- generated/exports/dll.inc | 173 +++++++++++++++++--- generated/meta/api-surface.json | 2 +- generated/meta/skipped.txt | 3 +- tools/export_policy.toml | 86 +++++----- tools/gen_exports.py | 160 ++++++++++++++++-- tools/tests/test_gen_exports_republish.py | 190 ++++++++++++++++++++++ 6 files changed, 539 insertions(+), 75 deletions(-) create mode 100644 tools/tests/test_gen_exports_republish.py diff --git a/generated/exports/dll.inc b/generated/exports/dll.inc index 8e75e207..b17e50a0 100644 --- a/generated/exports/dll.inc +++ b/generated/exports/dll.inc @@ -1,5 +1,5 @@ // GENERATED by tools/gen_exports.py - DO NOT EDIT -// lib=dll boost=1.92.0 target=x86_64-w64-mingw32 entities=150 +// lib=dll boost=1.92.0 target=x86_64-w64-mingw32 entities=288 export namespace boost { namespace dll { using boost::dll::import_alias; @@ -155,13 +155,9 @@ export namespace boost { namespace dll { namespace experimental { namespace deta }}}} export namespace boost { namespace dll { namespace fs { - // boost/dll/config.hpp spells boost::dll::fs as `using namespace - // boost::filesystem;` (std::filesystem with BOOST_DLL_USE_STD_FS), and an - // importer never sees a using-directive: the examples and the API (dll::fs::path, - // program_location's return type) name dll::fs::path, fs::is_regular_file, - // fs::recursive_directory_iterator. The filesystem names the documentation uses - // are re-declared here (error_code / system_error are using-declarations - // upstream and exported already). + // With BOOST_DLL_USE_STD_FS, boost/dll/config.hpp's directive names + // std::filesystem instead: a fixed standard surface, listed here in full + // (path's operators, swap and hash_value are found by ADL). #if defined(BOOST_DLL_USE_STD_FS) using ::std::filesystem::path; using ::std::filesystem::filesystem_error; @@ -169,68 +165,203 @@ export namespace boost { namespace dll { namespace fs { using ::std::filesystem::directory_iterator; using ::std::filesystem::recursive_directory_iterator; using ::std::filesystem::file_status; + using ::std::filesystem::space_info; using ::std::filesystem::file_type; using ::std::filesystem::perms; + using ::std::filesystem::perm_options; using ::std::filesystem::copy_options; - using ::std::filesystem::space_info; + using ::std::filesystem::directory_options; + using ::std::filesystem::file_time_type; + using ::std::filesystem::begin; + using ::std::filesystem::end; using ::std::filesystem::absolute; using ::std::filesystem::canonical; using ::std::filesystem::copy; using ::std::filesystem::copy_file; + using ::std::filesystem::copy_symlink; using ::std::filesystem::create_directories; using ::std::filesystem::create_directory; + using ::std::filesystem::create_directory_symlink; + using ::std::filesystem::create_hard_link; + using ::std::filesystem::create_symlink; using ::std::filesystem::current_path; using ::std::filesystem::equivalent; using ::std::filesystem::exists; using ::std::filesystem::file_size; + using ::std::filesystem::hard_link_count; + using ::std::filesystem::is_block_file; + using ::std::filesystem::is_character_file; using ::std::filesystem::is_directory; using ::std::filesystem::is_empty; + using ::std::filesystem::is_fifo; + using ::std::filesystem::is_other; using ::std::filesystem::is_regular_file; + using ::std::filesystem::is_socket; using ::std::filesystem::is_symlink; using ::std::filesystem::last_write_time; + using ::std::filesystem::permissions; + using ::std::filesystem::proximate; using ::std::filesystem::read_symlink; using ::std::filesystem::relative; using ::std::filesystem::remove; using ::std::filesystem::remove_all; using ::std::filesystem::rename; + using ::std::filesystem::resize_file; + using ::std::filesystem::space; using ::std::filesystem::status; + using ::std::filesystem::status_known; + using ::std::filesystem::symlink_status; using ::std::filesystem::temp_directory_path; using ::std::filesystem::weakly_canonical; - #else - using ::boost::filesystem::path; - using ::boost::filesystem::filesystem_error; - using ::boost::filesystem::directory_entry; - using ::boost::filesystem::directory_iterator; - using ::boost::filesystem::recursive_directory_iterator; - using ::boost::filesystem::file_status; - using ::boost::filesystem::file_type; - using ::boost::filesystem::perms; - using ::boost::filesystem::copy_options; - using ::boost::filesystem::space_info; + #endif +#if !defined(BOOST_DLL_USE_STD_FS) + // boost/dll/config.hpp spells boost::dll::fs as `using namespace + // boost::filesystem;`, and an importer never sees a using-directive: the + // examples and the API (dll::fs::path, program_location's return type) name + // dll::fs::path, fs::is_regular_file, fs::recursive_directory_iterator. Every + // name the filesystem module exports directly in boost::filesystem is + // re-exported through boost::dll::fs, so the spelling follows Boost.Filesystem. + // error_code / system_error are using-declarations upstream and exported + // already. using ::boost::filesystem::absolute; + using ::boost::filesystem::basic_filebuf; + using ::boost::filesystem::basic_fstream; + using ::boost::filesystem::basic_ifstream; + using ::boost::filesystem::basic_ofstream; + using ::boost::filesystem::begin; + using ::boost::filesystem::bitmask_set; using ::boost::filesystem::canonical; + using ::boost::filesystem::cbegin; + using ::boost::filesystem::cend; + using ::boost::filesystem::codecvt_error_category; using ::boost::filesystem::copy; using ::boost::filesystem::copy_file; + using ::boost::filesystem::copy_options; + using ::boost::filesystem::copy_symlink; using ::boost::filesystem::create_directories; using ::boost::filesystem::create_directory; + using ::boost::filesystem::create_directory_symlink; + using ::boost::filesystem::create_hard_link; + using ::boost::filesystem::create_symlink; + using ::boost::filesystem::creation_time; using ::boost::filesystem::current_path; + using ::boost::filesystem::directory_entry; + using ::boost::filesystem::directory_iterator; + using ::boost::filesystem::directory_options; + using ::boost::filesystem::end; using ::boost::filesystem::equivalent; using ::boost::filesystem::exists; using ::boost::filesystem::file_size; + using ::boost::filesystem::file_status; + using ::boost::filesystem::file_type; + using ::boost::filesystem::file_type::block_file; + using ::boost::filesystem::file_type::character_file; + using ::boost::filesystem::file_type::directory_file; + using ::boost::filesystem::file_type::fifo_file; + using ::boost::filesystem::file_type::file_not_found; + using ::boost::filesystem::file_type::regular_file; + using ::boost::filesystem::file_type::reparse_file; + using ::boost::filesystem::file_type::socket_file; + using ::boost::filesystem::file_type::status_error; + using ::boost::filesystem::file_type::symlink_file; + using ::boost::filesystem::file_type::type_unknown; + using ::boost::filesystem::filebuf; + using ::boost::filesystem::filesystem_error; + using ::boost::filesystem::fopen; + using ::boost::filesystem::fstream; + using ::boost::filesystem::hard_link_count; + using ::boost::filesystem::hash_value; + using ::boost::filesystem::ifstream; + using ::boost::filesystem::initial_path; + using ::boost::filesystem::is_block_file; + using ::boost::filesystem::is_character_file; using ::boost::filesystem::is_directory; using ::boost::filesystem::is_empty; + using ::boost::filesystem::is_fifo; + using ::boost::filesystem::is_other; using ::boost::filesystem::is_regular_file; + using ::boost::filesystem::is_reparse_file; + using ::boost::filesystem::is_socket; using ::boost::filesystem::is_symlink; using ::boost::filesystem::last_write_time; + using ::boost::filesystem::lexicographical_compare; + using ::boost::filesystem::native; + using ::boost::filesystem::ofstream; + using ::boost::filesystem::operator!; + using ::boost::filesystem::operator!=; + using ::boost::filesystem::operator&; + using ::boost::filesystem::operator&=; + using ::boost::filesystem::operator/; + using ::boost::filesystem::operator<; + using ::boost::filesystem::operator<<; + using ::boost::filesystem::operator<=; + using ::boost::filesystem::operator==; + using ::boost::filesystem::operator>; + using ::boost::filesystem::operator>=; + using ::boost::filesystem::operator>>; + using ::boost::filesystem::operator^; + using ::boost::filesystem::operator^=; + using ::boost::filesystem::operator|; + using ::boost::filesystem::operator|=; + using ::boost::filesystem::operator~; + using ::boost::filesystem::path; + using ::boost::filesystem::permissions; + using ::boost::filesystem::permissions_present; + using ::boost::filesystem::perms; + using ::boost::filesystem::perms::_detail_extend_perms_32_1; + using ::boost::filesystem::perms::_detail_extend_perms_32_2; + using ::boost::filesystem::perms::add_perms; + using ::boost::filesystem::perms::all_all; + using ::boost::filesystem::perms::group_all; + using ::boost::filesystem::perms::group_exe; + using ::boost::filesystem::perms::group_read; + using ::boost::filesystem::perms::group_write; + using ::boost::filesystem::perms::no_perms; + using ::boost::filesystem::perms::others_all; + using ::boost::filesystem::perms::others_exe; + using ::boost::filesystem::perms::others_read; + using ::boost::filesystem::perms::others_write; + using ::boost::filesystem::perms::owner_all; + using ::boost::filesystem::perms::owner_exe; + using ::boost::filesystem::perms::owner_read; + using ::boost::filesystem::perms::owner_write; + using ::boost::filesystem::perms::perms_mask; + using ::boost::filesystem::perms::perms_not_known; + using ::boost::filesystem::perms::remove_perms; + using ::boost::filesystem::perms::set_gid_on_exe; + using ::boost::filesystem::perms::set_uid_on_exe; + using ::boost::filesystem::perms::sticky_bit; + using ::boost::filesystem::perms::symlink_perms; + using ::boost::filesystem::portable_directory_name; + using ::boost::filesystem::portable_file_name; + using ::boost::filesystem::portable_name; + using ::boost::filesystem::portable_posix_name; + using ::boost::filesystem::range_begin; + using ::boost::filesystem::range_end; using ::boost::filesystem::read_symlink; + using ::boost::filesystem::recursive_directory_iterator; using ::boost::filesystem::relative; using ::boost::filesystem::remove; using ::boost::filesystem::remove_all; using ::boost::filesystem::rename; + using ::boost::filesystem::resize_file; + using ::boost::filesystem::space; + using ::boost::filesystem::space_info; using ::boost::filesystem::status; + using ::boost::filesystem::status_known; + using ::boost::filesystem::swap; + using ::boost::filesystem::symlink_status; + using ::boost::filesystem::system_complete; using ::boost::filesystem::temp_directory_path; + using ::boost::filesystem::type_present; + using ::boost::filesystem::unique_path; using ::boost::filesystem::weakly_canonical; - #endif + using ::boost::filesystem::wfilebuf; + using ::boost::filesystem::wfstream; + using ::boost::filesystem::wifstream; + using ::boost::filesystem::windows_name; + using ::boost::filesystem::wofstream; +#endif using boost::dll::fs::error_code; using boost::dll::fs::system_error; }}} diff --git a/generated/meta/api-surface.json b/generated/meta/api-surface.json index d1600d3c..85688f88 100644 --- a/generated/meta/api-surface.json +++ b/generated/meta/api-surface.json @@ -659,7 +659,7 @@ "type_index", "winapi" ], - "exported": 150, + "exported": 288, "gmf": [ "boost/dll.hpp", "boost/dll/import_class.hpp", diff --git a/generated/meta/skipped.txt b/generated/meta/skipped.txt index 3e917f80..e3aab331 100644 --- a/generated/meta/skipped.txt +++ b/generated/meta/skipped.txt @@ -123,7 +123,7 @@ decimal guard boost::int128::detail::impl::int128_udiv128_intrinsic if defined(B decimal guard boost::int128::detail::impl::int128_umul128_intrinsic if defined(BOOST_DECIMAL_DETAIL_INT128_HAS_FAST_DIV128) -- The 128-bit division intrinsics are declared only where BOOST_DECIMAL_DETAIL_INT128_HAS_FAST_DIV128 (x86-64 gcc/clang). decimal guard boost::int128::detail::impl::mg32_div_3by2 if defined(BOOST_DECIMAL_DETAIL_INT128_HAS_FAST_DIV128) -- The 128-bit division intrinsics are declared only where BOOST_DECIMAL_DETAIL_INT128_HAS_FAST_DIV128 (x86-64 gcc/clang). decimal guard boost::int128::detail::impl::mg32_reciprocal_2by1 if defined(BOOST_DECIMAL_DETAIL_INT128_HAS_FAST_DIV128) -- The 128-bit division intrinsics are declared only where BOOST_DECIMAL_DETAIL_INT128_HAS_FAST_DIV128 (x86-64 gcc/clang). -dll extra boost::dll::fs -- boost/dll/config.hpp spells boost::dll::fs as `using namespace boost::filesystem;` (std::filesystem with BOOST_DLL_USE_STD_FS), and an importer never sees a using-directive: the examples and the API (dll::fs::path, program_location's return type) name dll::fs::path, fs::is_regular_file, fs::recursive_directory_iterator. The filesystem names the documentation uses are re-declared here (error_code / system_error are using-declarations upstream and exported already). +dll extra boost::dll::fs -- With BOOST_DLL_USE_STD_FS, boost/dll/config.hpp's directive names std::filesystem instead: a fixed standard surface, listed here in full (path's operators, swap and hash_value are found by ADL). dll guard boost::dll::detail::last_error_code if defined(_WIN32) -- M9 platform guard: last_error_code is in detail/windows/ path_from_handle.hpp (no POSIX counterpart). dll guard boost::dll::detail::parser::arg_list if !defined(_MSC_VER) -- M9 platform guard: the itanium demangling parser (demangling/itanium.hpp) is selected only outside _MSC_VER (dll/detail/ctor_dtor.hpp). dll guard boost::dll::detail::parser::const_rule if !defined(_MSC_VER) -- M9 platform guard: the itanium demangling parser (demangling/itanium.hpp) is selected only outside _MSC_VER (dll/detail/ctor_dtor.hpp). @@ -138,6 +138,7 @@ dll guard boost::dll::detail::parser::type_name if !defined(_MSC_VER) -- M9 plat dll guard boost::dll::detail::parser::volatile_rule if !defined(_MSC_VER) -- M9 platform guard: the itanium demangling parser (demangling/itanium.hpp) is selected only outside _MSC_VER (dll/detail/ctor_dtor.hpp). dll guard boost::dll::detail::parser::volatile_rule_impl if !defined(_MSC_VER) -- M9 platform guard: the itanium demangling parser (demangling/itanium.hpp) is selected only outside _MSC_VER (dll/detail/ctor_dtor.hpp). dll guard boost::dll::experimental::demangle_symbol if !defined(_MSC_VER) -- M9 platform guard: demangle_symbol comes from demangling/itanium.hpp. +dll republish boost::dll::fs if !defined(BOOST_DLL_USE_STD_FS) -- boost/dll/config.hpp spells boost::dll::fs as `using namespace boost::filesystem;`, and an importer never sees a using-directive: the examples and the API (dll::fs::path, program_location's return type) name dll::fs::path, fs::is_regular_file, fs::recursive_directory_iterator. Every name the filesystem module exports directly in boost::filesystem is re-exported through boost::dll::fs, so the spelling follows Boost.Filesystem. error_code / system_error are using-declarations upstream and exported already. flyweight drop boost::detail::allocator::compliant_allocator_rebind_to -- The bundle pulls the transitive container/interprocess/parameter surface into shared namespaces; boost.flyweight exports its own namespaces and boost:: entry points only. flyweight drop boost::detail::allocator::construct -- The bundle pulls the transitive container/interprocess/parameter surface into shared namespaces; boost.flyweight exports its own namespaces and boost:: entry points only. flyweight drop boost::detail::allocator::destroy -- The bundle pulls the transitive container/interprocess/parameter surface into shared namespaces; boost.flyweight exports its own namespaces and boost:: entry points only. diff --git a/tools/export_policy.toml b/tools/export_policy.toml index b50a3ec8..344fa9c2 100644 --- a/tools/export_policy.toml +++ b/tools/export_policy.toml @@ -18,6 +18,11 @@ # [[.drop]] names = [...], reason = "..." # [[.extra]] namespace = "boost", lines = [...], reason = "..." # (namespace = "" exports into the global namespace) +# [[.republish]] namespace = "boost::dll::fs", reason = "...", +# if = "" (optional) — the namespace holds +# `using namespace ;` for a namespace another +# target library owns; every name that library exports +# directly in is re-exported through it # [.deps] add = [...], remove = [...], reason = "..." # # A `names` entry with `::` matches one qualified name exactly; a bare @@ -980,16 +985,26 @@ names = [ "boost::dll::experimental::demangle_symbol", ] -[[dll.extra]] +[[dll.republish]] namespace = "boost::dll::fs" +if = "!defined(BOOST_DLL_USE_STD_FS)" reason = ''' boost/dll/config.hpp spells boost::dll::fs as `using namespace -boost::filesystem;` (std::filesystem with BOOST_DLL_USE_STD_FS), and an -importer never sees a using-directive: the examples and the API (dll::fs::path, -program_location's return type) name dll::fs::path, fs::is_regular_file, -fs::recursive_directory_iterator. The filesystem names the documentation uses -are re-declared here (error_code / system_error are using-declarations -upstream and exported already). +boost::filesystem;`, and an importer never sees a using-directive: the +examples and the API (dll::fs::path, program_location's return type) name +dll::fs::path, fs::is_regular_file, fs::recursive_directory_iterator. Every +name the filesystem module exports directly in boost::filesystem is +re-exported through boost::dll::fs, so the spelling follows Boost.Filesystem. +error_code / system_error are using-declarations upstream and exported +already. +''' + +[[dll.extra]] +namespace = "boost::dll::fs" +reason = ''' +With BOOST_DLL_USE_STD_FS, boost/dll/config.hpp's directive names +std::filesystem instead: a fixed standard surface, listed here in full +(path's operators, swap and hash_value are found by ADL). ''' lines = [ "#if defined(BOOST_DLL_USE_STD_FS)", @@ -999,67 +1014,54 @@ lines = [ "using ::std::filesystem::directory_iterator;", "using ::std::filesystem::recursive_directory_iterator;", "using ::std::filesystem::file_status;", + "using ::std::filesystem::space_info;", "using ::std::filesystem::file_type;", "using ::std::filesystem::perms;", + "using ::std::filesystem::perm_options;", "using ::std::filesystem::copy_options;", - "using ::std::filesystem::space_info;", + "using ::std::filesystem::directory_options;", + "using ::std::filesystem::file_time_type;", + "using ::std::filesystem::begin;", + "using ::std::filesystem::end;", "using ::std::filesystem::absolute;", "using ::std::filesystem::canonical;", "using ::std::filesystem::copy;", "using ::std::filesystem::copy_file;", + "using ::std::filesystem::copy_symlink;", "using ::std::filesystem::create_directories;", "using ::std::filesystem::create_directory;", + "using ::std::filesystem::create_directory_symlink;", + "using ::std::filesystem::create_hard_link;", + "using ::std::filesystem::create_symlink;", "using ::std::filesystem::current_path;", "using ::std::filesystem::equivalent;", "using ::std::filesystem::exists;", "using ::std::filesystem::file_size;", + "using ::std::filesystem::hard_link_count;", + "using ::std::filesystem::is_block_file;", + "using ::std::filesystem::is_character_file;", "using ::std::filesystem::is_directory;", "using ::std::filesystem::is_empty;", + "using ::std::filesystem::is_fifo;", + "using ::std::filesystem::is_other;", "using ::std::filesystem::is_regular_file;", + "using ::std::filesystem::is_socket;", "using ::std::filesystem::is_symlink;", "using ::std::filesystem::last_write_time;", + "using ::std::filesystem::permissions;", + "using ::std::filesystem::proximate;", "using ::std::filesystem::read_symlink;", "using ::std::filesystem::relative;", "using ::std::filesystem::remove;", "using ::std::filesystem::remove_all;", "using ::std::filesystem::rename;", + "using ::std::filesystem::resize_file;", + "using ::std::filesystem::space;", "using ::std::filesystem::status;", + "using ::std::filesystem::status_known;", + "using ::std::filesystem::symlink_status;", "using ::std::filesystem::temp_directory_path;", "using ::std::filesystem::weakly_canonical;", - "#else", - "using ::boost::filesystem::path;", - "using ::boost::filesystem::filesystem_error;", - "using ::boost::filesystem::directory_entry;", - "using ::boost::filesystem::directory_iterator;", - "using ::boost::filesystem::recursive_directory_iterator;", - "using ::boost::filesystem::file_status;", - "using ::boost::filesystem::file_type;", - "using ::boost::filesystem::perms;", - "using ::boost::filesystem::copy_options;", - "using ::boost::filesystem::space_info;", - "using ::boost::filesystem::absolute;", - "using ::boost::filesystem::canonical;", - "using ::boost::filesystem::copy;", - "using ::boost::filesystem::copy_file;", - "using ::boost::filesystem::create_directories;", - "using ::boost::filesystem::create_directory;", - "using ::boost::filesystem::current_path;", - "using ::boost::filesystem::equivalent;", - "using ::boost::filesystem::exists;", - "using ::boost::filesystem::file_size;", - "using ::boost::filesystem::is_directory;", - "using ::boost::filesystem::is_empty;", - "using ::boost::filesystem::is_regular_file;", - "using ::boost::filesystem::is_symlink;", - "using ::boost::filesystem::last_write_time;", - "using ::boost::filesystem::read_symlink;", - "using ::boost::filesystem::relative;", - "using ::boost::filesystem::remove;", - "using ::boost::filesystem::remove_all;", - "using ::boost::filesystem::rename;", - "using ::boost::filesystem::status;", - "using ::boost::filesystem::temp_directory_path;", - "using ::boost::filesystem::weakly_canonical;", "#endif", ] diff --git a/tools/gen_exports.py b/tools/gen_exports.py index 624ba17f..06c38d79 100644 --- a/tools/gen_exports.py +++ b/tools/gen_exports.py @@ -86,6 +86,11 @@ class Policy: [[.drop]] reason / names / namespaces — never export the matching names (or anything inside the namespaces) [[.extra]] namespace / reason / lines — verbatim declarations + [[.republish]] namespace / reason / if — the library's `using + namespace ;` inside names a + namespace another target library owns: re-export + every name that library exports directly in + through (under `#if ` when given) [.deps] add / remove / reason — module edge corrections [.facade] omit-imports / reason — .deps edges src/.cppm cannot `export import` (checked by check_facade) @@ -128,6 +133,9 @@ def drops(self, lib): def extras(self, lib): return list(self.lib(lib).get("extra", ())) + def republishes(self, lib): + return list(self.lib(lib).get("republish", ())) + def deps(self, lib): return self.lib(lib).get("deps", {}) @@ -826,6 +834,98 @@ def collect_added(lib, m, policy, claimed): return out +def upstreams_of(graph, lib): + """Every target library `lib`'s headers reach, transitively.""" + seen, stack = set(), list(graph.get(lib, ())) + while stack: + u = stack.pop() + if u not in seen: + seen.add(u) + stack.extend(graph.get(u, ())) + seen.discard(lib) + return seen + + +def republish_sources(published, target, upstreams): + """[[owner, qname, condition]] — the names the libraries in `upstreams` + export directly in namespace `target`, as their emit_inc wrote them + (after drops; `condition` is the guard they sit under, or "").""" + chain = target.split("::") + return sorted([owner, e["qname"], e["if"]] + for owner in upstreams + for e in published.get(owner, ()) + if e["ns"] == chain) + + +def collect_republished(lib, m, policy, published, upstreams, claimed): + """Policy `republish` entries. `namespace boost { namespace dll { namespace + fs { using namespace boost::filesystem; } } }` makes dll::fs::path the + public spelling of filesystem's path, but an importer never sees a + using-directive, and the directive's target belongs to another module. + Every name that module exports directly in the target namespace is + re-exported through the directive's namespace, so the spelling follows the + owner's surface (its drops, guards and upstream additions) instead of a + hand-kept list. + + Returns (records, {"=": sources}, skipped entries, + errors); the sources are the republish_sources() lists a cached result + depends on (checked by _republish_holds).""" + out, sources, entries, errors = {}, {}, [], [] + directives = {} + for d in m.indexed(): + if d.kind != "UsingDirectiveDecl" or d.parent is None \ + or d.parent.kind != "NamespaceDecl": + continue + ns = m.by_id.get(d.target) + parts = _enclosing_ns(m, d) + if ns is None or not parts: + continue + tgt = m.qualified_name(ns) + found = directives.setdefault("::".join(parts), {}) + found.setdefault(tgt, d.file) + for entry in policy.republishes(lib): + where = entry["namespace"] + cond = " ".join(entry.get("if", "").split()) + entries.append((lib, "republish", where, cond, entry["reason"])) + targets = directives.get(where) + if not targets: + errors.append("policy republish {}: the TU has no using-directive " + "in that namespace".format(where)) + continue + guards = {} + + def guard_for(src_cond): + parts = [c for c in (cond, src_cond) if c] + key = " && ".join("(" + c + ")" for c in parts) \ + if len(parts) > 1 else "".join(parts) + if not key: + return None + return guards.setdefault(key, {"if": key, + "reason": entry["reason"]}) + + for tgt, dfile in sorted(targets.items()): + src = republish_sources(published, tgt, upstreams) + sources[where + "=" + tgt] = src + if not src: + errors.append( + "policy republish {}: no upstream module of {} exports " + "names directly in {}".format(where, lib, tgt)) + continue + for owner, qname, src_cond in src: + q = where + "::" + qname.rsplit("::", 1)[-1] + ckey = q + "=" + qname + if q in claimed or ckey in claimed: + continue + claimed[ckey] = lib + out[q] = { + "name": qname.rsplit("::", 1)[-1], "qname": "::" + qname, + "usr": "inject:" + ckey, "ns": where.split("::"), + "file": dfile, "home": lib, "kind": "USING_INJECT", + "guard": guard_for(src_cond), "owner": owner, + } + return out, sources, entries, errors + + # --------------------------------------------------------------------------- # signature closure (pass 1) # --------------------------------------------------------------------------- @@ -1040,14 +1140,19 @@ def _spell(qname, ns, namespaces): def emit_inc(lib, records, out_dir, claimed, policy, extra_deps=(), - namespaces=frozenset()): + namespaces=frozenset(), published=None): """Write generated/exports/.inc (+ .deps). Cross-module dedup (first wins): entities claimed by an earlier module are left out and their homes become `.deps` edges. One using-declaration per qualified name (it brings every overload). Policy guards, drops, inline- namespace collapses and verbatim lines are applied here, and every name - they touch is returned for generated/meta/skipped.txt. + they touch is returned for generated/meta/skipped.txt. A record that + carries its own "guard" (a republished name) is emitted under it; its + policy entry is listed once, by collect_republished. + + When `published` is a list, every emitted name is appended to it as + {"ns", "qname", "if"} (what a `republish` in a downstream library follows). Returns (exported_count, deps, skipped_entries).""" own = [r for r in records.values() if r["home"] == lib] @@ -1082,10 +1187,18 @@ def emit_inc(lib, records, out_dir, claimed, policy, extra_deps=(), if rule is not None: skipped.append((lib, "drop", q, "", rule["reason"])) continue - guard = next((g for g in guards if _matches(q, g["names"])), None) - if guard is not None: - skipped.append((lib, "guard", q, guard["if"], guard["reason"])) + if "guard" in rec: + guard = rec["guard"] + else: + guard = next((g for g in guards if _matches(q, g["names"])), None) + if guard is not None: + skipped.append((lib, "guard", q, guard["if"], + guard["reason"])) exports.append((tuple(ns), q, guard)) + if published is not None: + published.append({ + "ns": list(ns), "qname": q.lstrip(":"), + "if": " ".join(guard["if"].split()) if guard else ""}) groups = {} for ns, q, guard in exports: @@ -1388,6 +1501,19 @@ def _claims_hold(sk, claimed, claimed_inject): return all(claimed_inject.get(k) == o for k, o in view) +def _republish_holds(sk, published, upstreams): + """A cached `republish` result still matches what the owning modules + export now (their output can change while this library's key holds).""" + rp = sk.get("republish") + if rp is None or "published" not in sk: + return False + for key, src in rp.items(): + target = key.split("=", 1)[1] + if republish_sources(published, target, upstreams) != src: + return False + return True + + def _load_json(path): try: return json.loads(path.read_text(encoding="utf-8")) @@ -1532,7 +1658,7 @@ def generate(args, out): old_libs = (old_surface or {}).get("libraries", {}) old_skipped = _read_skipped(out / "generated" / "meta" / "skipped.txt") - claimed, claimed_inject = {}, {} + claimed, claimed_inject, published = {}, {}, {} summary, skipped, body_all, gfm_by_lib, deps_by_lib = {}, [], {}, {}, {} cache_payloads = {} for lib in order: @@ -1543,7 +1669,8 @@ def generate(args, out): if use_cache and key else None hit = sk is not None and sk.get("key") == key \ and _manifest_ok(sk.get("inputs")) \ - and _claims_hold(sk, claimed, claimed_inject) + and _claims_hold(sk, claimed, claimed_inject) \ + and _republish_holds(sk, published, upstreams_of(graph, lib)) if lib not in libs: # Not regenerated: its committed output stays, but its claims # shape first-wins ownership downstream, so replay them. @@ -1555,6 +1682,7 @@ def generate(args, out): claimed.setdefault(usr, owner) for q, owner in sk["inject_claims"]: claimed_inject.setdefault(q, owner) + published[lib] = sk["published"] else: print("warning: no current cache for {}; a --libs run " "may claim differently from a full run".format(lib)) @@ -1564,6 +1692,7 @@ def generate(args, out): claimed.setdefault(usr, owner) for q, owner in sk["inject_claims"]: claimed_inject.setdefault(q, owner) + published[lib] = sk["published"] gfm_by_lib[lib] = [bc.DEPS / rel for rel in sk["gfm"]] summary[lib] = sk["summary"] deps_by_lib[lib] = sk["summary"]["deps"] @@ -1595,13 +1724,22 @@ def generate(args, out): inject_view = _ClaimView(claimed_inject) injects = collect_injections(lib, m, inject_view) added = collect_added(lib, m, policy, inject_view) - records = closure_from(m, dict(cands, **injects, **added)) + rp, rp_sources, rp_entries, rp_errors = collect_republished( + lib, m, policy, published, upstreams_of(graph, lib), inject_view) + if rp_errors: + for e in rp_errors: + print("error: {}: {}".format(lib, e), file=sys.stderr) + return 1, [] + records = closure_from(m, dict(cands, **injects, **added, **rp)) pre_claimed = sorted({r["usr"] for r in records.values() if r["usr"] in claimed}) + published[lib] = [] exports, deps, sk_entries = emit_inc( lib, records, out, claimed, policy, - extra_deps=bc.lib_deps(lib, gfm_final), - namespaces=m.namespaces()) + extra_deps=bc.lib_deps(lib, gfm_final) | + {r["owner"] for r in rp.values()}, + namespaces=m.namespaces(), published=published[lib]) + sk_entries += rp_entries body = {} if args.no_body_deps else \ collect_body_edges(lib, m, records, claimed) if body: @@ -1635,6 +1773,8 @@ def generate(args, out): "claims": [[r["usr"], lib] for r in records.values()], "inject_claims": [[q, o] for q, o in claimed_inject.items() if o == lib], + "published": published[lib], + "republish": rp_sources, "pre_claimed": pre_claimed, "inject_view": sorted([k, o] for k, o in inject_view.seen.items()), diff --git a/tools/tests/test_gen_exports_republish.py b/tools/tests/test_gen_exports_republish.py new file mode 100644 index 00000000..17e7b06a --- /dev/null +++ b/tools/tests/test_gen_exports_republish.py @@ -0,0 +1,190 @@ +"""A `republish` policy entry re-exports what the owning module exports in the +namespace a using-directive names (boost::dll::fs -> boost::filesystem).""" +import io +import json +import tempfile +import unittest +from pathlib import Path + +import ast_json +import gen_exports + +HDR = "/b/boost/dll/config.hpp" + + +def loc(line=1): + return {"offset": 1, "line": line, "col": 1, "file": HDR} + + +def ns(nid, name, inner): + return {"id": nid, "kind": "NamespaceDecl", "loc": loc(), + "range": {"begin": loc(), "end": loc()}, "name": name, + "inner": inner} + + +def model(): + """namespace boost { + namespace filesystem { struct path; } + namespace dll { namespace fs { using namespace boost::filesystem; } } + }""" + text = json.dumps(ns("0x1", "boost", [ + ns("0x2", "filesystem", [ + {"id": "0x10", "kind": "CXXRecordDecl", "loc": loc(2), + "name": "path", "tagUsed": "struct", + "completeDefinition": True}, + ]), + ns("0x3", "dll", [ + ns("0x4", "fs", [ + {"id": "0x20", "kind": "UsingDirectiveDecl", "loc": loc(4), + "nominatedNamespace": {"id": "0x2", "kind": "NamespaceDecl", + "name": "filesystem"}}, + ]), + ]), + ]), indent=2) + "\n" + return gen_exports.Model(ast_json.TU.from_stream(io.BytesIO(text.encode()))) + + +def published(): + """What filesystem's emit_inc recorded (one guarded name, one enumerator + exported through its enum's scope, one name of a nested namespace).""" + return {"filesystem": [ + {"ns": ["boost", "filesystem"], "qname": "boost::filesystem::path", + "if": ""}, + {"ns": ["boost", "filesystem"], + "qname": "boost::filesystem::file_type::regular_file", "if": ""}, + {"ns": ["boost", "filesystem"], "qname": "boost::filesystem::fopen", + "if": "defined(_WIN32)"}, + {"ns": ["boost", "filesystem", "detail"], + "qname": "boost::filesystem::detail::status", "if": ""}, + ]} + + +ENTRY = {"namespace": "boost::dll::fs", "if": "!defined(USE_STD)", + "reason": "fs spelling"} + + +def policy(**overrides): + return gen_exports.Policy({"dll": {"republish": [dict(ENTRY, **overrides)]}}) + + +class RepublishTests(unittest.TestCase): + def setUp(self): + self.m = model() + + def collect(self, pol=None, pub=None, claimed=None, ups=("filesystem",)): + return gen_exports.collect_republished( + "dll", self.m, pol or policy(), published() if pub is None else pub, + set(ups), {} if claimed is None else claimed) + + def test_follows_the_owner_surface(self): + out, sources, entries, errors = self.collect() + self.assertEqual(errors, []) + self.assertEqual(sorted(out), [ + "boost::dll::fs::fopen", "boost::dll::fs::path", + "boost::dll::fs::regular_file"]) + rec = out["boost::dll::fs::regular_file"] + self.assertEqual(rec["qname"], + "::boost::filesystem::file_type::regular_file") + self.assertEqual(rec["ns"], ["boost", "dll", "fs"]) + self.assertEqual(rec["owner"], "filesystem") + self.assertEqual(list(sources), ["boost::dll::fs=boost::filesystem"]) + self.assertEqual(entries, [("dll", "republish", "boost::dll::fs", + "!defined(USE_STD)", "fs spelling")]) + + def test_entry_condition_combines_with_the_owner_guard(self): + out = self.collect()[0] + base = out["boost::dll::fs::path"]["guard"] + # One dict per condition: emit_inc groups consecutive names by it. + self.assertIs(out["boost::dll::fs::regular_file"]["guard"], base) + self.assertEqual(base, {"if": "!defined(USE_STD)", + "reason": "fs spelling"}) + self.assertEqual(out["boost::dll::fs::fopen"]["guard"]["if"], + "(!defined(USE_STD)) && (defined(_WIN32))") + + def test_without_condition_only_source_guards_apply(self): + pol = gen_exports.Policy({"dll": {"republish": [ + {"namespace": "boost::dll::fs", "reason": "r"}]}}) + out = self.collect(pol)[0] + self.assertIsNone(out["boost::dll::fs::path"]["guard"]) + self.assertEqual(out["boost::dll::fs::fopen"]["guard"]["if"], + "defined(_WIN32)") + + def test_name_claimed_earlier_is_left_out(self): + claimed = {"boost::dll::fs::path": "other"} + out = self.collect(claimed=claimed)[0] + self.assertNotIn("boost::dll::fs::path", out) + self.assertEqual( + claimed["boost::dll::fs::fopen=boost::filesystem::fopen"], "dll") + + def test_owner_must_be_upstream(self): + out, _, _, errors = self.collect(ups=("core",)) + self.assertEqual(out, {}) + self.assertEqual(len(errors), 1) + self.assertIn("no upstream module", errors[0]) + + def test_stale_entry_is_an_error(self): + errors = self.collect(policy(namespace="boost::dll::gone"))[3] + self.assertEqual(len(errors), 1) + self.assertIn("no using-directive", errors[0]) + + def test_cached_result_holds_only_while_the_owner_surface_does(self): + _, sources, _, _ = self.collect() + sk = {"republish": sources, "published": []} + ups = {"filesystem"} + self.assertTrue(gen_exports._republish_holds(sk, published(), ups)) + grown = published() + grown["filesystem"].append({"ns": ["boost", "filesystem"], + "qname": "boost::filesystem::space", + "if": ""}) + self.assertFalse(gen_exports._republish_holds(sk, grown, ups)) + self.assertFalse(gen_exports._republish_holds( + {"republish": sources}, published(), ups)) + + def test_upstreams_are_transitive(self): + graph = {"dll": {"filesystem"}, "filesystem": {"system"}, + "system": {"dll"}} + self.assertEqual(gen_exports.upstreams_of(graph, "dll"), + {"filesystem", "system"}) + + +class EmitRepublishedTests(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + self.addCleanup(self.tmp.cleanup) + self.root = Path(self.tmp.name) + + def test_inc_and_published_list(self): + out = gen_exports.collect_republished( + "dll", model(), policy(), published(), {"filesystem"}, {})[0] + out["own"] = {"home": "dll", "usr": "own", "qname": + "boost::dll::fs::error_code", "ns": ["boost", "dll", "fs"]} + pub = [] + count, deps, skipped = gen_exports.emit_inc( + "dll", out, self.root, {}, gen_exports.Policy({}), + extra_deps={"filesystem"}, published=pub) + self.assertEqual((count, deps, skipped), (4, ["filesystem"], [])) + inc = (self.root / "generated/exports/dll.inc").read_text() + block = inc[inc.index("export namespace boost { namespace dll"):] + self.assertEqual([ln for ln in block.splitlines() + if not ln.lstrip().startswith("//")], [ + "export namespace boost { namespace dll { namespace fs {", + "#if !defined(USE_STD)", + " using ::boost::filesystem::file_type::regular_file;", + "#endif", + "#if (!defined(USE_STD)) && (defined(_WIN32))", + " using ::boost::filesystem::fopen;", + "#endif", + "#if !defined(USE_STD)", + " using ::boost::filesystem::path;", + "#endif", + " using boost::dll::fs::error_code;", + "}}}"]) + self.assertIn({"ns": ["boost", "dll", "fs"], + "qname": "boost::filesystem::path", + "if": "!defined(USE_STD)"}, pub) + self.assertIn({"ns": ["boost", "dll", "fs"], + "qname": "boost::dll::fs::error_code", "if": ""}, pub) + + +if __name__ == "__main__": + unittest.main() From c973f114c1ee81f825660b3bf689e5a373c27d5a Mon Sep 17 00:00:00 2001 From: Zhe Feng Date: Sat, 28 Nov 2026 04:05:36 +0000 Subject: [PATCH 2/3] tests/dll: assert the boost::dll::fs spelling in the smoke test Same-type checks against boost::filesystem, program_location's return type, enumerators, Boost-only functions (unevaluated) and a temp-directory round trip through functions the hand-kept list lacked, on the error_code overloads. With main's dll.inc the file fails to compile on exactly those names. --- tests/dll/smoke.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/tests/dll/smoke.cpp b/tests/dll/smoke.cpp index 788b5937..e738c102 100644 --- a/tests/dll/smoke.cpp +++ b/tests/dll/smoke.cpp @@ -1,12 +1,91 @@ -// mcpplibs.mwrap.boost.dll smoke — shared_library default state only (path conversion on -// the MSVC flavor crashes in program_location — upstream issue, see M9 doc) +// mcpplibs.mwrap.boost.dll smoke — shared_library default state (path conversion on +// the MSVC flavor crashes in program_location — upstream issue, see M9 doc), and the +// boost::dll::fs spelling. Upstream that namespace is `using namespace +// boost::filesystem;`, which an importer cannot see; the module re-exports every name +// the filesystem module exports directly in boost::filesystem through it +// (tools/export_policy.toml [[dll.republish]]). The names below go beyond what the +// tests and examples use, including Boost-only ones (unique_path), so a narrowed +// re-export fails here. Filesystem calls use the error_code overloads: nothing throws. #include "../test_assert.hpp" import std; import mcpplibs.mwrap.boost.dll; -int main() { +namespace fs = boost::dll::fs; + +// The same entities as boost::filesystem, not look-alikes. +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); +// error_code / system_error are using-declarations in boost/dll/config.hpp. +static_assert(std::is_same_v); +static_assert(std::is_same_v); +// The API spells its paths dll::fs::path. +static_assert(std::is_same_v); +// Enumerators of the unscoped file_type / perms reach dll::fs like any other name. +static_assert(fs::regular_file == boost::filesystem::regular_file); +static_assert(fs::owner_read == boost::filesystem::owner_read); +// Functions outside the documented subset, unevaluated (unique_path needs the +// platform's random source; system_complete / portable_name are Boost-only). +static_assert(std::is_same_v); +static_assert(std::is_same_v())), + fs::path>); +static_assert(std::is_same_v); +static_assert(std::is_same_v())), + fs::file_status>); + +namespace { + +void shared_library_default_state() { boost::dll::shared_library lib; assert(!lib.is_loaded()); assert(!lib); +} + +void filesystem_through_dll_fs() { + fs::error_code ec; + const auto stamp = std::chrono::steady_clock::now().time_since_epoch().count(); + const fs::path dir = fs::temp_directory_path(ec) / ("boost-m-dll-fs-" + std::to_string(stamp)); + assert(!ec); + assert(fs::create_directories(dir / "sub", ec) && !ec); + assert(fs::is_directory(dir, ec)); + + const fs::path file = dir / "sub" / "a.txt"; + { + fs::ofstream out(file); + out << "abcdef"; + } + assert(fs::exists(file, ec)); + assert(fs::is_regular_file(fs::symlink_status(file, ec))); + assert(fs::status_known(fs::status(file, ec))); + assert(fs::file_size(file, ec) == 6 && !ec); + fs::resize_file(file, 2, ec); + assert(!ec && fs::file_size(file, ec) == 2); + assert(fs::hard_link_count(file, ec) == 1 && !ec); + assert((fs::status(file, ec).permissions() & fs::owner_read) != fs::no_perms); + assert(fs::space(dir, ec).capacity > 0 && !ec); + + fs::copy_file(file, dir / "b.txt", ec); + assert(!ec); + int files = 0; + for (fs::recursive_directory_iterator it(dir, ec), end; !ec && it != end; it.increment(ec)) + files += fs::is_regular_file(it->status()) ? 1 : 0; + assert(!ec && files == 2); + + fs::file_size(dir / "missing", ec); + assert(ec); + assert(fs::remove_all(dir, ec) == 4 && !ec); + assert(!fs::exists(dir, ec)); +} + +} // namespace + +int main() { + shared_library_default_state(); + filesystem_through_dll_fs(); return 0; } From fe6cec7373430ce236f7bb574c147aaabea28239 Mon Sep 17 00:00:00 2001 From: Zhe Feng Date: Sat, 28 Nov 2026 04:05:36 +0000 Subject: [PATCH 3/3] docs: the republish policy rule; design record for dll::fs --- .../2026-11-28-dll-fs-republish-design.md | 79 +++++++++++++++++++ .agents/docs/README.md | 7 +- docs/architecture.md | 9 ++- docs/architecture.zh.md | 9 ++- 4 files changed, 98 insertions(+), 6 deletions(-) create mode 100644 .agents/docs/2026-11-28-dll-fs-republish-design.md diff --git a/.agents/docs/2026-11-28-dll-fs-republish-design.md b/.agents/docs/2026-11-28-dll-fs-republish-design.md new file mode 100644 index 00000000..27291af0 --- /dev/null +++ b/.agents/docs/2026-11-28-dll-fs-republish-design.md @@ -0,0 +1,79 @@ +--- +subject: generator +status: landed +--- + +# `boost::dll::fs` 跟随 `boost::filesystem`:策略 `republish` + +来源:issue #2 的第一条验收标准,以及"建议方向"第 1 条。 + +## 问题 + +`boost/dll/config.hpp` 中 `boost::dll::fs` 的写法是 +`namespace boost { namespace dll { namespace fs { using namespace boost::filesystem; } } }` +(定义 `BOOST_DLL_USE_STD_FS` 时改为 `std::filesystem`)。导入模块的一方看不到 +using 指令。生成器目前只跟随 ADL 屏障形态的指令(目标命名空间嵌套在指令自身的 +命名空间里),所以这条指令被跳过。 + +PR #5 用 `[[dll.extra]]` 手写了 33 个名称(另有上游本来就是 using 声明的 +`error_code` / `system_error`)。和 #1 之前的 main 相比,`dll::fs::` 写法仍少了 +49 个,其中 28 个不是运算符(`symlink_status`、`space`、`permissions`、 +`create_symlink`、`unique_path` 等)。手写列表也不会随 Boost.Filesystem 升级更新。 +测试只用到了 `path`、`recursive_directory_iterator`、`is_regular_file` 三个名称。 + +## 决定 + +新增策略条目 `[[.republish]]`,字段为 `namespace`、`reason`,以及可选的 `if`。 + +- 生成器在该库的 TU 中找到 `namespace` 里的 using 指令,拿到它的目标命名空间 + (`boost::filesystem`)。 +- 名称来源是上游模块实际写进 `.inc` 的导出,即应用 drop、guard 之后的结果,并且 + 只取直接位于目标命名空间的那些(不含 `boost::filesystem::detail` 等嵌套命名 + 空间)。`emit_inc` 把每个库导出的名称记进 `published`;filesystem 按拓扑序 + 先于 dll 处理,所以处理 dll 时这些名称已经齐备。上游名称自带的 guard 会和条目 + 的 `if` 用 `&&` 合并。 +- 输出写成 `using ::boost::filesystem::X;`,放在 `export namespace boost::dll::fs` + 中,并整体包在 `#if !defined(BOOST_DLL_USE_STD_FS)` 里。拥有这些名称的库会加进 + `.deps`,保证模块 `export import` 了它。 +- 缓存:dll 的条目记下所用的来源列表(`republish`),以及自己导出的 + `published`。命中条件是来源列表与上游当前的导出一致:上游的输出可能因为 + 先认领者优先(first-wins)的归属而改变,dll 自己的 key 却没变。 +- 策略失效时直接报错,不静默跳过:TU 中没有这条指令,或者没有上游模块在目标 + 命名空间里导出名称。 +- `std::filesystem` 分支仍然是 `[[dll.extra]]`,放在 + `#if defined(BOOST_DLL_USE_STD_FS)` 中。它是固定的标准接口,这次按 + [fs.filesyn] 补全为 54 个名称;path 的运算符、`swap`、`hash_value` 靠 ADL + 查找,不逐个列出。 + +结果:`dll::fs` 现在导出 138 个 `boost::filesystem` 名称,与 `filesystem.inc` 在 +`boost::filesystem` 中直接导出的名称完全一致。重新生成后,只有 dll 的输出发生了 +变化。 + +## 否决的做法 + +- **自动跟随所有"目标由别的库拥有、所在命名空间不是 detail"的指令**(issue 中 + 提到的另一种写法):会一次性改变多个库的导出面,每一条都需要单独审查。issue #2 + 中其余几组名称仍按 issue 的计划逐个确认。显式的策略条目可以审查,也会写进 + `skipped.txt`。 +- **在 `republish` 上提供 `else`,把 std 列表放进 `#else` 分支**:当上游的部分 + 名称带有自己的 guard 时,按名称排序后,条目的 `#if` 块会被拆成几段,`#else` + 行就会重复输出。所以 std 列表留在独立的 `extra` 块里。 +- **写成 `using boost::dll::fs::X;`(#1 之前 main 的写法)**:两种写法指向同一个 + 实体。选用目标库的限定名,是为了让来源一目了然,也让以 `boost::filesystem::` + 开头的枚举项(`file_type::regular_file`)保持上游 `.inc` 原样的写法。 + +## 测试 + +- `tests/dll/smoke.cpp`: + - `static_assert` 检查 `dll::fs::path` 等名称与 `boost::filesystem` 中是同一 + 类型,`program_location()` 的返回类型是 `dll::fs::path`,枚举项可以写成 + `dll::fs::regular_file`; + - 以不求值的方式检查只有 Boost 才有的名称(`unique_path`、`system_complete`、 + `portable_name`); + - 在临时目录中用 `error_code` 重载调用一组旧列表里没有的函数 + (`symlink_status`、`resize_file`、`hard_link_count`、`space`、 + `status_known` 等)。 + + 换回 main 的 `dll.inc` 后,这个文件在 gcc 上编译失败,报的正是这些名称。 +- `tools/tests/test_gen_exports_republish.py`:覆盖来源选择、guard 合并、已被 + 认领的名称、上游不可达、过期条目、缓存失效和输出形态。 diff --git a/.agents/docs/README.md b/.agents/docs/README.md index 8932950e..6c66ac8a 100644 --- a/.agents/docs/README.md +++ b/.agents/docs/README.md @@ -27,7 +27,7 @@ - `todos/` 放尚未完成的工作项,它们不是决定的记录。 - 移动或改名用 `tools/doc-tools/move_record.py`,它同时改写仓库中对该文件的引用。 -共 28 篇记录(其中 0 篇已归档),1 项待办。 +共 29 篇记录(其中 0 篇已归档),1 项待办。 ## 进行中 @@ -43,6 +43,10 @@ - [设计记录的管理:只增不删、按年归档、生成的索引与 `tools/doc-tools/`](2026-11-08-design-records-management-design.md) — landed +### generator + +- [`boost::dll::fs` 跟随 `boost::filesystem`:策略 `republish`](2026-11-28-dll-fs-republish-design.md) — landed + ### tests - [PR #5 第二轮评审的 [nit] 修复:覆盖率按测试程序列出的用例核对](2026-11-21-pr5-review-nits-design.md) — active @@ -60,6 +64,7 @@ ### 2026-11 +- [`boost::dll::fs` 跟随 `boost::filesystem`:策略 `republish`](2026-11-28-dll-fs-republish-design.md) — landed - [PR #5 第二轮评审的 [nit] 修复:覆盖率按测试程序列出的用例核对](2026-11-21-pr5-review-nits-design.md) — active - [子工程复用根工程的构建产物,mcpp 升级到 2026.11.20.1](2026-11-20-sub-project-build-reuse-design.md) — active - [windows-llvm-msvc 上的进程崩溃:两个 clang 模块缺陷](2026-11-18-windows-msvc-module-crashes-analysis.md) — landed diff --git a/docs/architecture.md b/docs/architecture.md index 952b70ad..b76b70cf 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -167,6 +167,9 @@ libclang, no Python bindings, no LLVM release archive. deduction guides and class members are not candidates. - **Using-injections**: namespace-scope `using X::y;` / `using namespace X;` that give entities their public spelling (ADL barriers, `detail` re-exports). + A `using namespace` is followed only in the ADL-barrier shape (the target is + nested in the directive's own namespace); one that names another library's + namespace is followed when the policy declares it (`republish` below). - **Signature closure**: entities named by the candidates' signatures (parameters, results, bases, fields, typedef targets — with typedefs looked through), so the API's own types are exported with it. @@ -190,13 +193,15 @@ written reason and applied by the generator, never patched into its output: | `[[.guard]]` | wrap the matching exports in the upstream header's own condition (`#if defined(_WIN32)` ...), optional `#else` lines | | `[[.drop]]` | never export the matching names / namespaces | | `[[.extra]]` | verbatim declarations (the gcc `extern template` vtable workarounds) | +| `[[.republish]]` | the namespace holds `using namespace ;` for another library's namespace: every name that library exports directly in `` is re-exported through it, optionally under `if` (`boost::dll::fs` follows `boost::filesystem`) | | `add` | names no collector reaches (body-only or ADL-only references) | | `gmf`, `defines`, `facade-includes` | the bundle's include set and macros; facade-only includes | | `inline-namespaces` | export a macro-selected inline namespace through its parent | | `[.deps]` | module edge corrections; edges of the hand-written special modules | -`generated/meta/skipped.txt` lists every name a rule guards, drops or adds, so -the boundary is reviewable in one file, and `generated/meta/api-surface.json` +`generated/meta/skipped.txt` lists every name a rule guards, drops or adds, and +each `extra` / `republish` namespace, so the boundary is reviewable in one file, +and `generated/meta/api-surface.json` records the generator identity (clang release, target, defines) and per-library GMF, export count and edges. A diff after a compiler update therefore shows as a generator change, not as an unexplained API change. diff --git a/docs/architecture.zh.md b/docs/architecture.zh.md index 4dd005c6..1b5dc127 100644 --- a/docs/architecture.zh.md +++ b/docs/architecture.zh.md @@ -147,7 +147,9 @@ clang++ -std=c++23 --target=x86_64-w64-mingw32 --sysroot= \ friend 形式出现的声明、显式与偏特化(经由主模板可达)、推导指引以及类成员都 不是候选。 - **using 注入**:赋予实体公开拼写的命名空间作用域 `using X::y;` / - `using namespace X;`(ADL 屏障、`detail` 再导出)。 + `using namespace X;`(ADL 屏障、`detail` 再导出)。`using namespace` 只在 ADL + 屏障形态下跟随(目标嵌套在指令自身的命名空间内);指向其他库命名空间的指令, + 由策略声明后才跟随(见下文 `republish`)。 - **签名闭包**:候选签名中点名的实体(形参、返回值、基类、字段、typedef 目标—— typedef 会被看穿),使 API 自身的类型随之导出。 - **归属**:按依赖优先的顺序处理各库;第一个认领实体的库拥有它,之后的库在 @@ -167,13 +169,14 @@ clang++ -std=c++23 --target=x86_64-w64-mingw32 --sysroot= \ | `[[.guard]]` | 用上游头文件自身的条件包裹匹配的导出(`#if defined(_WIN32)` ...),可选 `#else` 行 | | `[[.drop]]` | 永不导出匹配的名字 / 命名空间 | | `[[.extra]]` | 原样声明(gcc `extern template` 虚表变通) | +| `[[.republish]]` | 该命名空间中有指向另一个库命名空间的 `using namespace ;`:把那个库直接导出在 `` 中的所有名字经由该命名空间再导出,可选 `if` 条件(`boost::dll::fs` 跟随 `boost::filesystem`) | | `add` | 没有收集器能到达的名字(只在函数体或 ADL 中出现的引用) | | `gmf`、`defines`、`facade-includes` | bundle 的 include 集合与宏;仅门面使用的 include | | `inline-namespaces` | 经由父命名空间导出由宏选择的 inline 命名空间 | | `[.deps]` | 模块边修正;手写特殊模块的边 | -`generated/meta/skipped.txt` 列出每条规则守卫、丢弃或添加的名字,边界可以在一个 -文件里审阅;`generated/meta/api-surface.json` 记录生成器身份(clang 版本、目标、 +`generated/meta/skipped.txt` 列出每条规则守卫、丢弃或添加的名字,以及每个 +`extra` / `republish` 命名空间,边界可以在一个文件里审阅;`generated/meta/api-surface.json` 记录生成器身份(clang 版本、目标、 宏定义)以及每个库的 GMF、导出数和边。因此编译器升级后的差异会显示为生成器 变化,而不是无法解释的 API 变化。