Skip to content

Commit

Permalink
Merge pull request #953 from NordicSemiconductor/enhance/nrfutil
Browse files Browse the repository at this point in the history
Enhance nrfutil code
  • Loading branch information
datenreisender authored Nov 14, 2024
2 parents 402853b + 86603ad commit fc754d5
Show file tree
Hide file tree
Showing 14 changed files with 623 additions and 131 deletions.
18 changes: 18 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ This project does _not_ adhere to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html) but contrary to it
every new version is a new major version.

## 191.0.0 - 2024-11-14

### Added

- Function `getJlinkCompatibility`.

### Changed

- nrfutil: The core gets upgraded before installing a command.
- nrfutil: The `version` properties of dependencies are now optional,
reflecting the behaviour since `nrfutil-device` v2.7.0.
- Warning for J-Link versions: Only inform (not warn) if the installed version
is newer than the tested version. Updated the text for all cases.

### Removed

- Export of internal type `SemanticVersion`.

## 190.0.0 - 2024-11-06

### Added
Expand Down
5 changes: 1 addition & 4 deletions ipc/MetaFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ const nrfutilModuleVersion = semver;
export type NrfutilModuleName = z.infer<typeof nrfutilModuleName>;
export type NrfutilModuleVersion = z.infer<typeof nrfutilModuleVersion>;

export const nrfModules = z.record(
nrfutilModuleName,
nrfutilModuleVersion.array().nonempty()
);
export const nrfModules = z.record(nrfutilModuleName, z.tuple([semver]));

export type NrfutilModules = z.infer<typeof nrfModules>;
3 changes: 2 additions & 1 deletion ipc/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { handle, invoke } from './infrastructure/rendererToMain';
import { AppVersions, UrlString } from './MetaFiles';
import type { AppVersions, NrfutilModules, UrlString } from './MetaFiles';
import { LOCAL, Source, SourceName } from './sources';

export interface AppSpec {
Expand Down Expand Up @@ -33,6 +33,7 @@ interface Installed {
engineVersion?: string;
repositoryUrl?: UrlString;
html?: string;
nrfutil?: NrfutilModules;
installed: {
publishTimestamp?: string;
path: string;
Expand Down
59 changes: 37 additions & 22 deletions nrfutil/device/logLibVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ import { spawn } from 'child_process';
import os from 'os';

import describeError from '../../src/logging/describeError';
import {
describeVersion,
getExpectedVersion,
resolveModuleVersion,
} from '../moduleVersion';
import { getJlinkCompatibility } from '../jlinkVersion';
import { describeVersion, findDependency } from '../moduleVersion';
import { getNrfutilLogger } from '../nrfutilLogger';
import type { ModuleVersion, SubDependency } from '../sandboxTypes';
import type { Dependency, ModuleVersion } from '../sandboxTypes';

const log = (description: string, moduleVersion?: SubDependency | string) => {
const log = (
description: string,
dependencyOrVersion?: Dependency | string
) => {
const logger = getNrfutilLogger();
if (moduleVersion == null) {
if (dependencyOrVersion == null) {
logger?.warn(`Unable to detect version of ${description}.`);
} else {
logger?.info(
`Using ${description} version: ${describeVersion(moduleVersion)}`
`Using ${description} version: ${describeVersion(
dependencyOrVersion
)}`
);
}
};
Expand Down Expand Up @@ -75,24 +77,37 @@ export default async (moduleVersion: ModuleVersion) => {
const dependencies = moduleVersion.dependencies;

log('nrfutil-device', moduleVersion.version);
log('nrf-device-lib', resolveModuleVersion('nrfdl', dependencies));
log('nrfjprog DLL', resolveModuleVersion('jprog', dependencies));
log('JLink', resolveModuleVersion('JlinkARM', dependencies));
log('nrf-device-lib', findDependency('nrfdl', dependencies));
log('nrfjprog DLL', findDependency('jprog', dependencies));
log('JLink', findDependency('JlinkARM', dependencies));

const jlinkVersion = resolveModuleVersion('JlinkARM', dependencies);
const jlinkCompatibility = getJlinkCompatibility(moduleVersion);

if (jlinkVersion) {
const result = getExpectedVersion(jlinkVersion);
if (!result.isExpectedVersion) {
switch (jlinkCompatibility.kind) {
case 'No J-Link installed':
logger?.warn(
`Installed JLink version does not match the expected version (${result.expectedVersion})`
`SEGGER J-Link is not installed. ` +
`Install at least version ${jlinkCompatibility.requiredJlink} ` +
`from https://www.segger.com/downloads/jlink`
);
}
} else {
logger?.warn(
`JLink is not installed. Please install JLink from: https://www.segger.com/downloads/jlink`
);
break;
case 'Outdated J-Link':
logger?.warn(
`Outdated SEGGER J-Link. Your version of SEGGER J-Link (${jlinkCompatibility.actualJlink}) ` +
`is older than the one this app was tested with (${jlinkCompatibility.requiredJlink}). ` +
`Install the newer version from https://www.segger.com/downloads/jlink`
);
break;
case 'Newer J-Link is used':
logger?.info(
`Your version of SEGGER J-Link (${jlinkCompatibility.actualJlink}) ` +
`is newer than the one this app was tested with (${jlinkCompatibility.requiredJlink}). ` +
`The tested version is not required, and your J-Link version will most likely work fine.` +
` If you get issues related to J-Link with your devices, use the tested version.`
);
break;
}

if (
process.platform === 'darwin' &&
os.cpus()[0].model.includes('Apple')
Expand Down
3 changes: 2 additions & 1 deletion nrfutil/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

export { default as prepareSandbox } from './sandbox';
export { NrfutilSandbox } from './sandbox';
export type { Progress, SemanticVersion } from './sandboxTypes';
export type { Progress } from './sandboxTypes';
export { getNrfutilLogger, setNrfutilLogger } from './nrfutilLogger';
export {
getModule,
setLogLevel,
setVerboseLogging,
getAllModuleVersions,
} from './modules';
export { getJlinkCompatibility } from './jlinkVersion';
Loading

0 comments on commit fc754d5

Please sign in to comment.