Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Try harder to not recompile sketch without modifications. #2961

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

Open
cmaglie wants to merge 11 commits into arduino:master
base: master
Choose a base branch
Loading
from cmaglie:do-not-recompile-sketch
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
11 commits
Select commit Hold shift + click to select a range
18ae29d
Implemented proper .d file parser
cmaglie Aug 3, 2025
63d9cf0
Avoid rebuilding the sketch if the sketch file is unchanged.
cmaglie Jul 29, 2025
97254ae
makeSourceFile is now a method of SketchLibrariesDetector
cmaglie Aug 12, 2025
2daaabd
Clone list before changing it by append
cmaglie Aug 25, 2025
919852d
Allow dep-file generation in GCC preprocessor
cmaglie Aug 25, 2025
88e37f4
Refactored integration test
cmaglie Aug 26, 2025
35ec6f8
Added integration test for lib-discovery-caching
cmaglie Aug 26, 2025
1c57270
Fixed ObjFileIsUptodate checks in library discovery.
cmaglie Sep 2, 2025
35d8e80
Structure sourceFile is now copied instead of passed-by-pointer
cmaglie Sep 2, 2025
096d8fa
Tracing for Library Discovery
cmaglie Sep 2, 2025
f32315f
Build dir cleanup keeps lib-discovery output files
cmaglie Sep 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion internal/arduino/builder/builder.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io"
"os"
"path/filepath"
"sort"
"strings"

