Skip to content

legacy removing: small advances (1st chunk of #481) #627

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

Merged
merged 4 commits into from
Apr 8, 2020
Merged
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c h1:agh2JT9
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c/go.mod h1:HK7SpkEax/3P+0w78iRQx1sz1vCDYYw9RXwHjQTB5i8=
github.com/arduino/go-paths-helper v1.0.1 h1:utYXLM2RfFlc9qp/MJTIYp3t6ux/xM6mWjeEb/WLK4Q=
github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck=
github.com/arduino/go-properties-orderedmap v0.0.0-20190828172252-05018b28ff6c h1:4z4PJqNH8WGXtm9ix2muUOAP7gxTGBOdQTuKEDyCnsA=
github.com/arduino/go-properties-orderedmap v0.0.0-20190828172252-05018b28ff6c/go.mod h1:kiSuHm7yz3chiy8rb2MphC7ECn3MlkQFAIe4SXmQg6o=
github.com/arduino/go-properties-orderedmap v1.0.0 h1:caaM25TQZKkytoKQUsgqtOVbrM5i8Gb427JmW0KL05s=
github.com/arduino/go-properties-orderedmap v1.0.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b h1:9hDi4F2st6dbLC3y4i02zFT5quS4X6iioWifGlVwfy4=
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b/go.mod h1:uwGy5PpN4lqW97FiLnbcx+xx8jly5YuPMJWfVwwjJiQ=
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b h1:3PjgYG5gVPA7cipp7vIR2lF96KkEJIFBJ+ANnuv6J20=
Expand Down
4 changes: 0 additions & 4 deletions legacy/builder/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
12 changes: 6 additions & 6 deletions legacy/builder/container_find_includes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 */)
}
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions legacy/builder/create_cmake_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 2 additions & 4 deletions legacy/builder/includes_finder_with_regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions legacy/builder/phases/core_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions legacy/builder/phases/sketch_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions legacy/builder/setup_build_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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") {
Expand Down
28 changes: 8 additions & 20 deletions legacy/builder/test/includes_finder_with_regexp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
16 changes: 0 additions & 16 deletions legacy/builder/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"unicode"
"unicode/utf8"
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down