@@ -17,6 +17,7 @@ package utils
17
17
18
18
import (
19
19
"os"
20
+ "runtime"
20
21
"strings"
21
22
"unicode"
22
23
@@ -96,57 +97,71 @@ func ObjFileIsUpToDate(sourceFile, objectFile, dependencyFile *paths.Path) (bool
96
97
return f .Filter (rows , f .NotEquals ("" )), nil
97
98
}
98
99
99
- rows , err := readDepFileWithEncoding (nil )
100
- if err != nil {
101
- logrus .Debugf ("Could not read dependency file: %s" , dependencyFile )
102
- return false , err
103
- }
104
- if len (rows ) == 0 {
105
- return true , nil
106
- }
107
-
108
- firstRow := rows [0 ]
109
- if ! strings .HasSuffix (firstRow , ":" ) {
110
- logrus .Debugf ("No colon in first line of depfile" )
111
- return false , nil
112
- }
113
- objFileInDepFile := firstRow [:len (firstRow )- 1 ]
114
- if objFileInDepFile != objectFile .String () {
115
- logrus .Debugf ("Depfile is about different object file: %v" , objFileInDepFile )
116
- return false , nil
117
- }
118
-
119
- // The first line of the depfile contains the path to the object file to generate.
120
- // The second line of the depfile contains the path to the source file.
121
- // All subsequent lines contain the header files necessary to compile the object file.
122
-
123
- // If we don't do this check it might happen that trying to compile a source file
124
- // that has the same name but a different path wouldn't recreate the object file.
125
- if sourceFile .String () != strings .Trim (rows [1 ], " " ) {
126
- logrus .Debugf ("Depfile is about different source file: %v" , strings .Trim (rows [1 ], " " ))
127
- return false , nil
128
- }
100
+ checkDepFileWithEncoding := func (mapping * charmap.Charmap ) (bool , error ) {
101
+ rows , err := readDepFileWithEncoding (mapping )
102
+ if err != nil {
103
+ logrus .Debugf ("Could not read dependency file: %s" , dependencyFile )
104
+ return false , err
105
+ }
106
+ if len (rows ) == 0 {
107
+ return true , nil
108
+ }
129
109
130
- rows = rows [1 :]
131
- for _ , row := range rows {
132
- depStat , err := os .Stat (row )
133
- if err != nil && ! os .IsNotExist (err ) {
134
- // There is probably a parsing error of the dep file
135
- // Ignore the error and trigger a full rebuild anyway
136
- logrus .WithError (err ).Debugf ("Failed to read: %v" , row )
110
+ firstRow := rows [0 ]
111
+ if ! strings .HasSuffix (firstRow , ":" ) {
112
+ logrus .Debugf ("No colon in first line of depfile" )
137
113
return false , nil
138
114
}
139
- if os .IsNotExist (err ) {
140
- logrus .Debugf ("Not found: %v" , row )
115
+ objFileInDepFile := firstRow [:len (firstRow )- 1 ]
116
+ if objFileInDepFile != objectFile .String () {
117
+ logrus .Debugf ("Depfile is about different object file: %v" , objFileInDepFile )
141
118
return false , nil
142
119
}
143
- if depStat .ModTime ().After (objectFileStat .ModTime ()) {
144
- logrus .Debugf ("%v newer than %v" , row , objectFile )
120
+
121
+ // The first line of the depfile contains the path to the object file to generate.
122
+ // The second line of the depfile contains the path to the source file.
123
+ // All subsequent lines contain the header files necessary to compile the object file.
124
+
125
+ // If we don't do this check it might happen that trying to compile a source file
126
+ // that has the same name but a different path wouldn't recreate the object file.
127
+ if sourceFile .String () != strings .Trim (rows [1 ], " " ) {
128
+ logrus .Debugf ("Depfile is about different source file: %v" , strings .Trim (rows [1 ], " " ))
145
129
return false , nil
146
130
}
131
+
132
+ rows = rows [1 :]
133
+ for _ , row := range rows {
134
+ depStat , err := os .Stat (row )
135
+ if err != nil && ! os .IsNotExist (err ) {
136
+ // There is probably a parsing error of the dep file
137
+ // Ignore the error and trigger a full rebuild anyway
138
+ logrus .WithError (err ).Debugf ("Failed to read: %v" , row )
139
+ return false , nil
140
+ }
141
+ if os .IsNotExist (err ) {
142
+ logrus .Debugf ("Not found: %v" , row )
143
+ return false , nil
144
+ }
145
+ if depStat .ModTime ().After (objectFileStat .ModTime ()) {
146
+ logrus .Debugf ("%v newer than %v" , row , objectFile )
147
+ return false , nil
148
+ }
149
+ }
150
+
151
+ return true , nil
147
152
}
148
153
149
- return true , nil
154
+ // This is required because on Windows we don't know which enconding is used
155
+ // by gcc to write the dep file (it could be UTF-8 or any of the Windows
156
+ // default mappings. Would ISO8859_1 be enough? Or we should differentiate the
157
+ // various ISO8859_XX based on selected locale? Only time will tell...).
158
+ if runtime .GOOS == "windows" {
159
+ if upToDate , err := checkDepFileWithEncoding (charmap .ISO8859_1 ); err != nil {
160
+ return upToDate , nil
161
+ }
162
+ // Fallback to UTF-8...
163
+ }
164
+ return checkDepFileWithEncoding (nil )
150
165
}
151
166
152
167
func removeEndingBackSlash (s string ) string {
0 commit comments