Unverified Commit 5b805dda authored by Cristian Maglie's avatar Cristian Maglie Committed by GitHub

[skip-changelog] legacy removing: small advances (1st chunk of #481) (#627)

* Removed legacy utils.PrettyOSName function

* Removed some constants

Possibly a container structure for build properties may be defined later
with helper methods (like GetBuildCorePath() ... etc.) to help in
retrieving these properties.

* Removed unused Context parameter

* upgrade github.com/arduino/go-properties-orderedmap to v1.0.0
parent c7742fab
......@@ -6,7 +6,7 @@ require (
bou.ke/monkey v1.0.1
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c
github.com/arduino/go-paths-helper v1.0.1
github.com/arduino/go-properties-orderedmap v0.0.0-20190828172252-05018b28ff6c
github.com/arduino/go-properties-orderedmap v1.0.0
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b
github.com/cmaglie/pb v1.0.27
......
......@@ -23,9 +23,7 @@ const BUILD_PROPERTIES_ARCH_OVERRIDE_CHECK = "architecture.override_check"
const BUILD_PROPERTIES_BOOTLOADER_FILE = "bootloader.file"
const BUILD_PROPERTIES_BOOTLOADER_NOBLINK = "bootloader.noblink"
const BUILD_PROPERTIES_BUILD_BOARD = "build.board"
const BUILD_PROPERTIES_BUILD_CORE_PATH = "build.core.path"
const BUILD_PROPERTIES_BUILD_MCU = "build.mcu"
const BUILD_PROPERTIES_BUILD_VARIANT_PATH = "build.variant.path"
const BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS = "compiler.c.elf.flags"
const BUILD_PROPERTIES_COMPILER_LDFLAGS = "compiler.ldflags"
const BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS = "compiler.libraries.ldflags"
......@@ -46,7 +44,6 @@ const CTAGS = "ctags"
const EMPTY_STRING = ""
const FILE_CTAGS_TARGET_FOR_GCC_MINUS_E = "ctags_target_for_gcc_minus_e.cpp"
const FILE_PLATFORM_KEYS_REWRITE_TXT = "platform.keys.rewrite.txt"
const FILE_INCLUDES_CACHE = "includes.cache"
const FOLDER_BOOTLOADERS = "bootloaders"
const FOLDER_CORE = "core"
const FOLDER_PREPROC = "preproc"
......@@ -156,7 +153,6 @@ const RECIPE_SIZE_REGEXP_EEPROM = "recipe.size.regex.eeprom"
const REWRITING_DISABLED = "disabled"
const REWRITING = "rewriting"
const SPACE = " "
const SKETCH_FOLDER_SRC = "src"
const TOOL_NAME = "name"
const TOOL_URL = "url"
const TOOL_VERSION = "version"
......@@ -111,12 +111,12 @@ import (
type ContainerFindIncludes struct{}
func (s *ContainerFindIncludes) Run(ctx *types.Context) error {
cachePath := ctx.BuildPath.Join(constants.FILE_INCLUDES_CACHE)
cachePath := ctx.BuildPath.Join("includes.cache")
cache := readCache(cachePath)
appendIncludeFolder(ctx, cache, nil, "", ctx.BuildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_CORE_PATH))
if ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH) != "" {
appendIncludeFolder(ctx, cache, nil, "", ctx.BuildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH))
appendIncludeFolder(ctx, cache, nil, "", ctx.BuildProperties.GetPath("build.core.path"))
if ctx.BuildProperties.Get("build.variant.path") != "" {
appendIncludeFolder(ctx, cache, nil, "", ctx.BuildProperties.GetPath("build.variant.path"))
}
sketch := ctx.Sketch
......@@ -128,7 +128,7 @@ func (s *ContainerFindIncludes) Run(ctx *types.Context) error {
sourceFilePaths := ctx.CollectedSourceFiles
queueSourceFilesFromFolder(ctx, sourceFilePaths, sketch, ctx.SketchBuildPath, false /* recurse */)
srcSubfolderPath := ctx.SketchBuildPath.Join(constants.SKETCH_FOLDER_SRC)
srcSubfolderPath := ctx.SketchBuildPath.Join("src")
if srcSubfolderPath.IsDir() {
queueSourceFilesFromFolder(ctx, sourceFilePaths, sketch, srcSubfolderPath, true /* recurse */)
}
......@@ -336,7 +336,7 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t
// other errors
return errors.WithStack(preproc_err)
} else {
include = IncludesFinderWithRegExp(ctx, string(preproc_stderr))
include = IncludesFinderWithRegExp(string(preproc_stderr))
if include == "" && ctx.Verbose {
ctx.GetLogger().Println(constants.LOG_LEVEL_DEBUG, constants.MSG_FIND_INCLUDES_FAILED, sourcePath)
}
......
......@@ -104,11 +104,11 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
}
// Copy core + variant in use + preprocessed sketch in the correct folders
err := utils.CopyDir(ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_CORE_PATH), coreFolder.String(), extensions)
err := utils.CopyDir(ctx.BuildProperties.Get("build.core.path"), coreFolder.String(), extensions)
if err != nil {
fmt.Println(err)
}
err = utils.CopyDir(ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH), coreFolder.Join("variant").String(), extensions)
err = utils.CopyDir(ctx.BuildProperties.Get("build.variant.path"), coreFolder.Join("variant").String(), extensions)
if err != nil {
fmt.Println(err)
}
......
......@@ -16,20 +16,18 @@
package builder
import (
"github.com/arduino/arduino-cli/legacy/builder/types"
"regexp"
"strings"
)
var INCLUDE_REGEXP = regexp.MustCompile("(?ms)^\\s*#[ \t]*include\\s*[<\"](\\S+)[\">]")
func IncludesFinderWithRegExp(ctx *types.Context, source string) string {
func IncludesFinderWithRegExp(source string) string {
match := INCLUDE_REGEXP.FindStringSubmatch(source)
if match != nil {
return strings.TrimSpace(match[1])
} else {
return findIncludeForOldCompilers(source)
}
return findIncludeForOldCompilers(source)
}
func findIncludeForOldCompilers(source string) string {
......
......@@ -64,8 +64,8 @@ func (s *CoreBuilder) Run(ctx *types.Context) error {
func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *paths.Path, buildProperties *properties.Map) (*paths.Path, paths.PathList, error) {
logger := ctx.GetLogger()
coreFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_CORE_PATH)
variantFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH)
coreFolder := buildProperties.GetPath("build.core.path")
variantFolder := buildProperties.GetPath("build.variant.path")
targetCoreFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH)
......
......@@ -17,7 +17,6 @@ package phases
import (
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
"github.com/arduino/arduino-cli/legacy/builder/constants"
"github.com/arduino/arduino-cli/legacy/builder/types"
"github.com/arduino/arduino-cli/legacy/builder/utils"
"github.com/pkg/errors"
......@@ -40,7 +39,7 @@ func (s *SketchBuilder) Run(ctx *types.Context) error {
}
// The "src/" subdirectory of a sketch is compiled recursively
sketchSrcPath := sketchBuildPath.Join(constants.SKETCH_FOLDER_SRC)
sketchSrcPath := sketchBuildPath.Join("src")
if sketchSrcPath.IsDir() {
srcObjectFiles, err := builder_utils.CompileFiles(ctx, sketchSrcPath, true, sketchSrcPath, buildProperties, includes)
if err != nil {
......
......@@ -24,7 +24,6 @@ import (
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/legacy/builder/types"
"github.com/arduino/arduino-cli/legacy/builder/utils"
properties "github.com/arduino/go-properties-orderedmap"
timeutils "github.com/arduino/go-timeutils"
)
......@@ -67,7 +66,7 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error {
buildProperties.Set("runtime.ide.path", exPath)
buildProperties.Set("build.fqbn", ctx.FQBN.String())
buildProperties.Set("ide_version", ctx.ArduinoAPIVersion)
buildProperties.Set("runtime.os", utils.PrettyOSName())
buildProperties.Set("runtime.os", properties.GetOSSuffix())
if ctx.OptimizeForDebug {
if buildProperties.ContainsKey("compiler.optimization_flags.debug") {
......
......@@ -16,74 +16,62 @@
package test
import (
"testing"
"github.com/arduino/arduino-cli/legacy/builder"
"github.com/arduino/arduino-cli/legacy/builder/types"
"github.com/stretchr/testify/require"
"testing"
)
func TestIncludesFinderWithRegExp(t *testing.T) {
ctx := &types.Context{}
output := "/some/path/sketch.ino:1:17: fatal error: SPI.h: No such file or directory\n" +
"#include <SPI.h>\n" +
"^\n" +
"compilation terminated."
include := builder.IncludesFinderWithRegExp(ctx, output)
include := builder.IncludesFinderWithRegExp(output)
require.Equal(t, "SPI.h", include)
}
func TestIncludesFinderWithRegExpEmptyOutput(t *testing.T) {
ctx := &types.Context{}
include := builder.IncludesFinderWithRegExp(ctx, "")
include := builder.IncludesFinderWithRegExp("")
require.Equal(t, "", include)
}
func TestIncludesFinderWithRegExpPaddedIncludes(t *testing.T) {
ctx := &types.Context{}
output := "/some/path/sketch.ino:1:33: fatal error: Wire.h: No such file or directory\n" +
" # include <Wire.h>\n" +
" ^\n" +
"compilation terminated.\n"
include := builder.IncludesFinderWithRegExp(ctx, output)
include := builder.IncludesFinderWithRegExp(output)
require.Equal(t, "Wire.h", include)
}
func TestIncludesFinderWithRegExpPaddedIncludes2(t *testing.T) {
ctx := &types.Context{}
output := "/some/path/sketch.ino:1:33: fatal error: Wire.h: No such file or directory\n" +
" #\t\t\tinclude <Wire.h>\n" +
" ^\n" +
"compilation terminated.\n"
include := builder.IncludesFinderWithRegExp(ctx, output)
include := builder.IncludesFinderWithRegExp(output)
require.Equal(t, "Wire.h", include)
}
func TestIncludesFinderWithRegExpPaddedIncludes3(t *testing.T) {
ctx := &types.Context{}
output := "/some/path/sketch.ino:1:33: fatal error: SPI.h: No such file or directory\n" +
"compilation terminated.\n"
include := builder.IncludesFinderWithRegExp(ctx, output)
include := builder.IncludesFinderWithRegExp(output)
require.Equal(t, "SPI.h", include)
}
func TestIncludesFinderWithRegExpPaddedIncludes4(t *testing.T) {
ctx := &types.Context{}
output := "In file included from /tmp/arduino_modified_sketch_815412/binouts.ino:52:0:\n" +
"/tmp/arduino_build_static/sketch/regtable.h:31:22: fatal error: register.h: No such file or directory\n"
include := builder.IncludesFinderWithRegExp(ctx, output)
include := builder.IncludesFinderWithRegExp(output)
require.Equal(t, "register.h", include)
}
......@@ -25,7 +25,6 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"unicode"
"unicode/utf8"
......@@ -40,21 +39,6 @@ import (
"golang.org/x/text/unicode/norm"
)
func PrettyOSName() string {
switch osName := runtime.GOOS; osName {
case "darwin":
return "macosx"
case "freebsd":
return "freebsd"
case "linux":
return "linux"
case "windows":
return "windows"
default:
return "other"
}
}
func ParseCommandLine(input string, logger i18n.Logger) ([]string, error) {
var parts []string
escapingChar := constants.EMPTY_STRING
......
......@@ -54,7 +54,7 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error {
// if so, trigger a "safety" wipe
buildProperties := ctx.BuildProperties
targetCoreFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH)
coreFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_CORE_PATH)
coreFolder := buildProperties.GetPath("build.core.path")
realCoreFolder := coreFolder.Parent().Parent()
jsonPath := ctx.BuildPath.Join(constants.BUILD_OPTIONS_FILE)
coreHasChanged := builder_utils.TXTBuildRulesHaveChanged(realCoreFolder, targetCoreFolder, jsonPath)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment