Skip to content

Commit edff07d

Browse files
matthijskooijmancmaglie
authored andcommitted
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 652f830 commit edff07d

5 files changed

+4
-9
lines changed

container_add_prototypes.go

+1-1
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

-2
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

+2-1
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

+1-2
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

-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ type Context struct {
8888
logger i18n.Logger
8989
DebugLevel int
9090

91-
// ReadFileAndStoreInContext command
92-
FileToRead string
93-
9491
// Reuse old tools since the backing storage didn't change
9592
CanUseCachedTools bool
9693
}

0 commit comments

Comments
 (0)