Skip to content

Commit bef9185

Browse files
committed
arduino/arduino-pro-ide#31: Include clangd for linux with 'bin' and 'lib' folders
1 parent b8fdb03 commit bef9185

File tree

5 files changed

+79
-25
lines changed

5 files changed

+79
-25
lines changed

arduino-ide-extension/scripts/download-cli.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
const DEFAULT_VERSION = '0.7.1'; // require('moment')().format('YYYYMMDD');
1414

15-
const os = require('os');
1615
const path = require('path');
1716
const shell = require('shelljs');
1817
const downloader = require('./downloader');
@@ -35,7 +34,7 @@
3534
const { platform, arch } = process;
3635

3736
const build = path.join(__dirname, '..', 'build');
38-
const cli = path.join(build, `arduino-cli${os.platform() === 'win32' ? '.exe' : ''}`);
37+
const cli = path.join(build, `arduino-cli${platform === 'win32' ? '.exe' : ''}`);
3938

4039
const suffix = (() => {
4140
switch (platform) {
@@ -57,6 +56,6 @@
5756
}
5857

5958
const url = `https://downloads.arduino.cc/arduino-cli${version.startsWith('nightly-') ? '/nightly' : ''}/arduino-cli_${version}_${suffix}`;
60-
downloader.download(url, cli, 'arduino-cli', force);
59+
downloader.downloadUnzipFile(url, cli, 'arduino-cli', force);
6160

6261
})();

arduino-ide-extension/scripts/download-ls.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
const DEFAULT_ALS_VERSION = 'nightly';
99
const DEFAULT_CLANGD_VERSION = '9.0.0';
1010

11-
const os = require('os');
1211
const path = require('path');
1312
const shell = require('shelljs');
1413
const downloader = require('./downloader');
@@ -39,34 +38,35 @@
3938
const { platform, arch } = process;
4039

4140
const build = path.join(__dirname, '..', 'build');
42-
const als = path.join(build, `arduino-language-server${os.platform() === 'win32' ? '.exe' : ''}`);
43-
const clangd = path.join(build, `clangd${os.platform() === 'win32' ? '.exe' : ''}`);
41+
const alsTarget = path.join(build, `arduino-language-server${platform === 'win32' ? '.exe' : ''}`);
4442

45-
let alsSuffix, clangdSuffix;
43+
let clangdTarget, alsSuffix, clangdSuffix;
4644
switch (platform) {
4745
case 'darwin':
46+
clangdTarget = path.join(build, 'bin', 'clangd')
4847
alsSuffix = 'Darwin_amd64.zip';
4948
clangdSuffix = 'macos.zip';
5049
break;
50+
case 'linux':
51+
clangdTarget = path.join(build, 'bin', 'clangd')
52+
alsSuffix = 'Linux_amd64.zip';
53+
clangdSuffix = 'linux.zip'
54+
break;
5155
case 'win32':
56+
clangdTarget = path.join(build, 'clangd.exe')
5257
alsSuffix = 'Windows_NT_amd64.zip';
5358
clangdSuffix = 'windows.zip';
5459
break;
55-
case 'linux':
56-
alsSuffix = 'Linux_amd64.zip';
57-
break;
5860
}
5961
if (!alsSuffix) {
6062
shell.echo(`The arduino-language-server is not available for ${platform} ${arch}.`);
6163
shell.exit(1);
6264
}
6365

6466
const alsUrl = `https://downloads.arduino.cc/arduino-language-server/${alsVersion === 'nightly' ? 'nightly/arduino-language-server' : 'arduino-language-server_' + alsVersion}_${alsSuffix}`;
65-
downloader.download(alsUrl, als, 'arduino-language-server', force);
67+
downloader.downloadUnzipAll(alsUrl, build, alsTarget, force);
6668

67-
if (clangdSuffix) {
68-
const clangdUrl = `https://downloads.arduino.cc/arduino-language-server/clangd/clangd_${clangdVersion}_${clangdSuffix}`;
69-
downloader.download(clangdUrl, clangd, 'clangd', force);
70-
}
69+
const clangdUrl = `https://downloads.arduino.cc/arduino-language-server/clangd/clangd_${clangdVersion}_${clangdSuffix}`;
70+
downloader.downloadUnzipAll(clangdUrl, build, clangdTarget, force);
7171

7272
})();

arduino-ide-extension/scripts/downloader.js

+50-5
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ process.on('uncaughtException', error => {
1717
throw error;
1818
});
1919

