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: Change working directory for relative paths settings #76

Merged
merged 2 commits into from
Nov 15, 2023
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
8 changes: 7 additions & 1 deletion client/src/lib/src/BitbakeSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ export interface BitbakeSettings {
pathToEnvScript: string
}

export function loadBitbakeSettings (settings: any, workspaceFolder: string = ''): BitbakeSettings {
export function loadBitbakeSettings (settings: any, workspaceFolder: string): BitbakeSettings {
/* eslint no-template-curly-in-string: "off" */
// The default values are defined in package.json
// Change the working directory to properly handle relative paths in the language client
try {
process.chdir(workspaceFolder)
} catch (err: any) {
console.error(`chdir: ${err}`)
}
let pathToBitbakeFolder: string = settings.pathToBitbakeFolder
pathToBitbakeFolder = pathToBitbakeFolder.replace('${workspaceFolder}', workspaceFolder)
pathToBitbakeFolder = path.resolve(pathToBitbakeFolder)
Expand Down
11 changes: 11 additions & 0 deletions client/src/lib/src/__tests__/driver/bitbake-settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import path from 'path'
import { loadBitbakeSettings } from '../../BitbakeSettings'

describe('BitbakeSettings Tests', () => {
Expand All @@ -19,4 +20,14 @@ describe('BitbakeSettings Tests', () => {
}, '/home/user/workspace')
expect(settings.pathToBuildFolder).toEqual('/home/user/workspace/build')
})

it('should expand relative paths', () => {
const settings = loadBitbakeSettings({
pathToBitbakeFolder: '',
pathToEnvScript: '',
// eslint-disable-next-line no-template-curly-in-string
pathToBuildFolder: './build'
}, __dirname)
expect(settings.pathToBuildFolder).toEqual(path.join(__dirname, '/build'))
})
})
Loading