Skip to content

Commit cc978ec

Browse files
Pass Context to ObjFileIsUpToDate
This does not use the passed variable yet, but prepares for a future commit. Signed-off-by: Matthijs Kooijman <[email protected]>
1 parent 788cecd commit cc978ec

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

Diff for: builder_utils/utils.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func compileFileWithRecipe(ctx *types.Context, sourcePath string, source string,
173173
return "", i18n.WrapError(err)
174174
}
175175

176-
objIsUpToDate, err := ObjFileIsUpToDate(properties[constants.BUILD_PROPERTIES_SOURCE_FILE], properties[constants.BUILD_PROPERTIES_OBJECT_FILE], filepath.Join(buildPath, relativeSource+".d"))
176+
objIsUpToDate, err := ObjFileIsUpToDate(ctx, properties[constants.BUILD_PROPERTIES_SOURCE_FILE], properties[constants.BUILD_PROPERTIES_OBJECT_FILE], filepath.Join(buildPath, relativeSource+".d"))
177177
if err != nil {
178178
return "", i18n.WrapError(err)
179179
}
@@ -190,7 +190,7 @@ func compileFileWithRecipe(ctx *types.Context, sourcePath string, source string,
190190
return properties[constants.BUILD_PROPERTIES_OBJECT_FILE], nil
191191
}
192192

193-
func ObjFileIsUpToDate(sourceFile, objectFile, dependencyFile string) (bool, error) {
193+
func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFile string) (bool, error) {
194194
sourceFile = filepath.Clean(sourceFile)
195195
objectFile = filepath.Clean(objectFile)
196196
dependencyFile = filepath.Clean(dependencyFile)

Diff for: container_find_includes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t
306306
// TODO: This reads the dependency file, but the actual building
307307
// does it again. Should the result be somehow cached? Perhaps
308308
// remove the object file if it is found to be stale?
309-
unchanged, err := builder_utils.ObjFileIsUpToDate(sourcePath, sourceFile.ObjectPath(ctx), sourceFile.DepfilePath(ctx))
309+
unchanged, err := builder_utils.ObjFileIsUpToDate(ctx, sourcePath, sourceFile.ObjectPath(ctx), sourceFile.DepfilePath(ctx))
310310
if err != nil {
311311
return i18n.WrapError(err)
312312
}

Diff for: test/builder_utils_test.go

+22-7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ package test
3131

3232
import (
3333
"github.com/arduino/arduino-builder/builder_utils"
34+
"github.com/arduino/arduino-builder/types"
3435
"github.com/arduino/arduino-builder/utils"
3536
"github.com/stretchr/testify/require"
3637
"io/ioutil"
@@ -52,27 +53,33 @@ func tempFile(t *testing.T, prefix string) string {
5253
}
5354

5455
func TestObjFileIsUpToDateObjMissing(t *testing.T) {
56+
ctx := &types.Context{}
57+
5558
sourceFile := tempFile(t, "source")
5659
defer os.RemoveAll(sourceFile)
5760

58-
upToDate, err := builder_utils.ObjFileIsUpToDate(sourceFile, "", "")
61+
upToDate, err := builder_utils.ObjFileIsUpToDate(ctx, sourceFile, "", "")
5962
NoError(t, err)
6063
require.False(t, upToDate)
6164
}
6265

6366
func TestObjFileIsUpToDateDepMissing(t *testing.T) {
67+
ctx := &types.Context{}
68+
6469
sourceFile := tempFile(t, "source")
6570
defer os.RemoveAll(sourceFile)
6671

6772
objFile := tempFile(t, "obj")
6873
defer os.RemoveAll(objFile)
6974

70-
upToDate, err := builder_utils.ObjFileIsUpToDate(sourceFile, objFile, "")
75+
upToDate, err := builder_utils.ObjFileIsUpToDate(ctx, sourceFile, objFile, "")
7176
NoError(t, err)
7277
require.False(t, upToDate)
7378
}
7479

7580
func TestObjFileIsUpToDateObjOlder(t *testing.T) {
81+
ctx := &types.Context{}
82+
7683
objFile := tempFile(t, "obj")
7784
defer os.RemoveAll(objFile)
7885
depFile := tempFile(t, "dep")
@@ -83,12 +90,14 @@ func TestObjFileIsUpToDateObjOlder(t *testing.T) {
8390
sourceFile := tempFile(t, "source")
8491
defer os.RemoveAll(sourceFile)
8592

86-
upToDate, err := builder_utils.ObjFileIsUpToDate(sourceFile, objFile, depFile)
93+
upToDate, err := builder_utils.ObjFileIsUpToDate(ctx, sourceFile, objFile, depFile)
8794
NoError(t, err)
8895
require.False(t, upToDate)
8996
}
9097

9198
func TestObjFileIsUpToDateObjNewer(t *testing.T) {
99+
ctx := &types.Context{}
100+
92101
sourceFile := tempFile(t, "source")
93102
defer os.RemoveAll(sourceFile)
94103

@@ -99,12 +108,14 @@ func TestObjFileIsUpToDateObjNewer(t *testing.T) {
99108
depFile := tempFile(t, "dep")
100109
defer os.RemoveAll(depFile)
101110

102-
upToDate, err := builder_utils.ObjFileIsUpToDate(sourceFile, objFile, depFile)
111+
upToDate, err := builder_utils.ObjFileIsUpToDate(ctx, sourceFile, objFile, depFile)
103112
NoError(t, err)
104113
require.True(t, upToDate)
105114
}
106115

107116
func TestObjFileIsUpToDateDepIsNewer(t *testing.T) {
117+
ctx := &types.Context{}
118+
108119
sourceFile := tempFile(t, "source")
109120
defer os.RemoveAll(sourceFile)
110121

@@ -122,12 +133,14 @@ func TestObjFileIsUpToDateDepIsNewer(t *testing.T) {
122133

123134
utils.WriteFile(depFile, objFile+": \\\n\t"+sourceFile+" \\\n\t"+headerFile)
124135

125-
upToDate, err := builder_utils.ObjFileIsUpToDate(sourceFile, objFile, depFile)
136+
upToDate, err := builder_utils.ObjFileIsUpToDate(ctx, sourceFile, objFile, depFile)
126137
NoError(t, err)
127138
require.False(t, upToDate)
128139
}
129140

130141
func TestObjFileIsUpToDateDepIsOlder(t *testing.T) {
142+
ctx := &types.Context{}
143+
131144
sourceFile := tempFile(t, "source")
132145
defer os.RemoveAll(sourceFile)
133146

@@ -143,12 +156,14 @@ func TestObjFileIsUpToDateDepIsOlder(t *testing.T) {
143156

144157
utils.WriteFile(depFile, objFile+": \\\n\t"+sourceFile+" \\\n\t"+headerFile)
145158

146-
upToDate, err := builder_utils.ObjFileIsUpToDate(sourceFile, objFile, depFile)
159+
upToDate, err := builder_utils.ObjFileIsUpToDate(ctx, sourceFile, objFile, depFile)
147160
NoError(t, err)
148161
require.True(t, upToDate)
149162
}
150163

151164
func TestObjFileIsUpToDateDepIsWrong(t *testing.T) {
165+
ctx := &types.Context{}
166+
152167
sourceFile := tempFile(t, "source")
153168
defer os.RemoveAll(sourceFile)
154169

@@ -166,7 +181,7 @@ func TestObjFileIsUpToDateDepIsWrong(t *testing.T) {
166181

167182
utils.WriteFile(depFile, sourceFile+": \\\n\t"+sourceFile+" \\\n\t"+headerFile)
168183

169-
upToDate, err := builder_utils.ObjFileIsUpToDate(sourceFile, objFile, depFile)
184+
upToDate, err := builder_utils.ObjFileIsUpToDate(ctx, sourceFile, objFile, depFile)
170185
NoError(t, err)
171186
require.False(t, upToDate)
172187
}

0 commit comments

Comments
 (0)