Skip to content

Commit d72f9be

Browse files
author
Federico Fissore
committed
Adding platform includes to the first gcc calls, allowing to compile a sketch
that includes Arduino.h Fixes #33 Signed-off-by: Federico Fissore <[email protected]>
1 parent 51d32d7 commit d72f9be

File tree

6 files changed

+139
-10
lines changed

6 files changed

+139
-10
lines changed

Diff for: src/arduino.cc/builder/container_find_includes.go

+17-6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ import (
3939
type ContainerFindIncludes struct{}
4040

4141
func (s *ContainerFindIncludes) Run(context map[string]interface{}) error {
42+
err := runCommand(context, &IncludesToIncludeFolders{})
43+
if err != nil {
44+
return utils.WrapError(err)
45+
}
46+
4247
sketch := context[constants.CTX_SKETCH].(*types.Sketch)
4348
sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string)
4449
wheelSpins := context[constants.CTX_LIBRARY_DISCOVERY_RECURSION_DEPTH].(int)
@@ -50,8 +55,7 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}) error {
5055
}
5156

5257
for _, command := range commands {
53-
PrintRingNameIfDebug(context, command)
54-
err := command.Run(context)
58+
err := runCommand(context, command)
5559
if err != nil {
5660
return utils.WrapError(err)
5761
}
@@ -66,8 +70,7 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}) error {
6670
}
6771
}
6872

69-
command := &CollectAllSourceFilesFromFoldersWithSources{}
70-
err := command.Run(context)
73+
err = runCommand(context, &CollectAllSourceFilesFromFoldersWithSources{})
7174
if err != nil {
7275
return utils.WrapError(err)
7376
}
@@ -83,8 +86,7 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}) error {
8386
}
8487

8588
for _, command := range commands {
86-
PrintRingNameIfDebug(context, command)
87-
err := command.Run(context)
89+
err := runCommand(context, command)
8890
if err != nil {
8991
return utils.WrapError(err)
9092
}
@@ -93,3 +95,12 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}) error {
9395

9496
return nil
9597
}
98+
99+
func runCommand(context map[string]interface{}, command types.Command) error {
100+
PrintRingNameIfDebug(context, command)
101+
err := command.Run(context)
102+
if err != nil {
103+
return utils.WrapError(err)
104+
}
105+
return nil
106+
}

Diff for: src/arduino.cc/builder/dump_context.go

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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/utils"
34+
"fmt"
35+
"sort"
36+
)
37+
38+
type DumpContext struct{}
39+
40+
func (s *DumpContext) Run(context map[string]interface{}) error {
41+
keys := utils.KeysOfMapOfStringInterface(context)
42+
sort.Strings(keys)
43+
44+
for _, key := range keys {
45+
fmt.Print(key + "=")
46+
fmt.Println(context[key])
47+
}
48+
49+
return nil
50+
}

Diff for: src/arduino.cc/builder/includes_to_include_folders.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ import (
4040
type IncludesToIncludeFolders struct{}
4141

4242
func (s *IncludesToIncludeFolders) Run(context map[string]interface{}) error {
43-
if !utils.MapHas(context, constants.CTX_LIBRARIES) {
44-
return nil
43+
includes := []string{}
44+
if utils.MapHas(context, constants.CTX_INCLUDES) {
45+
includes = context[constants.CTX_INCLUDES].([]string)
4546
}
46-
includes := context[constants.CTX_INCLUDES].([]string)
47-
headerToLibraries := context[constants.CTX_HEADER_TO_LIBRARIES].(map[string][]*types.Library)
47+
headerToLibraries := make(map[string][]*types.Library)
48+
if utils.MapHas(context, constants.CTX_HEADER_TO_LIBRARIES) {
49+
headerToLibraries = context[constants.CTX_HEADER_TO_LIBRARIES].(map[string][]*types.Library)
50+
}
51+
4852
platform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform)
4953
actualPlatform := context[constants.CTX_ACTUAL_PLATFORM].(*types.Platform)
5054
libraryResolutionResults := context[constants.CTX_LIBRARY_RESOLUTION_RESULTS].(map[string]types.LibraryResolutionResult)

Diff for: src/arduino.cc/builder/test/prototypes_adder_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -603,3 +603,43 @@ func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) {
603603
require.Equal(t, "#include <Arduino.h>\n#line 1\n", context[constants.CTX_INCLUDE_SECTION].(string))
604604
require.Equal(t, "void setup();\nvoid loop();\nint8_t adalight();\n#line 1\n", context[constants.CTX_PROTOTYPE_SECTION].(string))
605605
}
606+
607+
func TestPrototypesAdderSketchWithUSBCON(t *testing.T) {
608+
DownloadCoresAndToolsAndLibraries(t)
609+
610+
context := make(map[string]interface{})
611+
612+
buildPath := SetupBuildPath(t, context)
613+
defer os.RemoveAll(buildPath)
614+
615+
context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}
616+
context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"}
617+
context[constants.CTX_FQBN] = "arduino:avr:leonardo"
618+
context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_with_usbcon", "sketch.ino")
619+
context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600"
620+
context[constants.CTX_LIBRARIES_FOLDERS] = []string{"libraries", "downloaded_libraries"}
621+
context[constants.CTX_VERBOSE] = true
622+
623+
commands := []types.Command{
624+
&builder.SetupHumanLoggerIfMissing{},
625+
626+
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
627+
628+
&builder.ContainerMergeCopySketchFiles{},
629+
630+
&builder.ContainerFindIncludes{},
631+
632+
&builder.PrintUsedLibrariesIfVerbose{},
633+
&builder.WarnAboutArchIncompatibleLibraries{},
634+
635+
&builder.ContainerAddPrototypes{},
636+
}
637+
638+
for _, command := range commands {
639+
err := command.Run(context)
640+
NoError(t, err)
641+
}
642+
643+
require.Equal(t, "#include <Arduino.h>\n#line 1\n", context[constants.CTX_INCLUDE_SECTION].(string))
644+
require.Equal(t, "void ciao();\nvoid setup();\nvoid loop();\n#line 3\n", context[constants.CTX_PROTOTYPE_SECTION].(string))
645+
}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <Arduino.h>
2+
#if defined(USBCON)
3+
void ciao() {
4+
5+
}
6+
#endif
7+
8+
void setup() {
9+
// put your setup code here, to run once:
10+
11+
}
12+
13+
void loop() {
14+
// put your main code here, to run repeatedly:
15+
16+
}

Diff for: src/arduino.cc/builder/utils/utils.go

+8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ import (
4444
"strings"
4545
)
4646

47+
func KeysOfMapOfStringInterface(input map[string]interface{}) []string {
48+
var keys []string
49+
for key, _ := range input {
50+
keys = append(keys, key)
51+
}
52+
return keys
53+
}
54+
4755
func KeysOfMapOfString(input map[string]string) []string {
4856
var keys []string
4957
for key, _ := range input {

0 commit comments

Comments
 (0)