Skip to content

Commit

Permalink
wip-use-relative-layer-paths-for-docker
Browse files Browse the repository at this point in the history
  • Loading branch information
deribaucourt committed Nov 29, 2023
1 parent 25b9d43 commit 8eeee69
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions client/src/driver/BitBakeProjectScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class BitBakeProjectScanner {
private _shouldDeepExamine: boolean = false
private _bitbakeDriver: BitbakeDriver | undefined
private _languageClient: LanguageClient | undefined
private containerWorkdir: string | undefined

setDriver (bitbakeDriver: BitbakeDriver): void {
this._bitbakeDriver = bitbakeDriver
Expand Down Expand Up @@ -78,6 +79,7 @@ export class BitBakeProjectScanner {
this.onChange.emit('startScan')

try {
await this.scanContainerWorkdir()
await this.scanAvailableLayers()
this.scanForClasses()
this.scanForIncludeFiles()
Expand Down Expand Up @@ -109,6 +111,11 @@ export class BitBakeProjectScanner {
}
}

private async scanContainerWorkdir (): Promise<void> {
// TODO How do we guess this?
this.containerWorkdir = '/work'
}

private printScanStatistic (): void {
logger.info('Scan results:')
logger.info('******************************************************************')
Expand Down Expand Up @@ -145,15 +152,15 @@ export class BitBakeProjectScanner {
}

for (const element of outputLines.slice(layersFirstLine + 2)) {
const tempElement: string[] = element.split(/\s+/)
const tempElement = element.split(/\s+/)
const layerElement = {
name: tempElement[0],
path: tempElement[1],
path: this.resolveContainerPath(tempElement[1]),
priority: parseInt(tempElement[2])
}

if ((layerElement.name !== undefined) && (layerElement.path !== undefined) && layerElement.priority !== undefined) {
this._bitbakeScanResult._layers.push(layerElement)
if ((layerElement.name !== undefined) && (layerElement.path !== undefined) && (layerElement.priority !== undefined)) {
this._bitbakeScanResult._layers.push(layerElement as LayerInfo)
}
}
} else {
Expand All @@ -162,6 +169,23 @@ export class BitBakeProjectScanner {
}
}

/// If a docker container is used, the workdir may be different from the host system.
/// This function resolves the path to the host system.
private resolveContainerPath (filePath: string | undefined): string | undefined {
if (filePath === undefined) {
return undefined
}
if (this.containerWorkdir === undefined) {
return filePath
}
const hostWorkdir = this.bitbakeDriver?.bitbakeSettings.workingDirectory
if (hostWorkdir === undefined) {
throw new Error('hostWorkdir is undefined')
}
const relativePath = path.relative(this.containerWorkdir, filePath)
return path.resolve(hostWorkdir, relativePath)
}

private searchFiles (pattern: string): ElementInfo[] {
const elements: ElementInfo[] = new Array < ElementInfo >()

Expand All @@ -181,6 +205,7 @@ export class BitBakeProjectScanner {
elements.push(element)
}
} catch (error) {
// EDRT REMOVE THIS BEFORE MERGING Fails here
logger.error(`find error: pattern: ${pattern} layer.path: ${layer.path} error: ${JSON.stringify(error)}`)
throw error
}
Expand Down

0 comments on commit 8eeee69

Please sign in to comment.