Skip to content

Commit 210478f

Browse files
committed
Added charmap decoder in dep-file reader
1 parent ae11833 commit 210478f

File tree

1 file changed

+23
-7
lines changed
  • internal/arduino/builder/internal/utils

1 file changed

+23
-7
lines changed

Diff for: internal/arduino/builder/internal/utils/utils.go

+23-7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
f "github.com/arduino/arduino-cli/internal/algorithms"
2424
"github.com/arduino/go-paths-helper"
2525
"github.com/sirupsen/logrus"
26+
"golang.org/x/text/encoding/charmap"
2627
"golang.org/x/text/runes"
2728
"golang.org/x/text/transform"
2829
"golang.org/x/text/unicode/norm"
@@ -74,17 +75,32 @@ func ObjFileIsUpToDate(sourceFile, objectFile, dependencyFile *paths.Path) (bool
7475
return false, nil
7576
}
7677

77-
rows, err := dependencyFile.ReadFileAsLines()
78+
readDepFileWithEncoding := func(mapping *charmap.Charmap) ([]string, error) {
79+
data, err := dependencyFile.ReadFile()
80+
if err != nil {
81+
return nil, err
82+
}
83+
84+
if mapping != nil {
85+
decoded, err := mapping.NewDecoder().Bytes(data)
86+
if err != nil {
87+
return nil, err
88+
}
89+
data = decoded
90+
}
91+
92+
rows := strings.Split(strings.Replace(string(data), "\r\n", "\n", -1), "\n")
93+
rows = f.Map(rows, removeEndingBackSlash)
94+
rows = f.Map(rows, strings.TrimSpace)
95+
rows = f.Map(rows, unescapeDep)
96+
return f.Filter(rows, f.NotEquals("")), nil
97+
}
98+
99+
rows, err := readDepFileWithEncoding(nil)
78100
if err != nil {
79101
logrus.Debugf("Could not read dependency file: %s", dependencyFile)
80102
return false, err
81103
}
82-
83-
rows = f.Map(rows, removeEndingBackSlash)
84-
rows = f.Map(rows, strings.TrimSpace)
85-
rows = f.Map(rows, unescapeDep)
86-
rows = f.Filter(rows, f.NotEquals(""))
87-
88104
if len(rows) == 0 {
89105
return true, nil
90106
}

0 commit comments

Comments
 (0)