20-
exports.download = async (url, targetFile, filePrefix, force) => {
21-
const { platform, arch } = process;
22-
20+
/**
21+
* @param url {string} Download URL
22+
* @param targetFile {string} Path to the file to copy from the decompressed archive
23+
* @param filePrefix {string} Prefix of the file name found in the archive
24+
* @param force {boolean} Whether to download even if the target file exists
25+
*/
26+
exports.downloadUnzipFile = async (url, targetFile, filePrefix, force) => {
2327
if (fs.existsSync(targetFile) && !force) {
2428
shell.echo(`Skipping download because file already exists: ${targetFile}`);
2529
return;
@@ -65,7 +69,48 @@ exports.download = async (url, targetFile, filePrefix, force) => {
6569
if (!fs.existsSync(targetFile)) {
6670
shell.echo(`Could not find file: ${targetFile}`);
6771
shell.exit(1);
68-
} else {
69-
shell.echo(`Done: ${targetFile}`);
7072
}
73+
shell.echo(`Done: ${targetFile}`);
74+
}
75+
76+
/**
77+
* @param url {string} Download URL
78+
* @param targetDir {string} Directory into which to decompress the archive
79+
* @param targetFile {string} Path to the main file expected after decompressing
80+
* @param force {boolean} Whether to download even if the target file exists
81+
*/
82+
exports.downloadUnzipAll = async (url, targetDir, targetFile, force) => {
83+
if (fs.existsSync(targetFile) && !force) {
84+
shell.echo(`Skipping download because file already exists: ${targetFile}`);
85+
return;
86+
}
87+
if (!fs.existsSync(targetDir)) {
88+
if (shell.mkdir('-p', targetDir).code !== 0) {
89+
shell.echo('Could not create new directory.');
90+
shell.exit(1);
91+
}
92+
}
93+
94+
shell.echo(`>>> Downloading from '${url}'...`);
95+
const data = await download(url);
96+
shell.echo(`<<< Download succeeded.`);
97+
98+
shell.echo('>>> Decompressing...');
99+
const files = await decompress(data, targetDir, {
100+
plugins: [
101+
unzip(),
102+
untargz()
103+
]
104+
});
105+
if (files.length === 0) {
106+
shell.echo('Error ocurred while decompressing the archive.');
107+
shell.exit(1);
108+
}
109+
shell.echo('<<< Decompressing succeeded.');
110+
111+
if (!fs.existsSync(targetFile)) {
112+
shell.echo(`Could not find file: ${targetFile}`);
113+
shell.exit(1);
114+
}
115+
shell.echo(`Done: ${targetFile}`);
71116
}

arduino-ide-extension/src/node/arduino-backend-module.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
6464
bindBackendService(SketchesServicePath, SketchesService);
6565
});
6666
bind(ConnectionContainerModule).toConstantValue(sketchesServiceConnectionModule);
67-
67+
6868
// Config service
6969
bind(ConfigServiceImpl).toSelf().inSingletonScope();
7070
bind(ConfigService).toService(ConfigServiceImpl);
@@ -161,8 +161,14 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
161161

162162
// Set up cpp extension
163163
if (!process.env.CPP_CLANGD_COMMAND) {
164-
const executable = os.platform() === 'win32' ? 'clangd.exe' : 'clangd';
165-
const clangdCommand = join(__dirname, '..', '..', 'build', executable);
164+
const segments = ['..', '..', 'build'];
165+
if (os.platform() === 'win32') {
166+
segments.push('clangd.exe');
167+
} else {
168+
segments.push('bin');
169+
segments.push('clangd');
170+
}
171+
const clangdCommand = join(__dirname, ...segments);
166172
if (fs.existsSync(clangdCommand)) {
167173
process.env.CPP_CLANGD_COMMAND = clangdCommand;
168174
}

arduino-ide-extension/src/node/language/arduino-language-server-contribution.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export class ArduinoLanguageServerContribution extends BaseLanguageServerContrib
2424
}
2525

2626
async start(clientConnection: IConnection, options: LanguageServerStartOptions): Promise<void> {
27-
const clangd = await this.resolveExecutable('clangd');
2827
const languageServer = await this.resolveExecutable('arduino-language-server');
28+
const clangd = await this.resolveExecutable('clangd');
2929
const cli = await this.resolveExecutable('arduino-cli');
3030
// Add '-log' argument to enable logging to files
3131
const args: string[] = ['-clangd', clangd, '-cli', cli];
@@ -47,7 +47,11 @@ export class ArduinoLanguageServerContribution extends BaseLanguageServerContrib
4747

4848
protected resolveExecutable(name: string): Promise<string> {
4949
return new Promise<string>((resolve, reject) => {
50-
const path = `${process.env.PATH}${delimiter}${join(__dirname, '..', '..', '..', 'build')}`;
50+
const segments = ['..', '..', '..', 'build'];
51+
if (name === 'clangd' && os.platform() !== 'win32') {
52+
segments.push('bin');
53+
}
54+
const path = `${process.env.PATH}${delimiter}${join(__dirname, ...segments)}`;
5155
const suffix = os.platform() === 'win32' ? '.exe' : '';
5256
which(name + suffix, { path }, (err, execPath) => {
5357
if (err) {

0 commit comments

Comments
 (0)