Skip to content

Commit a14e0ef

Browse files
Pass FileToRead to ReadFileAndStoreInContext explicitly
Previously, this filename was set by GCCPreprocRunner into the context, because the full filename was not known until then. Since the previous commit, this filename is known by the ContainerAddPrototypes, which can just pass it to ReadFileAndStoreInContext explicitly. This allows Context::FileToRead to be removed. Signed-off-by: Matthijs Kooijman <[email protected]>
1 parent 85d3624 commit a14e0ef

5 files changed

+4
-9
lines changed

container_add_prototypes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (s *ContainerAddPrototypes) Run(ctx *types.Context) error {
5656
return i18n.WrapError(err)
5757
}
5858
commands := []types.Command{
59-
&ReadFileAndStoreInContext{Target: &ctx.SourceGccMinusE},
59+
&ReadFileAndStoreInContext{FileToRead: targetFilePath, Target: &ctx.SourceGccMinusE},
6060
&FilterSketchSource{Source: &ctx.SourceGccMinusE},
6161
&CTagsTargetFileSaver{Source: &ctx.SourceGccMinusE, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E},
6262
&CTagsRunner{},

gcc_preproc_runner.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ func GCCPreprocRunner(ctx *types.Context, sourceFilePath string, targetFilePath
5858
return i18n.WrapError(err)
5959
}
6060

61-
ctx.FileToRead = targetFilePath
62-
6361
return nil
6462
}
6563

read_file_and_store_in_context.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ import (
3636
)
3737

3838
type ReadFileAndStoreInContext struct {
39+
FileToRead string
3940
Target *string
4041
}
4142

4243
func (s *ReadFileAndStoreInContext) Run(ctx *types.Context) error {
43-
bytes, err := ioutil.ReadFile(ctx.FileToRead)
44+
bytes, err := ioutil.ReadFile(s.FileToRead)
4445
if err != nil {
4546
return i18n.WrapError(err)
4647
}

test/read_file_and_store_in_context_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ func TestReadFileAndStoreInContext(t *testing.T) {
4747
utils.WriteFile(file.Name(), "test test\nciao")
4848

4949
ctx := &types.Context{}
50-
ctx.FileToRead = file.Name()
5150

52-
command := &builder.ReadFileAndStoreInContext{Target: &ctx.SourceGccMinusE}
51+
command := &builder.ReadFileAndStoreInContext{FileToRead: file.Name(), Target: &ctx.SourceGccMinusE}
5352
err = command.Run(ctx)
5453
NoError(t, err)
5554

types/context.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ type Context struct {
8484
// Logging
8585
logger i18n.Logger
8686
DebugLevel int
87-
88-
// ReadFileAndStoreInContext command
89-
FileToRead string
9087
}
9188

9289
func (ctx *Context) ExtractBuildOptions() properties.Map {

0 commit comments

Comments
 (0)