Skip to content

Commit

Permalink
Feat: Have broader bitbake settings sanity checks
Browse files Browse the repository at this point in the history
When the user opens a new workspace he'll probably need to configure the
extension. Sanity checks are here to check that the settings are
remotely accurate. They don't check that bitbake is fully functionnal
but quickly allow detecting settings errors.

Previously, the only check and notification regarded the bitbake folder.
Now, the environment script is also checked. The build path doesn't need
to be checked because it is dynamically created.

The notification message has been changed to be more generic.
The "Open Settings" button now opens the workspace settings with a more
accurate filter.
  • Loading branch information
deribaucourt committed Nov 3, 2023
1 parent d6fca99 commit 034c462
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
14 changes: 7 additions & 7 deletions client/src/ui/ClientNotificationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ export class ClientNotificationManager {

buildHandlers (): Disposable[] {
const handlers = [
this.buildBitBakeNotFoundHandler()
this.bitBakeSettingsErrorHandler()
]

return handlers
}

private buildBitBakeNotFoundHandler (): Disposable {
const isNeverShowAgain = this.checkIsNeverShowAgain('custom/bitBakeNotFound')
private bitBakeSettingsErrorHandler (): Disposable {
const isNeverShowAgain = this.checkIsNeverShowAgain('custom/bitbakeSettingsError')
if (isNeverShowAgain) {
return { dispose: () => {} }
}
return this._client.onNotification('custom/bitBakeNotFound', () => {
return this._client.onNotification('custom/bitbakeSettingsError', (message?: string) => {
void window.showErrorMessage(
'BitBake folder could not be found. Please set its path in the settings. Optionally, also set an environment script.',
'BitBake could not be configured and started. To enable advanced Bitbake features, please configure the Bitbake extension.\n\n' + message,
'Open Settings',
'Close',
'Never Show Again'
)
.then((item) => {
if (item === 'Open Settings') {
void commands.executeCommand('workbench.action.openSettings', 'bitbake')
void commands.executeCommand('workbench.action.openWorkspaceSettings', '@ext:savoirfairelinux.bitbake')
} else if (item === 'Never Show Again') {
void this.neverShowAgain('custom/bitBakeNotFound')
void this.neverShowAgain('custom/bitbakeSettingsError')
}
})
})
Expand Down
6 changes: 3 additions & 3 deletions server/src/ServerNotificationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function setNotificationManagerConnection (connection: Connection): void
}

export type NotificationType =
'custom/bitBakeNotFound'
'custom/bitbakeSettingsError'

class ServerNotificationManager {
send (type: NotificationType, message?: string): void {
Expand All @@ -27,8 +27,8 @@ class ServerNotificationManager {
void _connection.sendNotification(type, message)
}

sendBitBakeNotFound (): void {
this.send('custom/bitBakeNotFound')
sendBitBakeSettingsError (message?: string): void {
this.send('custom/bitbakeSettingsError', message)
}
}

Expand Down
15 changes: 12 additions & 3 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,30 @@ function setSymbolScanner (newSymbolScanner: SymbolScanner | null): void {
contextHandler.symbolScanner = newSymbolScanner
}

function checkBitbakePresence (): void {
function checkBitbakeSettingsSanity (): boolean {
const bitbakeFolder = bitBakeProjectScanner.bitbakeDriver.bitbakeSettings.pathToBitbakeFolder
const bitbakeBinPath = bitbakeFolder + '/bin/bitbake'

if (!fs.existsSync(bitbakeBinPath)) {
serverNotificationManager.sendBitBakeNotFound()
serverNotificationManager.sendBitBakeSettingsError("Bitbake binary doesn't exist: " + bitbakeBinPath)
return false
}

const pathToEnvScript = bitBakeProjectScanner.bitbakeDriver.bitbakeSettings.pathToEnvScript
if (!fs.existsSync(pathToEnvScript)) {
serverNotificationManager.sendBitBakeSettingsError("Bitbake environment script doesn't exist: " + pathToEnvScript)
return false
}

return true
}

connection.onDidChangeConfiguration((change) => {
logger.level = change.settings.bitbake.loggingLevel
bitBakeProjectScanner.loadSettings(change.settings.bitbake, workspaceRoot)
checkBitbakeSettingsSanity()
bitBakeDocScanner.parseVariablesFile(bitBakeProjectScanner.bitbakeDriver.bitbakeSettings.pathToBitbakeFolder)
bitBakeDocScanner.parseVariableFlagFile(bitBakeProjectScanner.bitbakeDriver.bitbakeSettings.pathToBitbakeFolder)
checkBitbakePresence()
bitBakeProjectScanner.rescanProject()
})

Expand Down

0 comments on commit 034c462

Please sign in to comment.