@@ -1368,42 +1368,27 @@ prepare_build(bool print_fingerprint,
13681368 }
13691369
13701370 // Set up project-level .mcpp/ directory for custom indices.
1371- // This creates .mcpp/.xlings.json with non-builtin, non-local index
1371+ // This creates .mcpp/.xlings.json with custom non-builtin index
13721372 // entries so xlings can clone them into the project-scoped data dir.
13731373 if (!m->indices .empty ()) {
13741374 auto cfg2 = get_cfg ();
13751375 if (cfg2) {
13761376 mcpp::config::ensure_project_index_dir (**cfg2, *root, m->indices );
13771377
1378- // Gap 1: On first build, .mcpp/ data/ may be empty because
1378+ // On first build, the project xlings data root may be empty because
13791379 // ensure_project_index_dir only writes .xlings.json but doesn't
1380- // trigger the actual clone. Check if there are any non-local,
1381- // non-builtin indices and whether .mcpp/ data/ exists with content.
1382- // If not, run xlings update to clone them before dependency resolution.
1383- bool hasCustomGitIndices = false ;
1380+ // trigger clone/link creation . Check whether there are any custom
1381+ // non-builtin indices and whether the project data roots have index content.
1382+ // If not, run xlings update before dependency resolution.
1383+ bool hasCustomIndices = false ;
13841384 for (auto & [idxName, spec] : m->indices ) {
1385- if (!spec.is_local () && !spec. is_builtin ()) {
1386- hasCustomGitIndices = true ;
1385+ if (!spec.is_builtin ()) {
1386+ hasCustomIndices = true ;
13871387 break ;
13881388 }
13891389 }
1390- if (hasCustomGitIndices) {
1391- auto dataDir = *root / " .mcpp" / " data" ;
1392- bool needsClone = !std::filesystem::exists (dataDir);
1393- if (!needsClone) {
1394- // Check if data/ has any index directories (dirs with pkgs/ subdir)
1395- std::error_code ec;
1396- bool hasIndexRepo = false ;
1397- if (std::filesystem::is_directory (dataDir, ec)) {
1398- for (auto & entry : std::filesystem::directory_iterator (dataDir, ec)) {
1399- if (entry.is_directory () && std::filesystem::exists (entry.path () / " pkgs" )) {
1400- hasIndexRepo = true ;
1401- break ;
1402- }
1403- }
1404- }
1405- needsClone = !hasIndexRepo;
1406- }
1390+ if (hasCustomIndices) {
1391+ bool needsClone = !mcpp::config::project_index_data_initialized (*root);
14071392 if (needsClone) {
14081393 mcpp::ui::status (" Fetching" , " custom index repos (first use)" );
14091394 auto projEnv = mcpp::config::make_project_xlings_env (**cfg2, *root);
@@ -1513,17 +1498,20 @@ prepare_build(bool print_fingerprint,
15131498 // validate the lua exists, then fall through to the normal install
15141499 // flow below.
15151500 if (idxSpec && idxSpec->is_local ()) {
1501+ auto indexPath = mcpp::config::resolve_project_index_path (*root, *idxSpec);
15161502 auto luaCheck = mcpp::fetcher::Fetcher::read_xpkg_lua_from_path (
1517- idxSpec-> path , shortName);
1503+ indexPath , shortName);
15181504 if (!luaCheck) return std::unexpected (std::format (
15191505 " dependency '{}': not found in local index at '{}'" ,
1520- depName, idxSpec-> path .string ()));
1506+ depName, indexPath .string ()));
15211507 // lua found — fall through to normal install path resolution.
15221508 }
15231509
1524- // For custom git indices, try project-level .mcpp/data/ first.
1510+ const bool useProjectEnv = idxSpec && !idxSpec->is_builtin ();
1511+
1512+ // For custom indices, try project-level xlings data roots first.
15251513 std::optional<std::filesystem::path> installed;
1526- if (idxSpec && !idxSpec-> is_local () && !idxSpec-> is_builtin () ) {
1514+ if (useProjectEnv ) {
15271515 installed = mcpp::fetcher::Fetcher::install_path_from_project_data (
15281516 *root, ns, shortName, version);
15291517 }
@@ -1539,11 +1527,6 @@ prepare_build(bool print_fingerprint,
15391527 : std::format (" {}.{}" , ns, shortName);
15401528 mcpp::ui::info (" Downloading" , std::format (" {} v{}" , fqname, version));
15411529
1542- // Gap 2: For custom git indices, install using the project-level
1543- // xlings env so packages land in .mcpp/data/xpkgs/ and the custom
1544- // index clone is visible to xlings during resolution.
1545- bool useProjectEnv = idxSpec && !idxSpec->is_local () && !idxSpec->is_builtin ();
1546-
15471530 auto install_one = [&](std::string target) -> std::expected<mcpp::xlings::CallResult, mcpp::pm::CallError> {
15481531 if (useProjectEnv) {
15491532 auto projEnv = mcpp::config::make_project_xlings_env (**cfg, *root);
@@ -1559,7 +1542,7 @@ prepare_build(bool print_fingerprint,
15591542 return fetcher.install (targets, &progress);
15601543 };
15611544 auto target = std::format (" {}@{}" , fqname, version);
1562- // For custom git indices, use indexName:shortName@version format
1545+ // For custom indices, use indexName:shortName@version format
15631546 // so xlings knows which index to resolve from.
15641547 if (useProjectEnv) {
15651548 target = std::format (" {}:{}@{}" , ns, shortName, version);
@@ -1800,6 +1783,9 @@ prepare_build(bool print_fingerprint,
18001783 const auto & name = item.name ;
18011784 auto & spec = item.spec ;
18021785
1786+ mcpp::pm::compat::normalize_nested_namespace (
1787+ spec.namespace_ , spec.shortName , spec.legacyDottedKey );
1788+
18031789 // Pin SemVer constraint before dedup/fetch.
18041790 if (auto r = resolveSemver (spec, name); !r) {
18051791 return std::unexpected (r.error ());
@@ -2965,7 +2951,7 @@ int cmd_index_update(const mcpplibs::cmdline::ParsedArgs& parsed) {
29652951 } else {
29662952 mcpp::ui::status (" Updated" , std::format (" project index `{}`" , idxName));
29672953 }
2968- break ; // ensure_project_index_dir handles all non-local indices at once
2954+ break ; // ensure_project_index_dir handles all custom indices at once
29692955 }
29702956 }
29712957 }
0 commit comments