Skip to content
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

feat: use Arduino CLI 1.0.4 #2457

Merged
merged 5 commits into from
Sep 6, 2024
Merged

feat: use Arduino CLI 1.0.4 #2457

merged 5 commits into from
Sep 6, 2024

Conversation

giacomocusinato
Copy link
Collaborator

@giacomocusinato giacomocusinato commented Jun 17, 2024

Motivation

Use Arduino CLI 1.0.0 APIs in IDE2.

Change description

Update CLI version to 1.0.0, bind new APIs

Other information

Reviewer checklist

  • PR addresses a single concern.
  • The PR has no duplicates (please search among the Pull Requests before creating one)
  • PR title and description are properly filled.
  • Docs have been added / updated (for bug fixes / features)

@CLAassistant
Copy link

CLAassistant commented Jun 17, 2024

CLA assistant check
All committers have signed the CLA.

@per1234 per1234 added type: enhancement Proposed improvement topic: infrastructure Related to project infrastructure topic: CLI Related to Arduino CLI labels Jun 17, 2024
@giacomocusinato giacomocusinato marked this pull request as ready for review June 27, 2024 16:48
@giacomocusinato giacomocusinato marked this pull request as draft July 1, 2024 18:21
The npm package previously used (`protoc`) is still lacking apple arm32 support, see YePpHa/node-protoc#10
@giacomocusinato giacomocusinato force-pushed the use-cli-1.0.0 branch 2 times, most recently from d396032 to aca5ece Compare July 12, 2024 14:42
@@ -182,7 +182,11 @@ export class ConfigServiceImpl
});
const model = (yaml.safeLoad(content) || {}) as DefaultCliConfig;
this.logger.info(`Loaded CLI configuration: ${JSON.stringify(model)}`);
if (model.directories.data && model.directories.user) {
if (
model.directories &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If directories is optional, I propose reflecting it on the type:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think directories can be undefined only on the initial parse of the current config.
We can manipolate the loaded config object to assure the directories are alway defined object returned by loadCliConfig is always of type DefaultCliConfig.

That's the current logic:

  1. Load current cli config as type CliConfig (optional directories).
  2. Check directories value:
    1. If defined, return config as DefaultCliConfig type
    2. If undefined, call getFallbackCliConfig to get default directories, merge them to current config and return the object as DefaultCliConfig

Comment on lines 224 to 229
const rawJson = await spawnCommand(cliPath, ['config', 'dump', '--json']);
const config = JSON.parse(rawJson);

// Since CLI 1.0, the command `config dump` only returns user-modified values and not default ones.
// directories.user and directories.data are required by IDE2 so we get the default value explicitly.
const directoriesRaw = await spawnCommand(cliPath, [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CLI executions do not depend on each other: they can spawn parallel with Promise.all()

Comment on lines 321 to 316
const client = createArduinoCoreServiceClient({ port });
const req = new SettingsSetValueRequest();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a new CLI behavior? I see a client is created before setting each value. Can it be moved outside of the loop?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes CLI config API's were refactored and they now only exposed methods for retrieving/setting single values, instead of the previous "merge" approach.
I agree the client should be created one time outside the loop. Thanks for the review! 👍


const cliConfigUri = await this.getCliConfigFileUri();
const cliConfigPath = FileUri.fsPath(cliConfigUri);
fs.writeFile(cliConfigPath, configRaw, { encoding: 'utf-8' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing await or return

@giacomocusinato giacomocusinato marked this pull request as ready for review July 22, 2024 08:58
@giacomocusinato giacomocusinato force-pushed the use-cli-1.0.0 branch 2 times, most recently from d78e917 to 15e2a19 Compare July 26, 2024 12:54
@giacomocusinato giacomocusinato changed the title feat: use Arduino CLI 1.0.0 feat: use Arduino CLI 1.0.3 Jul 26, 2024
@giacomocusinato giacomocusinato changed the title feat: use Arduino CLI 1.0.3 feat: use Arduino CLI 1.0.4 Aug 20, 2024
Arduino deprecated platforms should have more priority then other deprecated ones
@giacomocusinato giacomocusinato merged commit 1ec0a8c into main Sep 6, 2024
25 checks passed
@giacomocusinato giacomocusinato deleted the use-cli-1.0.0 branch September 6, 2024 09:38
dankeboy36 added a commit to dankeboy36/ardunno-cli-gen that referenced this pull request Nov 17, 2024
dankeboy36 added a commit to dankeboy36/ardunno-cli-gen that referenced this pull request Nov 17, 2024
* fix: patch for missing `google` proto files in CLI (arduino/arduino-cli#2755)
* chore: replace `protoc` with `@pingghost/protoc` (arduino/arduino-ide#2457)
* chore(ci): build on Node.js 20.x
* fix(doc): refresh docs, update protoc version
* chore: update formatter + fix example command

---------

Signed-off-by: dankeboy36 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: CLI Related to Arduino CLI topic: infrastructure Related to project infrastructure type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants