Skip to content

Commit d950328

Browse files
author
Federico Fissore
committed
CreateBuildPathIfMissing now split into "Generate" and "Ensure exists".
This way we can emit build.path build property when using -dump-prefs Signed-off-by: Federico Fissore <[email protected]>
1 parent 00cc848 commit d950328

File tree

4 files changed

+92
-16
lines changed

4 files changed

+92
-16
lines changed

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ func (s *Builder) Run(context map[string]interface{}) error {
6868
commands := []types.Command{
6969
&SetupHumanLoggerIfMissing{},
7070

71-
&CreateBuildPathIfMissing{},
71+
&GenerateBuildPathIfMissing{},
72+
&EnsureBuildPathExists{},
7273

7374
&ContainerSetupHardwareToolsLibsSketchAndProps{},
7475

@@ -115,7 +116,12 @@ type ParseHardwareAndDumpBuildProperties struct{}
115116

116117
func (s *ParseHardwareAndDumpBuildProperties) Run(context map[string]interface{}) error {
117118
commands := []types.Command{
119+
&SetupHumanLoggerIfMissing{},
120+
121+
&GenerateBuildPathIfMissing{},
122+
118123
&ContainerSetupHardwareToolsLibsSketchAndProps{},
124+
119125
&DumpBuildProperties{},
120126
}
121127

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

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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/utils"
35+
"os"
36+
)
37+
38+
type EnsureBuildPathExists struct{}
39+
40+
func (s *EnsureBuildPathExists) Run(context map[string]interface{}) error {
41+
buildPath := context[constants.CTX_BUILD_PATH].(string)
42+
43+
err := os.MkdirAll(buildPath, os.FileMode(0755))
44+
if err != nil {
45+
return utils.WrapError(err)
46+
}
47+
48+
return nil
49+
}

Diff for: src/arduino.cc/builder/create_buildpath_if_missing.go renamed to src/arduino.cc/builder/generate_buildpath_if_missing.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ import (
4040
"strings"
4141
)
4242

43-
type CreateBuildPathIfMissing struct{}
43+
type GenerateBuildPathIfMissing struct{}
4444

45-
func (s *CreateBuildPathIfMissing) Run(context map[string]interface{}) error {
45+
func (s *GenerateBuildPathIfMissing) Run(context map[string]interface{}) error {
4646
if utils.MapHas(context, constants.CTX_BUILD_PATH) && context[constants.CTX_BUILD_PATH].(string) != constants.EMPTY_STRING {
4747
return nil
4848
}
@@ -56,10 +56,6 @@ func (s *CreateBuildPathIfMissing) Run(context map[string]interface{}) error {
5656
if err != nil && !os.IsNotExist(err) {
5757
return utils.WrapError(err)
5858
}
59-
err = os.MkdirAll(buildPath, os.FileMode(0755))
60-
if err != nil {
61-
return utils.WrapError(err)
62-
}
6359

6460
if utils.DebugLevel(context) > 5 {
6561
logger := context[constants.CTX_LOGGER].(i18n.Logger)

Diff for: src/arduino.cc/builder/test/create_buildpath_if_missing_test.go renamed to src/arduino.cc/builder/test/generate_buildpath_if_missing_test.go

+34-9
Original file line numberDiff line numberDiff line change
@@ -32,47 +32,72 @@ package test
3232
import (
3333
"arduino.cc/builder"
3434
"arduino.cc/builder/constants"
35+
"arduino.cc/builder/types"
3536
"github.com/stretchr/testify/require"
3637
"os"
3738
"path/filepath"
3839
"testing"
3940
)
4041

41-
func TestCreateBuildPathIfMissing(t *testing.T) {
42+
func TestGenerateBuildPathIfMissing(t *testing.T) {
4243
context := make(map[string]interface{})
4344

4445
context[constants.CTX_SKETCH_LOCATION] = "test"
4546

46-
createBuildPathIfMissing := builder.CreateBuildPathIfMissing{}
47-
err := createBuildPathIfMissing.Run(context)
47+
command := builder.GenerateBuildPathIfMissing{}
48+
err := command.Run(context)
4849
NoError(t, err)
4950

5051
require.Equal(t, filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6"), context[constants.CTX_BUILD_PATH])
51-
os.RemoveAll(context[constants.CTX_BUILD_PATH].(string))
52+
_, err = os.Stat(filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6"))
53+
require.True(t, os.IsNotExist(err))
5254
}
5355

54-
func TestCreateBuildPathIfEmpty(t *testing.T) {
56+
func TestGenerateBuildPathIfEmpty(t *testing.T) {
5557
context := make(map[string]interface{})
5658

5759
context[constants.CTX_SKETCH_LOCATION] = "test"
5860
context[constants.CTX_BUILD_PATH] = constants.EMPTY_STRING
5961

60-
createBuildPathIfMissing := builder.CreateBuildPathIfMissing{}
62+
createBuildPathIfMissing := builder.GenerateBuildPathIfMissing{}
6163
err := createBuildPathIfMissing.Run(context)
6264
NoError(t, err)
6365

6466
require.Equal(t, filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6"), context[constants.CTX_BUILD_PATH])
65-
os.RemoveAll(context[constants.CTX_BUILD_PATH].(string))
67+
_, err = os.Stat(filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6"))
68+
require.True(t, os.IsNotExist(err))
6669
}
6770

68-
func TestDontCreateBuildPathIfPresent(t *testing.T) {
71+
func TestDontGenerateBuildPathIfPresent(t *testing.T) {
6972
context := make(map[string]interface{})
7073

7174
context[constants.CTX_BUILD_PATH] = "test"
7275

73-
createBuildPathIfMissing := builder.CreateBuildPathIfMissing{}
76+
createBuildPathIfMissing := builder.GenerateBuildPathIfMissing{}
7477
err := createBuildPathIfMissing.Run(context)
7578
NoError(t, err)
7679

7780
require.Equal(t, "test", context[constants.CTX_BUILD_PATH])
7881
}
82+
83+
func TestGenerateBuildPathAndEnsureItExists(t *testing.T) {
84+
context := make(map[string]interface{})
85+
86+
context[constants.CTX_SKETCH_LOCATION] = "test"
87+
88+
commands := []types.Command{
89+
&builder.GenerateBuildPathIfMissing{},
90+
&builder.EnsureBuildPathExists{},
91+
}
92+
93+
for _, command := range commands {
94+
err := command.Run(context)
95+
NoError(t, err)
96+
}
97+
98+
defer os.RemoveAll(filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6"))
99+
100+
require.Equal(t, filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6"), context[constants.CTX_BUILD_PATH])
101+
_, err := os.Stat(filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6"))
102+
NoError(t, err)
103+
}

0 commit comments

Comments
 (0)