Skip to content

Commit cb4c70c

Browse files
committed
Init submodules when not present in existing SDK download
Sometimes the SDK download is missing submodules due to errors (eg #127) Fix this by checking for all submodules when checking for SDK, and downloading them if not present
1 parent 3a77afb commit cb4c70c

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

src/utils/download.mts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
WINDOWS_ARM64_PYTHON_DOWNLOAD_URL,
4747
WINDOWS_X86_PYTHON_DOWNLOAD_URL,
4848
} from "./sharedConstants.mjs";
49+
import { compareGe } from "./semverUtil.mjs";
4950

5051
/// Translate nodejs platform names to ninja platform names
5152
const NINJA_PLATFORMS: { [key: string]: string } = {
@@ -485,8 +486,45 @@ export async function downloadAndInstallSDK(
485486
LoggerSource.downloader,
486487
`SDK ${version} is already installed.`
487488
);
488-
489-
return true;
489+
// Constants taken from the SDK CMakeLists.txt files
490+
const TINYUSB_TEST_PATH = joinPosix(
491+
"lib/tinyusb", "src/portable/raspberrypi/rp2040"
492+
);
493+
const CYW43_DRIVER_TEST_FILE = joinPosix("lib/cyw43-driver", "src/cyw43.h");
494+
const LWIP_TEST_PATH = joinPosix("lib/lwip", "src/Filelists.cmake");
495+
const BTSTACK_TEST_PATH = joinPosix("lib/btstack", "src/bluetooth.h");
496+
const MBEDTLS_TEST_PATH = joinPosix("lib/mbedtls", "library/aes.c")
497+
const submoduleChecks = [
498+
TINYUSB_TEST_PATH
499+
]
500+
if (compareGe(version, "1.4.0")) {
501+
submoduleChecks.push(CYW43_DRIVER_TEST_FILE);
502+
submoduleChecks.push(LWIP_TEST_PATH);
503+
}
504+
if (compareGe(version, "1.5.0")) {
505+
submoduleChecks.push(BTSTACK_TEST_PATH);
506+
submoduleChecks.push(MBEDTLS_TEST_PATH);
507+
}
508+
let submodulesPresent = true;
509+
for (const testPath of submoduleChecks) {
510+
if (!existsSync(joinPosix(targetDirectory, testPath))) {
511+
submodulesPresent = false;
512+
}
513+
}
514+
if (!submodulesPresent) {
515+
Logger.info(
516+
LoggerSource.downloader,
517+
`SDK ${version} is missing submodules - installing them now.`
518+
);
519+
const gitPath = await getGit(settings);
520+
if (gitPath !== undefined) {
521+
return initSubmodules(targetDirectory, gitPath);
522+
} else {
523+
return false;
524+
}
525+
} else {
526+
return true;
527+
}
490528
}
491529

492530
// Ensure the target directory exists

0 commit comments

Comments
 (0)