Skip to content

Commit 708459e

Browse files
author
vinay-lanka
committed
update compile --build-path to support both relative and absolute flags
update compile --build-path for both relative and absolute flags - Shifted fix from cli/compile/compile.go to command/compile/compile.go - Added tests for checking compile --build-path
1 parent b8f82ce commit 708459e

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

Diff for: cli/compile/compile.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package compile
1818
import (
1919
"context"
2020
"os"
21-
"fmt"
2221

2322
"github.com/arduino/arduino-cli/cli/feedback"
2423

@@ -102,11 +101,7 @@ func run(cmd *cobra.Command, args []string) {
102101
}
103102

104103
sketchPath := initSketchPath(path)
105-
fmt.Println("FLAG LMAO")
106-
fmt.Println(buildPath)
107-
if string(buildPath) != "/" {
108-
buildPath = args[0]
109-
}
104+
110105
_, err = compile.Compile(context.Background(), &rpc.CompileReq{
111106
Instance: inst,
112107
Fqbn: fqbn,

Diff for: commands/compile/compile.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,12 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
123123
builderCtx.OtherLibrariesDirs.Add(configuration.LibrariesDir())
124124

125125
if req.GetBuildPath() != "" {
126-
builderCtx.BuildPath = paths.New(req.GetBuildPath())
126+
if req.GetBuildPath() != "/" {
127+
builderCtx.BuildPath = paths.New(req.GetSketchPath() + strings.TrimPrefix(req.GetBuildPath(), "."))
128+
} else {
129+
builderCtx.BuildPath = paths.New(req.GetBuildPath())
130+
}
131+
127132
err = builderCtx.BuildPath.MkdirAll()
128133
if err != nil {
129134
return nil, fmt.Errorf("cannot create build directory: %s", err)

Diff for: test/test_compile.py

+36
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,42 @@ def test_compile_with_simple_sketch(run_command, data_dir, working_dir):
8484
assert result.ok
8585
assert os.path.exists(target)
8686

87+
def test_build_path_flag(run_command, data_dir, working_dir):
88+
# Init the environment explicitly
89+
result = run_command("core update-index")
90+
assert result.ok
91+
92+
# Download latest AVR
93+
result = run_command("core install arduino:avr")
94+
assert result.ok
95+
96+
# Create a test sketch
97+
sketch_path = os.path.join(data_dir, "test_output_flag_default_path")
98+
fqbn = "arduino:avr:uno"
99+
result = run_command("sketch new {}".format(sketch_path))
100+
assert result.ok
101+
102+
build_file_path = os.path.join(data_dir, "test_output_flag_default_path","build","test_output_flag_default_path.ino.hex")
103+
104+
# Test the --build-path flag for a relative build path
105+
result = run_command(
106+
"compile -b {fqbn} {sketch_path} --build-path ./build".format(
107+
fqbn=fqbn, sketch_path=sketch_path
108+
)
109+
)
110+
assert result.ok
111+
assert os.path.exists(build_file_path)
112+
113+
abs_build_path = os.path.join(sketch_path, "/build")
114+
115+
# Test the --build-path flag for a absolute build path
116+
result = run_command(
117+
"compile -b {fqbn} {sketch_path} --build-path {abs_build_path}".format(
118+
fqbn=fqbn, sketch_path=sketch_path, abs_build_path=abs_build_path
119+
)
120+
)
121+
assert result.ok
122+
assert os.path.exists(build_file_path)
87123

88124
@pytest.mark.skipif(
89125
running_on_ci() and platform.system() == "Windows",

0 commit comments

Comments
 (0)