"github.com/arduino/arduino-cli/internal/arduino/builder/internal/compilation"
Expand Down Expand Up @@ -331,7 +332,7 @@ func (b *Builder) preprocess() error {
if b.logger.VerbosityLevel() == logger.VerbosityVerbose {
b.logger.Info(i18n.Tr("The list of included libraries has been changed... rebuilding all libraries."))
}
if err := b.librariesBuildPath.RemoveAll(); err != nil {
if err := b.removeBuildPathExecptLibsdiscoveryFiles(b.librariesBuildPath); err != nil {
return err
}
}
Expand Down Expand Up @@ -544,3 +545,28 @@ func (b *Builder) execCommand(command *paths.Process) error {

return command.Wait()
}

func (b *Builder) removeBuildPathExecptLibsdiscoveryFiles(pathToRemove *paths.Path) error {
filesToRemove, err := pathToRemove.ReadDirRecursiveFiltered(nil,
paths.FilterOutDirectories(),
paths.FilterOutSuffixes(".libsdetect.d"))
if err != nil {
return err
}
for _, f := range filesToRemove {
if err := f.Remove(); err != nil {
return err
}
}

dirsToRemove, err := pathToRemove.ReadDirRecursiveFiltered(nil, paths.FilterDirectories())
if err != nil {
return err
}
// Remove directories in reverse order (deepest first)
sort.Slice(dirsToRemove, func(i, j int) bool { return len(dirsToRemove[i].String()) > len(dirsToRemove[j].String()) })
for _, d := range dirsToRemove {
_ = d.Remove()
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

//go:build !windows

package utils
package cpp

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package utils
package cpp

import (
"golang.org/x/sys/windows"
Expand Down
139 changes: 139 additions & 0 deletions internal/arduino/builder/cpp/depfile.go
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// This file is part of arduino-cli.
//
// Copyright 2025 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 license@arduino.cc.

package cpp

import (
"errors"
"runtime"
"strings"
"unicode"

"github.com/arduino/go-paths-helper"
"go.bug.st/f"
)

// Dependencies represents the dependencies of a source file.
type Dependencies struct {
ObjectFile string
Dependencies []string
}

// ReadDepFile reads a dependency file and returns the dependencies.
// It may return nil if the dependency file is empty.
func ReadDepFile(depFilePath *paths.Path) (*Dependencies, error) {
depFileData, err := depFilePath.ReadFile()
if err != nil {
return nil, err
}

if runtime.GOOS == "windows" {
// This is required because on Windows we don't know which encoding is used
// by gcc to write the dep file (it could be UTF-8 or any of the Windows
// ANSI mappings).
if decoded, err := convertAnsiBytesToString(depFileData); err == nil {
if res, err := readDepFile(decoded); err == nil && res != nil {
return res, nil
}
}
// Fallback to UTF-8...
}

return readDepFile(string(depFileData))
}

func readDepFile(depFile string) (*Dependencies, error) {
rows, err := unescapeAndSplit(strings.ReplaceAll(depFile, "\r\n", "\n"))
if err != nil {
return nil, err
}
rows = f.Map(rows, strings.TrimSpace)
rows = f.Filter(rows, f.NotEquals(""))
if len(rows) == 0 {
return &Dependencies{}, nil
}

// The first line of the depfile contains the path to the object file to generate.
// The second line of the depfile contains the path to the source file.
// All subsequent lines contain the header files necessary to compile the object file.

if !strings.HasSuffix(rows[0], ":") {
return nil, errors.New("no colon in first item of depfile")
}
res := &Dependencies{
ObjectFile: strings.TrimSuffix(rows[0], ":"),
Dependencies: rows[1:],
}
return res, nil
}

func unescapeAndSplit(s string) ([]string, error) {
var res []string
backslash := false
dollar := false
current := strings.Builder{}
for _, c := range s {
if backslash {
switch c {
case ' ':
current.WriteRune(' ')
case '#':
current.WriteRune('#')
case '\\':
current.WriteRune('\\')
case '\n':
// ignore
default:
current.WriteRune('\\')
current.WriteRune(c)
}
backslash = false
continue
}
if dollar {
if c != '$' {
return nil, errors.New("invalid dollar sequence: $" + string(c))
}
current.WriteByte('$')
dollar = false
continue
}

if c == '\\' {
backslash = true
continue
}
if c == '$' {
dollar = true
continue
}

if unicode.IsSpace(c) {
if current.Len() > 0 {
res = append(res, current.String())
current.Reset()
}
continue
}
current.WriteRune(c)
}
if dollar {
return nil, errors.New("unclosed escape sequence at end of depfile")
}
if current.Len() > 0 {
res = append(res, current.String())
}
return res, nil
}
95 changes: 95 additions & 0 deletions internal/arduino/builder/cpp/depfile_test.go
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// This file is part of arduino-cli.
//
// Copyright 2025 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 license@arduino.cc.

package cpp

import (
"testing"

"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require"
)

func TestDepFileReader(t *testing.T) {
t.Run("0", func(t *testing.T) {
deps, err := ReadDepFile(paths.New("testdata", "depcheck.0.d"))
require.NoError(t, err)
require.NotNil(t, deps)
require.Len(t, deps.Dependencies, 302)
require.Equal(t, "sketch.ino.cpp.o", deps.ObjectFile)
require.Equal(t, "/home/megabug/Arduino/sketch/build/sketch/sketch.ino.cpp.merged", deps.Dependencies[0])
require.Equal(t, "/home/megabug/.arduino15/packages/arduino/hardware/zephyr/0.10.0-rc.10/variants/b_u585i_iot02a_stm32u585xx/llext-edk/include/zephyr/include/generated/zephyr/autoconf.h", deps.Dependencies[1])
require.Equal(t, "/home/megabug/.arduino15/packages/arduino/hardware/zephyr/0.10.0-rc.10/variants/b_u585i_iot02a_stm32u585xx/llext-edk/include/zephyr/include/zephyr/toolchain/zephyr_stdint.h", deps.Dependencies[2])
require.Equal(t, "/home/megabug/.arduino15/packages/arduino/hardware/zephyr/0.10.0-rc.10/libraries/Arduino_RPCLite/src/dispatcher.h", deps.Dependencies[301])
})
t.Run("1", func(t *testing.T) {
deps, err := ReadDepFile(paths.New("testdata", "depcheck.1.d"))
require.NoError(t, err)
require.NotNil(t, deps)
require.Equal(t, "sketch.ino.o", deps.ObjectFile)
require.Len(t, deps.Dependencies, 302)
require.Equal(t, "/home/megabug/Arduino/sketch/build/sketch/sketch.ino.cpp", deps.Dependencies[0])
require.Equal(t, "/home/megabug/.arduino15/packages/arduino/hardware/zephyr/0.10.0-rc.10/variants/b_u585i_iot02a_stm32u585xx/llext-edk/include/zephyr/include/generated/zephyr/autoconf.h", deps.Dependencies[1])
require.Equal(t, "/home/megabug/.arduino15/packages/arduino/hardware/zephyr/0.10.0-rc.10/variants/b_u585i_iot02a_stm32u585xx/llext-edk/include/zephyr/include/zephyr/toolchain/zephyr_stdint.h", deps.Dependencies[2])
require.Equal(t, "/home/megabug/.arduino15/packages/arduino/hardware/zephyr/0.10.0-rc.10/libraries/Arduino_RPCLite/src/dispatcher.h", deps.Dependencies[301])
})
t.Run("2", func(t *testing.T) {
deps, err := ReadDepFile(paths.New("testdata", "depcheck.2.d"))
require.NoError(t, err)
require.NotNil(t, deps)
require.Equal(t, "ske tch.ino.cpp.o", deps.ObjectFile)
require.Len(t, deps.Dependencies, 302)
require.Equal(t, "/home/megabug/Arduino/ske tch/build/sketch/ske tch.ino.cpp.merged", deps.Dependencies[0])
require.Equal(t, "/home/megabug/.arduino15/packages/arduino/hardware/zephyr/0.10.0-rc.10/variants/b_u585i_iot02a_stm32u585xx/llext-edk/include/zephyr/include/generated/zephyr/autoconf.h", deps.Dependencies[1])
require.Equal(t, "/home/megabug/.arduino15/packages/arduino/hardware/zephyr/0.10.0-rc.10/variants/b_u585i_iot02a_stm32u585xx/llext-edk/include/zephyr/include/zephyr/toolchain/zephyr_stdint.h", deps.Dependencies[2])
require.Equal(t, "/home/megabug/.arduino15/packages/arduino/hardware/zephyr/0.10.0-rc.10/libraries/Arduino_RPCLite/src/dispatcher.h", deps.Dependencies[301])
})
t.Run("3", func(t *testing.T) {
deps, err := ReadDepFile(paths.New("testdata", "depcheck.3.d"))
require.NoError(t, err)
require.NotNil(t, deps)
require.Equal(t, "myfile.o", deps.ObjectFile)
require.Len(t, deps.Dependencies, 3)
require.Equal(t, "/some/path\\twith/backslash and spaces/file.cpp", deps.Dependencies[0])
require.Equal(t, "/some/other$/path#/file.h", deps.Dependencies[1])
require.Equal(t, "/yet/ano\\ther/path/file.h", deps.Dependencies[2])
})
t.Run("4", func(t *testing.T) {
deps, err := ReadDepFile(paths.New("testdata", "depcheck.4.d"))
require.EqualError(t, err, "invalid dollar sequence: $a")
require.Nil(t, deps)
})
t.Run("6", func(t *testing.T) {
deps, err := ReadDepFile(paths.New("testdata", "depcheck.6.d"))
require.EqualError(t, err, "unclosed escape sequence at end of depfile")
require.Nil(t, deps)
})
t.Run("7", func(t *testing.T) {
deps, err := ReadDepFile(paths.New("testdata", "depcheck.7.d"))
require.EqualError(t, err, "no colon in first item of depfile")
require.Nil(t, deps)
})
t.Run("8", func(t *testing.T) {
deps, err := ReadDepFile(paths.New("testdata", "depcheck.8.d"))
require.NoError(t, err)
require.Nil(t, deps.Dependencies)
require.Empty(t, deps.ObjectFile)
})
t.Run("9", func(t *testing.T) {
deps, err := ReadDepFile(paths.New("testdata", "nonexistent.d"))
require.Error(t, err)
require.Nil(t, deps)
})
}
Loading
Loading

AltStyle によって変換されたページ (->オリジナル) /