Purpose
When analyzing the implementation of a dependency library, you need to find the library'ssource directorybefore Read/Grep. The package directory name in the Conan cache is a
short hash (e.g. freer1302c20ea6851), so you cannot guess by name; you must look up the cache database mapping. This skill provides
a script to automatically complete the location, compatible across machines (the source directory may differ on each computer).
Quick Use (Recommended)
~/.claude/skills/conan-source-lookup/find_lib_source.sh <库名> [版本号]
The script outputs therecommended source directory, top-level subdirectories, and example source files, which you can directly use for Read/Grep.
# 常见用法
find_lib_source.sh freertos # 自动选工程 conanfile.py 所需版本(标 ★)
find_lib_source.sh dlt698 1.0.10 # 指定版本
find_lib_source.sh v32g410x
find_lib_source.sh mcu_driver # 不在缓存 -> 回退搜索工程目录
After locating the directory, use Grep to search for symbols under that directory, or Read specific files. For example:
Grep pattern: xQueueSend path: /home/xx/.conan2/p/freer1302c20ea6851/s
Location Priority (Already Implemented by the Script, No Manual Work Needed)
- editable package: check
~/.conan2/editable_packages.json; if hit, the source is in the local working directory (not in the caches/). For examplemicro_crv_algorithm。 - Conan cache: check
~/.conan2/p/cache.sqlite3'srecipestable (reference -> hash directory), source is in~/.conan2/p/<hash>/s/(some packages usees/, the script automatically falls back).- When multiple versions coexist, ★ marks the version required by the project's current
conanfile.py. - Cache layout:
e/=recipe,s/=source,es/=exported source,d/=metadata. s//es/When neither exists, callconan cache path <ref> --folder sourceas a fallback for resolution (official command, compatible with future cache layout changes; at most once throughout, without slowing down common cases).
- When multiple versions coexist, ★ marks the version required by the project's current
- Directory scan fallback(when sqlite3 is unavailable): traverse
~/.conan2/p/*/e/conanfile.pyand match byname=(can correctly distinguish prefix collisions likedlt645/dlt698). - Project directory fallback(when the cache does not contain the package at all):
grep -rl 'name = "<库名>"' <搜索根> --include=conanfile.py. Two-phase search (first the current project ~0.5s, only if not hit expand to parent directories), and prune.git/build*to speed up; the search root can be overridden with the environment variableLIB_SEARCH_ROOTS(colon-separated).When the package is already in the conan cache (even if that version has no source), skip this step and no longer search the whole disk.
Manual Location (Equivalent Commands When the Script Is Unavailable)
# 1. 查缓存数据库, 拿到 hash 目录名
sqlite3 ~/.conan2/p/cache.sqlite3 \
"SELECT reference,path FROM recipes WHERE reference LIKE 'freertos/%';"
# freertos/10.4.3.1@xian/stable|freer1302c20ea6851
# 2. 源码目录 = ~/.conan2/p/<hash>/s (无 s/ 则用 es/)
ls ~/.conan2/p/freer1302c20ea6851/s
# (或用 conan 官方命令直接拿源码路径, 最稳健但 ~200ms)
conan cache path "freertos/10.4.3.1@xian/stable" --folder source
# 3. 缓存没有 -> 按配方 name 字段搜索工程目录
grep -rlE 'name *= *"mcu_driver"' /mnt/f/.../gitlab --include=conanfile.py
Cross-machine note: the cache root is preferentially taken from $CONAN_HOME, and only when it is empty use ~/.conan2。
Common Library Quick Reference (Measured on This Machine)
| Library Name | Type | Source Location | Key Subdirectories |
|---|---|---|---|
freertos |
Cache | ~/.conan2/p/freer1302c20ea6851/s |
freeRTOS/(tasks.c/queue.c/list.c) |
v32g410x |
Cache | ~/.conan2/p/v32g498a63ab2cde3f/s |
Inc/(lib_.h)、Src/(lib_.c) |
dlt698 |
Cache | ~/.conan2/p/dlt69e753b0a1ab7e2/s |
inc/、src/ |
dlt645 |
Cache | ~/.conan2/p/dlt6434b8d7face969/s |
Inc/、Src/ |
micro_crv_algorithm |
editable | .../gitlab/lib/micro_crv_algorithm |
Inc/、Src/ |
mcu_driver |
Local | <工程>/kernel/mcu_driver_lib |
driver/、include/、source/ |
The hash directories in the quick reference table are a snapshot of this machine and will change when switching machines/versions; rely on the script output, do not hardcode.
Notes
- Use the Conan package name for the library name (the
name = "..."in the recipe), not the directory name. For example, the package namemcu_drivercorresponds to the directorymcu_driver_lib; the package namev32g410xis notv32g410x_lib。 - In the cache, the same library often has multiple versions, and some older versions may only have the recipe
e/, without source codes/(never built on this machine); the script will mark "no s/ source directory", so just switch to a version with source code. - If what is being analyzed isa library modified by the project itself(not pulled by conan), prioritize looking at the source code under
kernel/、modules/orgitlab/lib/in the project, rather than the original version in the cache.