-
Notifications
You must be signed in to change notification settings - Fork 15
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
Improve linux dependency check #195
base: main
Are you sure you want to change the base?
Changes from all commits
85d239a
5ba5ca8
853eabc
6cdf0d8
70fa2a3
2c55752
4717a71
9e984d1
fa2818f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,31 @@ | ||
import type { GluegunPrint } from 'gluegun' | ||
import { execWithSudo } from '../../system/exec' | ||
import type { Dependency } from '../../system/types' | ||
import { findMissingDependencies, installPackages } from '../../system/packages' | ||
|
||
// apt-get install git wget flex bison gperf python-is-python3 python3-pip python3-serial python-setuptools cmake ninja-build ccache libffi-dev libssl-dev dfu-util | ||
export async function installDeps( | ||
spinner: ReturnType<GluegunPrint['spin']>, | ||
): Promise<void> { | ||
await execWithSudo( | ||
'apt-get install --yes git wget flex bison gperf python-is-python3 python3-pip python3-serial python3-setuptools cmake ninja-build ccache libffi-dev libssl-dev dfu-util', | ||
{ stdout: process.stdout }, | ||
) | ||
const dependencies: Dependency[] = [ | ||
{ name: 'bison', packageName: 'bison', type: 'binary' }, | ||
{ name: 'ccache', packageName: 'ccache', type: 'binary' }, | ||
{ name: 'cmake', packageName: 'cmake', type: 'binary' }, | ||
{ name: 'dfu-util', packageName: 'dfu-util', type: 'binary' }, | ||
{ name: 'flex', packageName: 'flex', type: 'binary' }, | ||
{ name: 'git', packageName: 'git', type: 'binary' }, | ||
{ name: 'gperf', packageName: 'gperf', type: 'binary' }, | ||
{ name: 'libffi', packageName: 'libffi-dev', type: 'library' }, | ||
{ name: 'libssl', packageName: 'libssl-dev', type: 'library' }, | ||
{ name: 'ninja', packageName: 'ninja-build', type: 'binary' }, | ||
{ name: 'pip', packageName: 'python-pip', type: 'binary' }, | ||
{ name: 'pyserial-miniterm', packageName: 'python3-serial', type: 'binary' }, | ||
{ name: 'python', packageName: 'python-is-python3', type: 'binary' }, | ||
{ name: 'setuptools', packageName: 'python3-setuptools', type: 'pylib' }, | ||
{ name: 'wget', packageName: 'wget', type: 'binary' }, | ||
] | ||
|
||
const missingDependencies = await findMissingDependencies(dependencies) | ||
if (missingDependencies.length !== 0) { | ||
await installPackages(missingDependencies) | ||
} | ||
spinner.succeed() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
import type { GluegunPrint } from 'gluegun' | ||
import { execWithSudo } from '../../system/exec' | ||
import type { Dependency } from '../../system/types' | ||
import { findMissingDependencies, installPackages } from '../../system/packages' | ||
|
||
export async function installDeps( | ||
spinner: ReturnType<GluegunPrint['spin']>, | ||
): Promise<void> { | ||
spinner.start('Installing python deps with apt-get') | ||
await execWithSudo( | ||
'apt-get install --yes python-is-python3 python3-pip python3-serial', | ||
{ stdout: process.stdout }, | ||
) | ||
const dependencies: Dependency[] = [ | ||
{ name: 'pip', packageName: 'python-pip', type: 'binary' }, | ||
{ name: 'pyserial-miniterm', packageName: 'python3-serial', type: 'binary' }, | ||
{ name: 'python', packageName: 'python-is-python3', type: 'binary' }, | ||
] | ||
|
||
const missingDependencies = await findMissingDependencies(dependencies) | ||
if (missingDependencies.length !== 0) { | ||
await installPackages(missingDependencies) | ||
} | ||
spinner.succeed() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import type { Dependency } from './types' | ||
import { execWithSudo } from '../system/exec' | ||
import { print, system } from 'gluegun' | ||
|
||
/** | ||
* Check if the list of dependencies are installed on the system. | ||
**/ | ||
export async function findMissingDependencies(dependencies: Dependency[]): Promise<Dependency[]> { | ||
const missingDependencies: Dependency[] = [] | ||
|
||
for (const dep of dependencies) { | ||
if (dep.type === 'binary') { | ||
if (system.which(dep.name) === null) { | ||
missingDependencies.push(dep) | ||
} | ||
} | ||
if (dep.type === 'library') { | ||
try { | ||
await system.run(`pkg-config --exists ${dep.name}`) | ||
} catch (error) { | ||
missingDependencies.push(dep) | ||
} | ||
} | ||
if (dep.type === 'pylib') { | ||
try { | ||
await system.run(`pip3 show ${dep.name}`) | ||
} catch (error) { | ||
missingDependencies.push(dep) | ||
} | ||
} | ||
} | ||
|
||
return missingDependencies | ||
} | ||
|
||
/** | ||
* Attempt to install packages on the linux platform. | ||
**/ | ||
export async function installPackages(packages: Dependency[]): Promise<void> { | ||
const packageManager = system.which('apt') | ||
|
||
if (packageManager !== null && packageManager !== undefined) { | ||
await execWithSudo( | ||
`${packageManager} install --yes ${packages.map((p) => p.packageName).join(' ')}`, | ||
{ stdout: process.stdout }, | ||
) | ||
} else { | ||
print.warning( | ||
'xs-dev attempted to install dependencies, but your Linux distribution is not yet supported', | ||
) | ||
print.warning( | ||
`Please install these dependencies before running this command again: ${packages.map((p) => p.packageName).join(', ')}`, | ||
) | ||
process.exit(1) | ||
} | ||
Comment on lines
+39
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a handy abstraction. I wonder if it's worth exploring integration something like UPT on top of this as a follow up. 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll have to read up on it, but I like the idea of letting another tool do all the work for us. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface Dependency { | ||
name: string | ||
packageName: string | ||
type: 'binary' | 'library' | 'pylib' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I changed this in #190, it actually broke some of the later steps during setup that I hadn't anticipated. It turns out, what needed to change was the actual platform file name, and I did so in one of these commits.