Skip to content

Commit

Permalink
manifest: Support various variables in simple commands
Browse files Browse the repository at this point in the history
Fixes #223
  • Loading branch information
bilelmoussaoui committed Jan 21, 2024
1 parent 33e18a0 commit 91d102f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

- rust-analyzer: Ignore `.flatpak-builder`, `_build`, `build` directories
- manifest: Support `FLATPAK_ID` / `FLATPAK_ARCH` / `FLATPAK_DEST` / `FLATPAK_BUILDER_N_JOBS` / `FLATPAK_BUILDER_BUILDDIR` variables

## [0.0.36]

Expand Down
16 changes: 11 additions & 5 deletions src/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from 'vscode'
import { BuildOptionsPathKeys, ManifestSchema, Module, SdkExtension } from './flatpak.types'
import * as path from 'path'
import { cpus } from 'os'
import { arch, cpus } from 'os'
import * as fs from 'fs/promises'
import { Command } from './command'
import { generatePathOverride, getA11yBusArgs, getFontsArgs, getHostEnv } from './utils'
Expand Down Expand Up @@ -323,14 +323,14 @@ export class Manifest {
commands = this.getMesonCommands(rebuild, buildArgs, configOpts)
break
case 'simple':
commands = this.getSimpleCommands(module['build-commands'], buildArgs)
commands = this.getSimpleCommands(module.name, module['build-commands'], buildArgs)
break
case 'qmake':
throw new Error('Qmake is not implemented yet')
}
/// Add the post-install commands if there are any
commands.push(
... this.getSimpleCommands(this.module()['post-install'] || [], buildArgs)
... this.getSimpleCommands(this.module().name, this.module()['post-install'] || [], buildArgs)
)
return commands
}
Expand Down Expand Up @@ -524,11 +524,17 @@ export class Manifest {
return commands
}

getSimpleCommands(buildCommands: string[], buildArgs: string[]): Command[] {
getSimpleCommands(moduleName: string, buildCommands: string[], buildArgs: string[]): Command[] {
return buildCommands.map((command) => {
const commandArgs = command.replace('${FLATPAK_ID}', this.id())
.replace('${FLATPAK_ARCH}', arch())
.replace('${FLATPAK_DEST}', '/app') // We only support applications
.replace('${FLATPAK_BUILDER_N_JOBS}', cpus().length.toString())
.replace('${FLATPAK_BUILDER_BUILDDIR}', `/run/build/${moduleName}`)
.split(' ').filter((v) => !!v)
return new Command(
'flatpak',
['build', ...buildArgs, this.repoDir, ...command.split(' ').filter((v) => !!v)],
['build', ...buildArgs, this.repoDir, ...commandArgs],
{ cwd: this.workspace },
)
})
Expand Down

0 comments on commit 91d102f

Please sign in to comment.