Skip to content

Commit

Permalink
move some legacy constans in builder package
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Sep 6, 2023
1 parent 19906a7 commit 29f8215
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
10 changes: 10 additions & 0 deletions arduino/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ package builder

import "github.com/arduino/arduino-cli/arduino/sketch"

const (
BuildPropertiesArchiveFile = "archive_file"
BuildPropertiesArchiveFilePath = "archive_file_path"
BuildPropertiesObjectFile = "object_file"
RecipeARPattern = "recipe.ar.pattern"
BuildPropertiesIncludes = "includes"
BuildPropertiesCompilerWarningFlags = "compiler.warning_flags"
Space = " "
)

// Builder is a Sketch builder.
type Builder struct {
sketch *sketch.Sketch
Expand Down
15 changes: 7 additions & 8 deletions legacy/builder/builder_utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/arduino/arduino-cli/arduino/globals"
"github.com/arduino/arduino-cli/executils"
"github.com/arduino/arduino-cli/i18n"
"github.com/arduino/arduino-cli/legacy/builder/constants"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/go-paths-helper"
"github.com/arduino/go-properties-orderedmap"
Expand Down Expand Up @@ -251,8 +250,8 @@ func compileFileWithRecipe(
verboseStdout, verboseInfo, errOut := &bytes.Buffer{}, &bytes.Buffer{}, &bytes.Buffer{}

properties := buildProperties.Clone()
properties.Set(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS, properties.Get(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+warningsLevel))
properties.Set(constants.BUILD_PROPERTIES_INCLUDES, strings.Join(includes, constants.SPACE))
properties.Set(builder.BuildPropertiesCompilerWarningFlags, properties.Get(builder.BuildPropertiesCompilerWarningFlags+"."+warningsLevel))
properties.Set(builder.BuildPropertiesIncludes, strings.Join(includes, builder.Space))
properties.SetPath("source_file", source)
relativeSource, err := sourcePath.RelTo(source)
if err != nil {
Expand All @@ -261,7 +260,7 @@ func compileFileWithRecipe(
depsFile := buildPath.Join(relativeSource.String() + ".d")
objectFile := buildPath.Join(relativeSource.String() + ".o")

properties.SetPath(constants.BUILD_PROPERTIES_OBJECT_FILE, objectFile)
properties.SetPath(builder.BuildPropertiesObjectFile, objectFile)
err = objectFile.Parent().MkdirAll()
if err != nil {
return nil, nil, nil, nil, errors.WithStack(err)
Expand Down Expand Up @@ -345,11 +344,11 @@ func ArchiveCompiledFiles(

for _, objectFile := range objectFilesToArchive {
properties := buildProperties.Clone()
properties.Set(constants.BUILD_PROPERTIES_ARCHIVE_FILE, archiveFilePath.Base())
properties.SetPath(constants.BUILD_PROPERTIES_ARCHIVE_FILE_PATH, archiveFilePath)
properties.SetPath(constants.BUILD_PROPERTIES_OBJECT_FILE, objectFile)
properties.Set(builder.BuildPropertiesArchiveFile, archiveFilePath.Base())
properties.SetPath(builder.BuildPropertiesArchiveFilePath, archiveFilePath)
properties.SetPath(builder.BuildPropertiesObjectFile, objectFile)

command, err := PrepareCommandForRecipe(properties, constants.RECIPE_AR_PATTERN, false)
command, err := PrepareCommandForRecipe(properties, builder.RecipeARPattern, false)
if err != nil {
return nil, verboseInfobuf.Bytes(), errors.WithStack(err)
}
Expand Down
7 changes: 0 additions & 7 deletions legacy/builder/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package constants

const BUILD_OPTIONS_FILE = "build.options.json"
const BUILD_PROPERTIES_ARCHIVE_FILE = "archive_file"
const BUILD_PROPERTIES_ARCHIVE_FILE_PATH = "archive_file_path"
const BUILD_PROPERTIES_ARCH_OVERRIDE_CHECK = "architecture.override_check"
const BUILD_PROPERTIES_BOOTLOADER_FILE = "bootloader.file"
const BUILD_PROPERTIES_BOOTLOADER_NOBLINK = "bootloader.noblink"
Expand All @@ -27,9 +25,6 @@ const BUILD_PROPERTIES_BUILD_MCU = "build.mcu"
const BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS = "compiler.c.elf.flags"
const BUILD_PROPERTIES_COMPILER_LDFLAGS = "compiler.ldflags"
const BUILD_PROPERTIES_COMPILER_CPP_FLAGS = "compiler.cpp.flags"
const BUILD_PROPERTIES_COMPILER_WARNING_FLAGS = "compiler.warning_flags"
const BUILD_PROPERTIES_INCLUDES = "includes"
const BUILD_PROPERTIES_OBJECT_FILE = "object_file"
const BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH = "runtime.platform.path"
const EMPTY_STRING = ""
const FOLDER_BOOTLOADERS = "bootloaders"
Expand All @@ -50,9 +45,7 @@ const PACKAGE_TOOLS = "tools"
const PLATFORM_ARCHITECTURE = "architecture"
const PLATFORM_URL = "url"
const PLATFORM_VERSION = "version"
const RECIPE_AR_PATTERN = "recipe.ar.pattern"
const RECIPE_C_COMBINE_PATTERN = "recipe.c.combine.pattern"
const SPACE = " "
const TOOL_NAME = "name"
const TOOL_URL = "url"
const TOOL_VERSION = "version"
9 changes: 5 additions & 4 deletions legacy/builder/phases/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package phases
import (
"strings"

"github.com/arduino/arduino-cli/arduino/builder"
"github.com/arduino/arduino-cli/arduino/builder/utils"
f "github.com/arduino/arduino-cli/internal/algorithms"
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
Expand Down Expand Up @@ -93,7 +94,7 @@ func link(ctx *types.Context, objectFiles paths.PathList, coreDotARelPath *paths
properties.SetPath("archive_file_path", archive)
properties.SetPath("object_file", object)

command, err := builder_utils.PrepareCommandForRecipe(properties, constants.RECIPE_AR_PATTERN, false)
command, err := builder_utils.PrepareCommandForRecipe(properties, builder.RecipeARPattern, false)
if err != nil {
return errors.WithStack(err)
}
Expand All @@ -112,9 +113,9 @@ func link(ctx *types.Context, objectFiles paths.PathList, coreDotARelPath *paths

properties := buildProperties.Clone()
properties.Set(constants.BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS, properties.Get(constants.BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS))
properties.Set(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS, properties.Get(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+ctx.WarningsLevel))
properties.Set(constants.BUILD_PROPERTIES_ARCHIVE_FILE, coreDotARelPath.String())
properties.Set(constants.BUILD_PROPERTIES_ARCHIVE_FILE_PATH, coreArchiveFilePath.String())
properties.Set(builder.BuildPropertiesCompilerWarningFlags, properties.Get(builder.BuildPropertiesCompilerWarningFlags+"."+ctx.WarningsLevel))
properties.Set(builder.BuildPropertiesArchiveFile, coreDotARelPath.String())
properties.Set(builder.BuildPropertiesArchiveFilePath, coreArchiveFilePath.String())
properties.Set("object_files", objectFileList)

command, err := builder_utils.PrepareCommandForRecipe(properties, constants.RECIPE_C_COMBINE_PATTERN, false)
Expand Down

0 comments on commit 29f8215

Please sign in to comment.