Skip to content

Commit 7604e85

Browse files
committed
Added --skip-post-install flags. Refactored PostInstall function.
1 parent 7f6ca6f commit 7604e85

File tree

7 files changed

+105
-63
lines changed

7 files changed

+105
-63
lines changed

arduino/cores/packagemanager/install_uninstall.go

+11-14
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121

2222
"github.com/arduino/arduino-cli/arduino/cores"
2323
"github.com/arduino/arduino-cli/executils"
24-
"github.com/arduino/go-paths-helper"
2524
"github.com/pkg/errors"
2625
)
2726

@@ -35,33 +34,31 @@ func (pm *PackageManager) InstallPlatform(platformRelease *cores.PlatformRelease
3534
if err := platformRelease.Resource.Install(pm.DownloadDir, pm.TempDir, destDir); err != nil {
3635
return errors.Errorf("installing platform %s: %s", platformRelease, err)
3736
}
38-
39-
// Perform post install
40-
if platformRelease.IsTrusted {
41-
if err := pm.runPostInstallScript(destDir); err != nil {
42-
return errors.Errorf("running post install script for %s: %s", platformRelease, err)
43-
}
37+
if d, err := destDir.Abs(); err == nil {
38+
platformRelease.InstallDir = d
39+
} else {
40+
return err
4441
}
45-
4642
return nil
4743
}
4844

49-
func (pm *PackageManager) runPostInstallScript(destDir *paths.Path) error {
50-
absDestDir, err := destDir.Abs()
51-
if err != nil {
52-
return err
45+
// RunPostInstallScript runs the post_install.sh (or post_install.bat) script for the
46+
// specified platformRelease.
47+
func (pm *PackageManager) RunPostInstallScript(platformRelease *cores.PlatformRelease) error {
48+
if !platformRelease.IsInstalled() {
49+
return errors.New("platform not installed")
5350
}
5451
postInstallFilename := "post_install.sh"
5552
if runtime.GOOS == "windows" {
5653
postInstallFilename = "post_install.bat"
5754
}
58-
postInstall := absDestDir.Join(postInstallFilename)
55+
postInstall := platformRelease.InstallDir.Join(postInstallFilename)
5956
if postInstall.Exist() && postInstall.IsNotDir() {
6057
cmd, err := executils.Command(postInstall.String())
6158
if err != nil {
6259
return err
6360
}
64-
cmd.Dir = absDestDir.String()
61+
cmd.Dir = platformRelease.InstallDir.String()
6562
cmd.Stdout = nil
6663
cmd.Stderr = nil
6764
if err := cmd.Run(); err != nil {

cli/core/install.go

+6
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ func initInstallCommand() *cobra.Command {
4242
Args: cobra.MinimumNArgs(1),
4343
Run: runInstallCommand,
4444
}
45+
installCommand.Flags().BoolVar(&installFlags.skipPostInstall, "skip-post-install", false, "Do not run post-install scripts.")
4546
return installCommand
4647
}
4748

49+
var installFlags struct {
50+
skipPostInstall bool
51+
}
52+
4853
func runInstallCommand(cmd *cobra.Command, args []string) {
4954
inst, err := instance.CreateInstance()
5055
if err != nil {
@@ -66,6 +71,7 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
6671
PlatformPackage: platformRef.PackageName,
6772
Architecture: platformRef.Architecture,
6873
Version: platformRef.Version,
74+
SkipPostInstall: installFlags.skipPostInstall,
6975
}
7076
_, err := core.PlatformInstall(context.Background(), platformInstallReq, output.ProgressBar(), output.TaskProgress())
7177
if err != nil {

cli/core/upgrade.go

+6
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ func initUpgradeCommand() *cobra.Command {
4242
" " + os.Args[0] + " core upgrade arduino:samd",
4343
Run: runUpgradeCommand,
4444
}
45+
upgradeCommand.Flags().BoolVar(&upgradeFlags.skipPostInstall, "skip-post-install", false, "Do not run post-install scripts.")
4546
return upgradeCommand
4647
}
4748

49+
var upgradeFlags struct {
50+
skipPostInstall bool
51+
}
52+
4853
func runUpgradeCommand(cmd *cobra.Command, args []string) {
4954
inst, err := instance.CreateInstance()
5055
if err != nil {
@@ -91,6 +96,7 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
9196
Instance: inst,
9297
PlatformPackage: platformRef.PackageName,
9398
Architecture: platformRef.Architecture,
99+
SkipPostInstall: upgradeFlags.skipPostInstall,
94100
}
95101

96102
_, err := core.PlatformUpgrade(context.Background(), r, output.ProgressBar(), output.TaskProgress())

commands/core/install.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ package core
1717

1818
import (
1919
"context"
20-
"errors"
2120
"fmt"
2221

2322
"github.com/arduino/arduino-cli/arduino/cores"
2423
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
2524
"github.com/arduino/arduino-cli/commands"
2625
rpc "github.com/arduino/arduino-cli/rpc/commands"
26+
"github.com/pkg/errors"
2727
)
2828

2929
// PlatformInstall FIXMEDOC
@@ -49,7 +49,7 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallReq,
4949
return nil, fmt.Errorf("finding platform dependencies: %s", err)
5050
}
5151

52-
err = installPlatform(pm, platform, tools, downloadCB, taskCB)
52+
err = installPlatform(pm, platform, tools, downloadCB, taskCB, req.GetSkipPostInstall())
5353
if err != nil {
5454
return nil, err
5555
}
@@ -64,7 +64,8 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallReq,
6464

6565
func installPlatform(pm *packagemanager.PackageManager,
6666
platformRelease *cores.PlatformRelease, requiredTools []*cores.ToolRelease,
67-
downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB) error {
67+
downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB,
68+
skipPostInstall bool) error {
6869
log := pm.Log.WithField("platform", platformRelease)
6970

7071
// Prerequisite checks before install
@@ -138,6 +139,14 @@ func installPlatform(pm *packagemanager.PackageManager,
138139
}
139140
}
140141

142+
// Perform post install
143+
if !skipPostInstall && platformRelease.IsTrusted {
144+
log.Info("Running post_install script")
145+
if err := pm.RunPostInstallScript(platformRelease); err != nil {
146+
return errors.Errorf("running post install: %s", err)
147+
}
148+
}
149+
141150
log.Info("Platform installed")
142151
taskCB(&rpc.TaskProgress{Message: platformRelease.String() + " installed", Completed: true})
143152
return nil

commands/core/upgrade.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeReq,
4545
Package: req.PlatformPackage,
4646
PlatformArchitecture: req.Architecture,
4747
}
48-
if err := upgradePlatform(pm, ref, downloadCB, taskCB); err != nil {
48+
if err := upgradePlatform(pm, ref, downloadCB, taskCB, req.GetSkipPostInstall()); err != nil {
4949
return nil, err
5050
}
5151

@@ -57,7 +57,8 @@ func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeReq,
5757
}
5858

5959
func upgradePlatform(pm *packagemanager.PackageManager, platformRef *packagemanager.PlatformReference,
60-
downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB) error {
60+
downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB,
61+
skipPostInstall bool) error {
6162
if platformRef.PlatformVersion != nil {
6263
return fmt.Errorf("upgrade doesn't accept parameters with version")
6364
}
@@ -84,7 +85,7 @@ func upgradePlatform(pm *packagemanager.PackageManager, platformRef *packagemana
8485
if err != nil {
8586
return fmt.Errorf("platform %s is not installed", platformRef)
8687
}
87-
err = installPlatform(pm, platform, tools, downloadCB, taskCB)
88+
err = installPlatform(pm, platform, tools, downloadCB, taskCB, skipPostInstall)
8889
if err != nil {
8990
return err
9091
}

rpc/commands/core.pb.go

+62-43
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/commands/core.proto

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ message PlatformInstallReq {
3030
string architecture = 3;
3131
// Platform version to install.
3232
string version = 4;
33+
// Set to true to not run (eventual) post install scripts for trusted platforms
34+
bool skipPostInstall = 5;
3335
}
3436

3537
message PlatformInstallResp {
@@ -75,6 +77,8 @@ message PlatformUpgradeReq {
7577
string platform_package = 2;
7678
// Architecture name of the platform (e.g., `avr`).
7779
string architecture = 3;
80+
// Set to true to not run (eventual) post install scripts for trusted platforms
81+
bool skipPostInstall = 4;
7882
}
7983

8084
message PlatformUpgradeResp {

0 commit comments

Comments
 (0)