Skip to content

Commit 86a9b21

Browse files
committed
[ATL-1539] Integrate FWUploader into IDE2
1 parent 6515273 commit 86a9b21

File tree

3 files changed

+175
-2
lines changed

3 files changed

+175
-2
lines changed

Diff for: arduino-ide-extension/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
"description": "An extension for Theia building the Arduino IDE",
55
"license": "AGPL-3.0-or-later",
66
"scripts": {
7-
"prepare": "yarn download-cli && yarn download-ls && yarn clean && yarn download-examples && yarn build",
7+
"prepare": "yarn download-cli && yarn download-fwuploader && yarn download-ls && yarn clean && yarn download-examples && yarn build",
88
"clean": "rimraf lib",
99
"download-cli": "node ./scripts/download-cli.js",
10+
"download-fwuploader": "node ./scripts/download-fwuploader.js",
1011
"download-ls": "node ./scripts/download-ls.js",
1112
"download-examples": "node ./scripts/download-examples.js",
1213
"generate-protocol": "node ./scripts/generate-protocol.js",
@@ -137,6 +138,9 @@
137138
"arduino": {
138139
"cli": {
139140
"version": "0.18.3"
141+
},
142+
"fwuploader": {
143+
"version": "1.0.2"
140144
}
141145
}
142146
}

Diff for: arduino-ide-extension/scripts/download-fwuploader.js

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
// @ts-check
2+
3+
(async () => {
4+
const fs = require('fs');
5+
const path = require('path');
6+
const temp = require('temp');
7+
const shell = require('shelljs');
8+
const semver = require('semver');
9+
const downloader = require('./downloader');
10+
11+
const version = (() => {
12+
const pkg = require(path.join(__dirname, '..', 'package.json'));
13+
if (!pkg) {
14+
return undefined;
15+
}
16+
17+
const { arduino } = pkg;
18+
if (!arduino) {
19+
return undefined;
20+
}
21+
22+
const { fwuploader } = arduino;
23+
if (!fwuploader) {
24+
return undefined;
25+
}
26+
27+
const { version } = fwuploader;
28+
return version;
29+
})();
30+
31+
if (!version) {
32+
shell.echo(
33+
`Could not retrieve Firmware Uploader version info from the 'package.json'.`
34+
);
35+
shell.exit(1);
36+
}
37+
38+
const { platform, arch } = process;
39+
const buildFolder = path.join(__dirname, '..', 'build');
40+
const fwuploderName = `arduino-fwuploader${
41+
platform === 'win32' ? '.exe' : ''
42+
}`;
43+
const destinationPath = path.join(buildFolder, fwuploderName);
44+
45+
if (typeof version === 'string') {
46+
const suffix = (() => {
47+
switch (platform) {
48+
case 'darwin':
49+
return 'macOS_64bit.tar.gz';
50+
case 'win32':
51+
return 'Windows_64bit.zip';
52+
case 'linux': {
53+
switch (arch) {
54+
case 'arm':
55+
return 'Linux_ARMv7.tar.gz';
56+
case 'arm64':
57+
return 'Linux_ARM64.tar.gz';
58+
case 'x64':
59+
return 'Linux_64bit.tar.gz';
60+
default:
61+
return undefined;
62+
}
63+
}
64+
default:
65+
return undefined;
66+
}
67+
})();
68+
if (!suffix) {
69+
shell.echo(
70+
`The Firmware Uploader is not available for ${platform} ${arch}.`
71+
);
72+
shell.exit(1);
73+
}
74+
if (semver.valid(version)) {
75+
const url = `https://downloads.arduino.cc/arduino-fwuploader/arduino-fwuploader_${version}_${suffix}`;
76+
shell.echo(
77+
`📦 Identified released version of the Firmware Uploader. Downloading version ${version} from '${url}'`
78+
);
79+
await downloader.downloadUnzipFile(
80+
url,
81+
destinationPath,
82+
'arduino-fwuploader'
83+
);
84+
} else {
85+
shell.echo(`🔥 Could not interpret 'version': ${version}`);
86+
shell.exit(1);
87+
}
88+
} else {
89+
// We assume an object with `owner`, `repo`, commitish?` properties.
90+
const { owner, repo, commitish } = version;
91+
if (!owner) {
92+
shell.echo(`Could not retrieve 'owner' from ${JSON.stringify(version)}`);
93+
shell.exit(1);
94+
}
95+
if (!repo) {
96+
shell.echo(`Could not retrieve 'repo' from ${JSON.stringify(version)}`);
97+
shell.exit(1);
98+
}
99+
const url = `https://github.com/${owner}/${repo}.git`;
100+
shell.echo(
101+
`Building Firmware Uploader from ${url}. Commitish: ${
102+
commitish ? commitish : 'HEAD'
103+
}`
104+
);
105+
106+
if (fs.existsSync(destinationPath)) {
107+
shell.echo(
108+
`Skipping the Firmware Uploader build because it already exists: ${destinationPath}`
109+
);
110+
return;
111+
}
112+
113+
if (shell.mkdir('-p', buildFolder).code !== 0) {
114+
shell.echo('Could not create build folder.');
115+
shell.exit(1);
116+
}
117+
118+
const tempRepoPath = temp.mkdirSync();
119+
shell.echo(`>>> Cloning Firmware Uploader source to ${tempRepoPath}...`);
120+
if (shell.exec(`git clone ${url} ${tempRepoPath}`).code !== 0) {
121+
shell.exit(1);
122+
}
123+
shell.echo('<<< Cloned Firmware Uploader repo.');
124+
125+
if (commitish) {
126+
shell.echo(`>>> Checking out ${commitish}...`);
127+
if (
128+
shell.exec(`git -C ${tempRepoPath} checkout ${commitish}`).code !== 0
129+
) {
130+
shell.exit(1);
131+
}
132+
shell.echo(`<<< Checked out ${commitish}.`);
133+
}
134+
135+
shell.echo(`>>> Building the Firmware Uploader...`);
136+
if (shell.exec('go build', { cwd: tempRepoPath }).code !== 0) {
137+
shell.exit(1);
138+
}
139+
shell.echo('<<< Firmware Uploader build done.');
140+
141+
if (!fs.existsSync(path.join(tempRepoPath, fwuploderName))) {
142+
shell.echo(
143+
`Could not find the Firmware Uploader at ${path.join(
144+
tempRepoPath,
145+
fwuploderName
146+
)}.`
147+
);
148+
shell.exit(1);
149+
}
150+
151+
const builtFwUploaderPath = path.join(tempRepoPath, fwuploderName);
152+
shell.echo(
153+
`>>> Copying Firmware Uploader from ${builtFwUploaderPath} to ${destinationPath}...`
154+
);
155+
if (shell.cp(builtFwUploaderPath, destinationPath).code !== 0) {
156+
shell.exit(1);
157+
}
158+
shell.echo(`<<< Copied the Firmware Uploader.`);
159+
160+
shell.echo('<<< Verifying Firmware Uploader...');
161+
if (!fs.existsSync(destinationPath)) {
162+
shell.exit(1);
163+
}
164+
shell.echo('>>> Verified Firmware Uploader.');
165+
}
166+
})();

Diff for: arduino-ide-extension/src/node/executable-service-impl.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@ export class ExecutableServiceImpl implements ExecutableService {
1313
clangdUri: string;
1414
cliUri: string;
1515
lsUri: string;
16+
fwuploaderUri: string;
1617
}> {
17-
const [ls, clangd, cli] = await Promise.all([
18+
const [ls, clangd, cli, fwuploader] = await Promise.all([
1819
getExecPath('arduino-language-server', this.onError.bind(this)),
1920
getExecPath('clangd', this.onError.bind(this), undefined, true),
2021
getExecPath('arduino-cli', this.onError.bind(this)),
22+
getExecPath('arduino-fwuploader', this.onError.bind(this)),
2123
]);
2224
return {
2325
clangdUri: FileUri.create(clangd).toString(),
2426
cliUri: FileUri.create(cli).toString(),
2527
lsUri: FileUri.create(ls).toString(),
28+
fwuploaderUri: FileUri.create(fwuploader).toString(),
2629
};
2730
}
2831

0 commit comments

Comments
 (0)