Skip to content

Commit

Permalink
Fix CMAKE_DO_NOT_EDIT_HEADER_PREFIX grammar (#103)
Browse files Browse the repository at this point in the history
* Fix CMAKE_DO_NOT_EDIT_HEADER_PREFIX grammar

* Update pico_project.py

* Update cmakeUtil.mts

* Update extension.mts
  • Loading branch information
NickGuyver authored Oct 31, 2024
1 parent 00722b4 commit 9ca0df0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
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 @@ -209,9 +210,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 @@ -322,7 +325,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

0 comments on commit 9ca0df0

Please sign in to comment.