Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CMAKE_DO_NOT_EDIT_HEADER_PREFIX grammar #103

Merged
merged 7 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/pico_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,9 @@ def GenerateCMake(folder, params):
"# (note this can come from environment, CMake cache etc)\n\n"
)

# if you change the do never edit headline you need to change the check for it in extension.mts
# if you change the do not edit headline you need to change the check for it in extension.mts
cmake_header_us = (
"# == DO NEVER EDIT THE NEXT LINES for Raspberry Pi Pico VS Code Extension to work ==\n"
"# == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work ==\n"
"if(WIN32)\n"
" set(USERHOME $ENV{USERPROFILE})\n"
"else()\n"
Expand Down
12 changes: 9 additions & 3 deletions src/extension.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import NewProjectCommand from "./commands/newProject.mjs";
import Logger, { LoggerSource } from "./logger.mjs";
import {
CMAKE_DO_NOT_EDIT_HEADER_PREFIX,
CMAKE_DO_NOT_EDIT_HEADER_PREFIX_OLD,
cmakeGetSelectedBoard,
cmakeGetSelectedToolchainAndSDKVersions,
configureCmakeNinja,
Expand Down Expand Up @@ -207,9 +208,14 @@ export async function activate(context: ExtensionContext): Promise<void> {
// check if it has .vscode folder and cmake donotedit header in CMakelists.txt
if (
!existsSync(join(workspaceFolder.uri.fsPath, ".vscode")) ||
!readFileSync(cmakeListsFilePath)
.toString("utf-8")
.includes(CMAKE_DO_NOT_EDIT_HEADER_PREFIX)
!(
readFileSync(cmakeListsFilePath)
.toString("utf-8")
.includes(CMAKE_DO_NOT_EDIT_HEADER_PREFIX) ||
readFileSync(cmakeListsFilePath)
.toString("utf-8")
.includes(CMAKE_DO_NOT_EDIT_HEADER_PREFIX_OLD)
)
) {
Logger.warn(
LoggerSource.extension,
Expand Down
6 changes: 5 additions & 1 deletion src/utils/cmakeUtil.mts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { buildCMakeIncPath } from "./download.mjs";

export const CMAKE_DO_NOT_EDIT_HEADER_PREFIX =
// eslint-disable-next-line max-len
"== DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work ==";
export const CMAKE_DO_NOT_EDIT_HEADER_PREFIX_OLD =
// eslint-disable-next-line max-len
"== DO NEVER EDIT THE NEXT LINES for Raspberry Pi Pico VS Code Extension to work ==";

export async function getPythonPath(): Promise<string> {
Expand Down Expand Up @@ -333,7 +336,8 @@ export async function cmakeUpdateSDK(
const cmakeFilePath = join(folder.fsPath, "CMakeLists.txt");
// This regex requires multiline (m) and dotall (s) flags to work
const updateSectionRegex = new RegExp(
`^# ${CMAKE_DO_NOT_EDIT_HEADER_PREFIX}.*# =+$`,
`^# (${CMAKE_DO_NOT_EDIT_HEADER_PREFIX}` +
`|${CMAKE_DO_NOT_EDIT_HEADER_PREFIX_OLD}).*# =+$`,
"ms"
);
const picoBoardRegex = /^set\(PICO_BOARD\s+([^)]+)\)$/m;
Expand Down
Loading