Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita0dfb78

Browse files
author
Federico Fissore
committed
Added --preprocess action: preprocess (doesn't compile) given sketch. Better
call arduino-compiler with the new -quite flag, otherwise output will getclutteredSigned-off-by: Federico Fissore <f.fissore@arduino.cc>
1 parentd17b4a8 commita0dfb78

File tree

4 files changed

+118
-28
lines changed

4 files changed

+118
-28
lines changed

‎main.go‎

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ import (
4949

5050
constVERSION="1.0.7"
5151

52-
constFLAG_COMPILE="compile"
53-
constFLAG_DUMP_PREFS="dump-prefs"
52+
constFLAG_ACTION_COMPILE="compile"
53+
constFLAG_ACTION_PREPROCESS="preprocess"
54+
constFLAG_ACTION_DUMP_PREFS="dump-prefs"
5455
constFLAG_BUILD_OPTIONS_FILE="build-options-file"
5556
constFLAG_HARDWARE="hardware"
5657
constFLAG_TOOLS="tools"
@@ -61,6 +62,7 @@ const FLAG_FQBN = "fqbn"
6162
constFLAG_IDE_VERSION="ide-version"
6263
constFLAG_BUILD_PATH="build-path"
6364
constFLAG_VERBOSE="verbose"
65+
constFLAG_QUITE="quite"
6466
constFLAG_DEBUG_LEVEL="debug-level"
6567
constFLAG_WARNINGS="warnings"
6668
constFLAG_WARNINGS_NONE="none"
@@ -97,6 +99,7 @@ func (h *slice) Set(csv string) error {
9799
}
98100

99101
varcompileFlag*bool
102+
varpreprocessFlag*bool
100103
vardumpPrefsFlag*bool
101104
varbuildOptionsFileFlag*string
102105
varhardwareFoldersFlagslice
@@ -108,6 +111,7 @@ var fqbnFlag *string
108111
varideVersionFlag*string
109112
varbuildPathFlag*string
110113
varverboseFlag*bool
114+
varquiteFlag*bool
111115
vardebugLevelFlag*int
112116
varlibraryDiscoveryRecursionDepthFlag*int
113117
varwarningsLevelFlag*string
@@ -116,8 +120,9 @@ var versionFlag *bool
116120
varvidPidFlag*string
117121

118122
funcinit() {
119-
compileFlag=flag.Bool(FLAG_COMPILE,false,"compiles the given sketch")
120-
dumpPrefsFlag=flag.Bool(FLAG_DUMP_PREFS,false,"dumps build properties used when compiling")
123+
compileFlag=flag.Bool(FLAG_ACTION_COMPILE,false,"compiles the given sketch")
124+
preprocessFlag=flag.Bool(FLAG_ACTION_PREPROCESS,false,"preprocess the given sketch")
125+
dumpPrefsFlag=flag.Bool(FLAG_ACTION_DUMP_PREFS,false,"dumps build properties used when compiling")
121126
buildOptionsFileFlag=flag.String(FLAG_BUILD_OPTIONS_FILE,"","Instead of specifying --"+FLAG_HARDWARE+", --"+FLAG_TOOLS+" etc every time, you can load all such options from a file")
122127
flag.Var(&hardwareFoldersFlag,FLAG_HARDWARE,"Specify a 'hardware' folder. Can be added multiple times for specifying multiple 'hardware' folders")
123128
flag.Var(&toolsFoldersFlag,FLAG_TOOLS,"Specify a 'tools' folder. Can be added multiple times for specifying multiple 'tools' folders")
@@ -128,6 +133,7 @@ func init() {
128133
ideVersionFlag=flag.String(FLAG_IDE_VERSION,"10600","fake IDE version")
129134
buildPathFlag=flag.String(FLAG_BUILD_PATH,"","build path")
130135
verboseFlag=flag.Bool(FLAG_VERBOSE,false,"if 'true' prints lots of stuff")
136+
quiteFlag=flag.Bool(FLAG_QUITE,false,"if 'true' doesn't print any warnings or progress or whatever")
131137
debugLevelFlag=flag.Int(FLAG_DEBUG_LEVEL,builder.DEFAULT_DEBUG_LEVEL,"Turns on debugging messages. The higher, the chattier")
132138
warningsLevelFlag=flag.String(FLAG_WARNINGS,"","Sets warnings level. Available values are '"+FLAG_WARNINGS_NONE+"', '"+FLAG_WARNINGS_DEFAULT+"', '"+FLAG_WARNINGS_MORE+"' and '"+FLAG_WARNINGS_ALL+"'")
133139
loggerFlag=flag.String(FLAG_LOGGER,FLAG_LOGGER_HUMAN,"Sets type of logger. Available values are '"+FLAG_LOGGER_HUMAN+"', '"+FLAG_LOGGER_MACHINE+"'")
@@ -149,19 +155,6 @@ func main() {
149155
return
150156
}
151157

152-
compile:=*compileFlag
153-
dumpPrefs:=*dumpPrefsFlag
154-
155-
ifcompile&&dumpPrefs {
156-
fmt.Fprintln(os.Stderr,"You can either specify --"+FLAG_COMPILE+" or --"+FLAG_DUMP_PREFS+", not both")
157-
deferos.Exit(1)
158-
return
159-
}
160-
161-
if!compile&&!dumpPrefs {
162-
compile=true
163-
}
164-
165158
context:=make(map[string]interface{})
166159

167160
buildOptions:=make(map[string]string)
@@ -265,13 +258,6 @@ func main() {
265258
context[constants.CTX_VIDPID]=*vidPidFlag
266259
}
267260

268-
ifcompile&&flag.NArg()==0 {
269-
fmt.Fprintln(os.Stderr,"Last parameter must be the sketch to compile")
270-
flag.Usage()
271-
deferos.Exit(1)
272-
return
273-
}
274-
275261
ifflag.NArg()>0 {
276262
sketchLocation:=flag.Arg(0)
277263
sketchLocation,err:=gohasissues.Unquote(sketchLocation)
@@ -283,6 +269,11 @@ func main() {
283269
context[constants.CTX_SKETCH_LOCATION]=sketchLocation
284270
}
285271

272+
if*verboseFlag&&*quiteFlag {
273+
*verboseFlag=false
274+
*quiteFlag=false
275+
}
276+
286277
context[constants.CTX_VERBOSE]=*verboseFlag
287278

288279
ideVersion:=""
@@ -305,16 +296,26 @@ func main() {
305296
context[constants.CTX_LIBRARY_DISCOVERY_RECURSION_DEPTH]=*libraryDiscoveryRecursionDepthFlag
306297
}
307298

308-
if*loggerFlag==FLAG_LOGGER_MACHINE {
299+
if*quiteFlag {
300+
context[constants.CTX_LOGGER]= i18n.NoopLogger{}
301+
}elseif*loggerFlag==FLAG_LOGGER_MACHINE {
309302
context[constants.CTX_LOGGER]= i18n.MachineLogger{}
310303
}else {
311304
context[constants.CTX_LOGGER]= i18n.HumanLogger{}
312305
}
313306

314-
ifcompile {
315-
err=builder.RunBuilder(context)
316-
}elseifdumpPrefs {
307+
if*dumpPrefsFlag {
317308
err=builder.RunParseHardwareAndDumpBuildProperties(context)
309+
}elseif*preprocessFlag {
310+
err=builder.RunPreprocess(context)
311+
}else {
312+
ifflag.NArg()==0 {
313+
fmt.Fprintln(os.Stderr,"Last parameter must be the sketch to compile")
314+
flag.Usage()
315+
deferos.Exit(1)
316+
return
317+
}
318+
err=builder.RunBuilder(context)
318319
}
319320

320321
exitCode:=0

‎src/arduino.cc/builder/builder.go‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,35 @@ func (s *Builder) Run(context map[string]interface{}) error {
128128
returnotherErr
129129
}
130130

131+
typePreprocessstruct{}
132+
133+
func (s*Preprocess)Run(contextmap[string]interface{})error {
134+
commands:= []types.Command{
135+
&SetupHumanLoggerIfMissing{},
136+
137+
&GenerateBuildPathIfMissing{},
138+
&EnsureBuildPathExists{},
139+
140+
&ContainerSetupHardwareToolsLibsSketchAndProps{},
141+
142+
&ContainerBuildOptions{},
143+
144+
&RecipeByPrefixSuffixRunner{Prefix:constants.HOOKS_PREBUILD,Suffix:constants.HOOKS_PATTERN_SUFFIX},
145+
146+
&ContainerMergeCopySketchFiles{},
147+
148+
&ContainerFindIncludes{},
149+
150+
&WarnAboutArchIncompatibleLibraries{},
151+
152+
&ContainerAddPrototypes{},
153+
154+
&PrintPreprocessedSource{},
155+
}
156+
157+
returnrunCommands(context,commands,true)
158+
}
159+
131160
typeParseHardwareAndDumpBuildPropertiesstruct{}
132161

133162
func (s*ParseHardwareAndDumpBuildProperties)Run(contextmap[string]interface{})error {
@@ -190,3 +219,8 @@ func RunParseHardwareAndDumpBuildProperties(context map[string]interface{}) erro
190219
command:=ParseHardwareAndDumpBuildProperties{}
191220
returncommand.Run(context)
192221
}
222+
223+
funcRunPreprocess(contextmap[string]interface{})error {
224+
command:=Preprocess{}
225+
returncommand.Run(context)
226+
}

‎src/arduino.cc/builder/i18n/i18n.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ type Logger interface {
4848
Name()string
4949
}
5050

51+
typeNoopLoggerstruct{}
52+
53+
func (sNoopLogger)Fprintln(w io.Writer,formatstring,a...interface{}) {}
54+
55+
func (sNoopLogger)Println(formatstring,a...interface{}) {}
56+
57+
func (sNoopLogger)Name()string {
58+
return"noop"
59+
}
60+
5161
typeHumanLoggerstruct{}
5262

5363
func (sHumanLogger)Fprintln(w io.Writer,formatstring,a...interface{}) {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
"fmt"
35+
)
36+
37+
typePrintPreprocessedSourcestruct{}
38+
39+
func (s*PrintPreprocessedSource)Run(contextmap[string]interface{})error {
40+
source:=context[constants.CTX_GCC_MINUS_E_SOURCE].(string)
41+
42+
fmt.Println(source)
43+
44+
returnnil
45+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp