-
-
Notifications
You must be signed in to change notification settings - Fork 405
gRPC Compile
will now fail if a platform core has been modified.
#2551
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ac0ef0c
Slighlty moved variables near their utilization place
cmaglie 6992c97
Added facility to keep timestamps of used files
cmaglie b305906
Compile will fail if platforms are changed
cmaglie 8d4b820
Added integration test
cmaglie a4f3a10
Make linter happy
cmaglie 2f4afce
Fixed grammar
cmaglie 185627b
Test all monitored files
cmaglie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
internal/integrationtest/daemon/detect_core_changes_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// This file is part of arduino-cli. | ||
// | ||
// Copyright 2022 ARDUINO SA (http://www.arduino.cc/) | ||
// | ||
// This software is released under the GNU General Public License version 3, | ||
// which covers the main part of arduino-cli. | ||
// The terms of this license can be found at: | ||
// https://www.gnu.org/licenses/gpl-3.0.en.html | ||
// | ||
// You can be released from the requirements of the above licenses by purchasing | ||
// a commercial license. Buying such a license is mandatory if you want to | ||
// modify or otherwise use the software for commercial activities involving the | ||
// Arduino software without disclosing the source code of your own applications. | ||
// To purchase a commercial license, send an email to [email protected]. | ||
|
||
package daemon_test | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"testing" | ||
"time" | ||
|
||
"github.com/arduino/arduino-cli/internal/integrationtest" | ||
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" | ||
"github.com/arduino/go-paths-helper" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDetectionOfChangesInCoreBeforeCompile(t *testing.T) { | ||
cmaglie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// See: https://github.com/arduino/arduino-cli/issues/2523 | ||
|
||
env, cli := integrationtest.CreateEnvForDaemon(t) | ||
defer env.CleanUp() | ||
|
||
// Create a new instance of the daemon | ||
grpcInst := cli.Create() | ||
require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) { | ||
fmt.Printf("INIT> %v\n", ir.GetMessage()) | ||
})) | ||
|
||
// Install avr core | ||
installCl, err := grpcInst.PlatformInstall(context.Background(), "arduino", "avr", "", true) | ||
require.NoError(t, err) | ||
for { | ||
installResp, err := installCl.Recv() | ||
if errors.Is(err, io.EOF) { | ||
break | ||
} | ||
require.NoError(t, err) | ||
fmt.Printf("INSTALL> %v\n", installResp) | ||
} | ||
installCl.CloseSend() | ||
|
||
// Utility functions: tryCompile | ||
sketchPath, err := paths.New("testdata", "bare_minimum").Abs() | ||
require.NoError(t, err) | ||
tryCompile := func() error { | ||
compileCl, err := grpcInst.Compile(context.Background(), "arduino:avr:uno", sketchPath.String(), "") | ||
require.NoError(t, err) | ||
defer compileCl.CloseSend() | ||
for { | ||
if compileResp, err := compileCl.Recv(); errors.Is(err, io.EOF) { | ||
return nil | ||
} else if err != nil { | ||
return err | ||
} else { | ||
fmt.Printf("COMPILE> %v\n", compileResp) | ||
} | ||
} | ||
} | ||
|
||
// Utility functions: tryTouch will touch a file and see if the compile detects the change | ||
tryTouch := func(fileToTouch *paths.Path) { | ||
time.Sleep(time.Second) // await at least one second so the timestamp of the file is different | ||
|
||
// touch the file | ||
f, err := fileToTouch.Append() | ||
require.NoError(t, err) | ||
_, err = f.WriteString("\n") | ||
require.NoError(t, err) | ||
require.NoError(t, f.Close()) | ||
|
||
// try compile: should fail | ||
err = tryCompile() | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), "The instance is no longer valid and needs to be reinitialized") | ||
|
||
// re-init instance | ||
require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) { | ||
fmt.Printf("INIT> %v\n", ir.GetMessage()) | ||
})) | ||
|
||
// try compile: should succeed | ||
require.NoError(t, tryCompile()) | ||
} | ||
|
||
avrCorePath := cli.DataDir().Join("packages", "arduino", "hardware", "avr", "1.8.6") | ||
tryTouch(avrCorePath.Join("installed.json")) | ||
tryTouch(avrCorePath.Join("platform.txt")) | ||
tryTouch(avrCorePath.Join("platform.local.txt")) | ||
tryTouch(avrCorePath.Join("programmers.txt")) | ||
tryTouch(avrCorePath.Join("boards.txt")) | ||
tryTouch(avrCorePath.Join("boards.local.txt")) | ||
|
||
// Delete a file and check if the change is detected | ||
require.NoError(t, avrCorePath.Join("programmers.txt").Remove()) | ||
err = tryCompile() | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), "The instance is no longer valid and needs to be reinitialized") | ||
|
||
// Re-init instance and check again | ||
require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) { | ||
fmt.Printf("INIT> %v\n", ir.GetMessage()) | ||
})) | ||
require.NoError(t, tryCompile()) | ||
|
||
// Create a file and check if the change is detected | ||
{ | ||
f, err := avrCorePath.Join("programmers.txt").Create() | ||
require.NoError(t, err) | ||
require.NoError(t, f.Close()) | ||
} | ||
err = tryCompile() | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), "The instance is no longer valid and needs to be reinitialized") | ||
|
||
// Re-init instance and check again | ||
require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) { | ||
fmt.Printf("INIT> %v\n", ir.GetMessage()) | ||
})) | ||
require.NoError(t, tryCompile()) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.