[4453] use-package 带路径包名改为按 package/style 根目录直查 - #4463
Open
priyanshusky0 wants to merge 2 commits into
Open
Conversation
1200 的直查快路径只搜 $TEXMACS_PATH/packages 与 $TEXMACS_PATH/plugins/<首段>/packages,不查 $TEXMACS_HOME_PATH, 用户自己写的带路径包名在被别的包 use-package 时找不到,级联加载失效。 改为在 $TEXMACS_PACKAGE_ROOT、$TEXMACS_STYLE_ROOT 和文档所在目录 依次直查。两个根变量条目数是「2 + 插件个数」量级,不是递归展开 全部子目录的 $TEXMACS_STYLE_PATH,1200 的性能优化基本保留。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4453.
What was broken
A user package installed under
$TEXMACS_HOME_PATH/packages/that loads its ownsub-packages with a path-qualified name stopped cascading between 2026_2.6 and
2026_3.2. Given this layout:
where
unicode-core.tscontains:adding only
unicode-coreto a document silently fails to load the twosub-packages, and their macros render as raw markup (
⟨big-unicode-table|...⟩).Adding all three packages to the document's own list works, which is what made
the bug confusing. GNU TeXmacs 2.1.5 and 2026_2.6 are both fine.
Root cause
17e6bab45([1200], #4331) added a direct-lookup fast path toedit_env_rep::exec_use_package. When a package name contains/it callsresolve_dotted_package, which searched exactly two places:$TEXMACS_HOME_PATHis never consulted. Before [1200], resolution went through$TEXMACS_STYLE_PATH, whichinit_env_varsbuilds withsearch_sub_dirs (style_root | package_root)and which therefore contains$TEXMACS_HOME_PATH/packagesand every subdirectory below it.The design note in
devel/1200.mdsays the change is compatible because "所有样式文件均为裸包名,无一带
/". That holds for the bundled tree, but not foruser packages, where a slash-qualified name has always been valid.
Why adding packages to the document list still works: those names first pass
through
preprocess_style(new_style.cpp:118), which resolves them against$TEXMACS_STYLE_PATHand rewrites them to absolute paths beforeexec (USE_PACKAGE, ...). An absolute path also contains/, so it enters thesame fast path, but
url::operator*returns a rooted right operand unchanged(
lolly/System/Classes/url.cpp:645), so it still resolves. A relative nameinside a package body has no such fallback.
The failure is silent:
load_stringfails and the package is skipped. Theuse-package: package not found:line added by [1200] only appears with-debug-io.How it is fixed
resolve_dotted_packagenow takesbase_file_nameand searches, in order:$TEXMACS_PACKAGE_ROOT—$TEXMACS_HOME_PATH/packages,$TEXMACS_PATH/packages, andplugin_path ("packages")$TEXMACS_STYLE_ROOT— the same three for stylesrestores the behaviour the non-slash branch still has
This keeps the [1200] optimisation. Both root variables are set by
init_env_varsand hold on the order of2 + number of pluginsentries; theyare not
$TEXMACS_STYLE_PATH, whichsearch_sub_dirsexpands recursivelyinto every subdirectory. Measured stat calls to locate one bundled package:
main)plugin_path's base is$TEXMACS_HOME_PATH:$TEXMACS_PATH, so it fully coversthe old
$TEXMACS_PATH/plugins/<first-segment>/packagesrule and additionallyfixes plugin packages installed under the user's home.
resolve_pack_ingained an or-url branch that walks roots one at a time ratherthan handing the whole or-url to
resolve. This keeps ".stem before .ts" scopedto a single root, so a user package can override a bundled one, and it stops at
the first hit instead of sweeping every root for
.stemfirst.Only
exec_use_packagewas ever converted to the fast path —load_style_tree(
new_buffer.cpp:541) still uses the full$TEXMACS_STYLE_PATHand was neveraffected.
Testing
New test:
tests/Typeset/Env/use_package_resolve_test.cpp. It builds fixturesunder a temporary
$TEXMACS_HOME_PATH, uses only the entry package, and assertsthe cascaded macros actually reach the environment via
env->provides (...)rather than merely checking that files exist.
Run with
xmake b use_package_resolve_test && xmake r use_package_resolve_teston macOS arm64, Qt 6.8.3, releasedbg:
mainnested_user_packageTST-core/unicode-coreadded, both sub-packages must cascadedocument_relative_package<doc>/sub/, package in<doc>/relative/, found by ancestor walkhome_plugin_package$TEXMACS_HOME_PATH/plugins/<plugin>/packagesstyle_root_packagepackage_root_wins_over_style_rootbare_package_name_still_works/still use$TEXMACS_STYLE_PATH— guards the untouched branchmissing_package_is_silentThe two control cases passing on
mainmatter: they show the test discriminatesthis specific bug instead of failing wholesale.
Additionally verified end to end with the three
.tsfiles attached to theissue, installed in the exact layout reported. Loading only
unicode-core:big-unicode-table,small-unicode-table,unicode-figures-marker,uno-refand
uex-refall resolve with this patch, and onmainthe same check failswith
use-package: package not found: TST-core/unicode-core.Not verified locally: the full
--group=testssweep (the machine ran out ofdisk partway through linking, not a build error) and any Linux/GCC run. CI
covers both.