Skip to content

update compile --build-path to support both relative and absolute flags #632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
builderCtx.OtherLibrariesDirs.Add(configuration.LibrariesDir())

if req.GetBuildPath() != "" {
builderCtx.BuildPath = paths.New(req.GetBuildPath())
if req.GetBuildPath() != "/" {
builderCtx.BuildPath = paths.New(req.GetSketchPath() + strings.TrimPrefix(req.GetBuildPath(), "."))
} else {
builderCtx.BuildPath = paths.New(req.GetBuildPath())
}

err = builderCtx.BuildPath.MkdirAll()
if err != nil {
return nil, fmt.Errorf("cannot create build directory: %s", err)
Expand Down
36 changes: 36 additions & 0 deletions test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,42 @@ def test_compile_with_simple_sketch(run_command, data_dir, working_dir):
assert result.ok
assert os.path.exists(target)

def test_build_path_flag(run_command, data_dir, working_dir):
# Init the environment explicitly
result = run_command("core update-index")
assert result.ok

# Download latest AVR
result = run_command("core install arduino:avr")
assert result.ok

# Create a test sketch
sketch_path = os.path.join(data_dir, "test_output_flag_default_path")
fqbn = "arduino:avr:uno"
result = run_command("sketch new {}".format(sketch_path))
assert result.ok

build_file_path = os.path.join(data_dir, "test_output_flag_default_path","build","test_output_flag_default_path.ino.hex")

# Test the --build-path flag for a relative build path
result = run_command(
"compile -b {fqbn} {sketch_path} --build-path ./build".format(
fqbn=fqbn, sketch_path=sketch_path
)
)
assert result.ok
assert os.path.exists(build_file_path)

abs_build_path = os.path.join(sketch_path, "/build")

# Test the --build-path flag for a absolute build path
result = run_command(
"compile -b {fqbn} {sketch_path} --build-path {abs_build_path}".format(
fqbn=fqbn, sketch_path=sketch_path, abs_build_path=abs_build_path
)
)
assert result.ok
assert os.path.exists(build_file_path)

@pytest.mark.skipif(
running_on_ci() and platform.system() == "Windows",
Expand Down