Skip to content

Commit 8d4dce3

Browse files
author
Federico Fissore
committed
CTags is now run only once, using the file it reports to filter prototypes
which belong to the sketch. Fixes #52 Signed-off-by: Federico Fissore <f.fissore@arduino.cc>
1 parent cdd452b commit 8d4dce3

File tree

3 files changed

+64
-16
lines changed

3 files changed

+64
-16
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* This file is part of Arduino Builder.
3+
*
4+
* Arduino Builder is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
* As a special exception, you may use this file as part of a free software
19+
* library without restriction. Specifically, if other files instantiate
20+
* templates or use macros or inline functions from this file, or you compile
21+
* this file and link it with other files to produce an executable, this
22+
* file does not by itself cause the resulting executable to be covered by
23+
* the GNU General Public License. This exception does not however
24+
* invalidate any other reasons why the executable file might be covered by
25+
* the GNU General Public License.
26+
*
27+
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
28+
*/
29+
30+
package builder
31+
32+
import (
33+
"arduino.cc/builder/constants"
34+
"arduino.cc/builder/types"
35+
"arduino.cc/builder/utils"
36+
)
37+
38+
type CollectCTagsFromSketchFiles struct{}
39+
40+
func (s *CollectCTagsFromSketchFiles) Run(context map[string]interface{}) error {
41+
sketch := context[constants.CTX_SKETCH].(*types.Sketch)
42+
sketchFileNames := collectSketchFileNamesFrom(sketch)
43+
44+
ctags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]map[string]string)
45+
ctagsOfSketch := []map[string]string{}
46+
for _, ctag := range ctags {
47+
if utils.SliceContains(sketchFileNames, ctag[FIELD_FILENAME]) {
48+
ctagsOfSketch = append(ctagsOfSketch, ctag)
49+
}
50+
}
51+
52+
context[constants.CTX_COLLECTED_CTAGS] = ctagsOfSketch
53+
54+
return nil
55+
}
56+
57+
func collectSketchFileNamesFrom(sketch *types.Sketch) []string {
58+
fileNames := []string{sketch.MainFile.Name}
59+
for _, file := range sketch.OtherSketchFiles {
60+
fileNames = append(fileNames, file.Name)
61+
}
62+
return fileNames
63+
}

src/arduino.cc/builder/container_add_prototypes.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ func (s *ContainerAddPrototypes) Run(context map[string]interface{}) error {
4444
&CTagsTargetFileSaver{SourceField: constants.CTX_GCC_MINUS_E_SOURCE, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E},
4545
&CTagsRunner{},
4646
&CTagsParser{CTagsField: constants.CTX_CTAGS_OF_PREPROC_SOURCE},
47-
&CTagsTargetFileSaver{SourceField: constants.CTX_SOURCE, TargetFileName: constants.FILE_CTAGS_TARGET},
48-
&CTagsRunner{},
49-
&CTagsParser{CTagsField: constants.CTX_CTAGS_OF_SOURCE},
50-
&ComparePrototypesFromSourceAndPreprocSource{},
47+
&CollectCTagsFromSketchFiles{},
5148
&CTagsToPrototypes{},
5249
&PrototypesAdder{},
5350
&SketchSaver{},

src/arduino.cc/builder/test/builder_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ func TestBuilderEmptySketch(t *testing.T) {
6262

6363
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "HardwareSerial.cpp.o"))
6464
NoError(t, err)
65-
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET))
66-
NoError(t, err)
6765
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E))
6866
NoError(t, err)
6967
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_SKETCH, "sketch.ino.cpp.o"))
@@ -97,8 +95,6 @@ func TestBuilderBridge(t *testing.T) {
9795

9896
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "HardwareSerial.cpp.o"))
9997
NoError(t, err)
100-
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET))
101-
NoError(t, err)
10298
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E))
10399
NoError(t, err)
104100
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_SKETCH, "Bridge.ino.cpp.o"))
@@ -133,8 +129,6 @@ func TestBuilderSketchWithConfig(t *testing.T) {
133129

134130
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "HardwareSerial.cpp.o"))
135131
NoError(t, err)
136-
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET))
137-
NoError(t, err)
138132
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E))
139133
NoError(t, err)
140134
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_SKETCH, "sketch_with_config.ino.cpp.o"))
@@ -173,8 +167,6 @@ func TestBuilderBridgeTwice(t *testing.T) {
173167

174168
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "HardwareSerial.cpp.o"))
175169
NoError(t, err)
176-
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET))
177-
NoError(t, err)
178170
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E))
179171
NoError(t, err)
180172
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_SKETCH, "Bridge.ino.cpp.o"))
@@ -214,8 +206,6 @@ func TestBuilderBridgeSAM(t *testing.T) {
214206
NoError(t, err)
215207
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "avr", "dtostrf.c.d"))
216208
NoError(t, err)
217-
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET))
218-
NoError(t, err)
219209
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E))
220210
NoError(t, err)
221211
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_SKETCH, "Bridge.ino.cpp.o"))
@@ -250,8 +240,6 @@ func TestBuilderBridgeRedBearLab(t *testing.T) {
250240

251241
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "HardwareSerial.cpp.o"))
252242
NoError(t, err)
253-
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET))
254-
NoError(t, err)
255243
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E))
256244
NoError(t, err)
257245
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_SKETCH, "Bridge.ino.cpp.o"))

0 commit comments

Comments
 (0)