Skip to content

Commit 5d56cb9

Browse files
author
vinay-lanka
committed
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 909ffa2 commit 5d56cb9

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

Diff for: cli/compile/compile.go

-3
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ func run(cmd *cobra.Command, args []string) {
102102

103103
sketchPath := initSketchPath(path)
104104

105-
if string(buildPath) != "/" {
106-
buildPath = args[0]
107-
}
108105
_, err = compile.Compile(context.Background(), &rpc.CompileReq{
109106
Instance: inst,
110107
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)