-
-
Notifications
You must be signed in to change notification settings - Fork 406
legacy: Builder refactorization (part 5...) #2312
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
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
1709a8f
move customBuildProperties to arduino/builder
alessio-perugini c19a712
remove BuildProperties from context
alessio-perugini c22f1c7
remove BuildPath from context
alessio-perugini 2c22616
remove sketch,libraries,core build path from Context
alessio-perugini 0afe884
remove buildPath parameter to PrepareSketchBuildPath func
alessio-perugini 7ff4427
Make CoreBuilder a method recevier of arduino/builder
alessio-perugini 2297f2b
Add BuilderLogger in arduino/builder
alessio-perugini d704e4c
Remove BuilderLogger from CoreBuild parameter
alessio-perugini f8cbfe5
Make getCachedCoreArchiveDirName unexported
alessio-perugini 5916daa
heavily refactored the ContainerBuildOptions
alessio-perugini 895c593
remove fqbn from Context
alessio-perugini b4891ea
remove clean from Context
alessio-perugini 870f624
remove unsued properties in Context
alessio-perugini a6e1ef2
remove sourceOverrides from Context
alessio-perugini 776ed23
make SketchBuilder a method recevier of arduino/builder
alessio-perugini 93a9cfa
make BuildLibraries a method recevier of arduino/builder
alessio-perugini e965599
make RunRecipe a method recevier of arduino/builder
alessio-perugini f1fdf17
make RemoveUnusedCompiledLibraries a method recevier of arduino/builder
alessio-perugini 41b47b7
make MergeSketchWithBootloader a method recevier of arduino/builder
alessio-perugini 4f99d33
make WarnAboutArchIncompatibleLibraries a method recevier of arduino/…
alessio-perugini 16f7fe0
make PrintUsedLibraries a method recevier of arduino/builder
alessio-perugini 97a15a4
make ExportCmake and PreprocessorSketch a method recevier of arduino/…
alessio-perugini f4f7298
remove legacy/constans pkg
alessio-perugini 5e9f9ca
make Linker a method recevier of arduino/builder
alessio-perugini 290e8b1
make Size a method recevier of arduino/builder
alessio-perugini 2279e9b
remove onlyUpdateCompilationDatabase from Context
alessio-perugini a0f8e30
remove Progress from Context
alessio-perugini aa904b6
remove ExecutableSectionSize from Context
alessio-perugini 34e6204
remove CompilationDatabase from Context
alessio-perugini d5c040f
remove LineOffset from Context
alessio-perugini 8995aff
introduce BuilderArtifacts to better isolate write operations
alessio-perugini e005586
remove ActualPlatform and TargetPlatform from Context
alessio-perugini a7963f4
directly pass the remaining properties of Context in the builder cons…
alessio-perugini 6004057
polish legacy test
alessio-perugini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
// This file is part of arduino-cli. | ||
// | ||
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) | ||
// | ||
// This software is released under the GNU General Public License version 3, | ||
// which covers the main part of arduino-cli. | ||
// The terms of this license can be found at: | ||
// https://www.gnu.org/licenses/gpl-3.0.en.html | ||
// | ||
// You can be released from the requirements of the above licenses by purchasing | ||
// a commercial license. Buying such a license is mandatory if you want to | ||
// modify or otherwise use the software for commercial activities involving the | ||
// Arduino software without disclosing the source code of your own applications. | ||
// To purchase a commercial license, send an email to [email protected]. | ||
|
||
package builder | ||
|
||
import ( | ||
"encoding/json" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/arduino/arduino-cli/arduino/builder/logger" | ||
"github.com/arduino/arduino-cli/arduino/builder/utils" | ||
"github.com/arduino/arduino-cli/arduino/cores" | ||
"github.com/arduino/arduino-cli/arduino/sketch" | ||
"github.com/arduino/go-paths-helper" | ||
properties "github.com/arduino/go-properties-orderedmap" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// BuildOptionsManager fixdoc | ||
type BuildOptionsManager struct { | ||
currentOptions *properties.Map | ||
currentBuildOptionsJSON []byte | ||
|
||
hardwareDirs paths.PathList | ||
builtInToolsDirs paths.PathList | ||
otherLibrariesDirs paths.PathList | ||
builtInLibrariesDirs *paths.Path | ||
buildPath *paths.Path | ||
runtimePlatformPath *paths.Path | ||
buildCorePath *paths.Path | ||
sketch *sketch.Sketch | ||
customBuildProperties []string | ||
compilerOptimizationFlags string | ||
clean bool | ||
builderLogger *logger.BuilderLogger | ||
} | ||
|
||
// NewBuildOptionsManager fixdoc | ||
func NewBuildOptionsManager( | ||
hardwareDirs, builtInToolsDirs, otherLibrariesDirs paths.PathList, | ||
builtInLibrariesDirs, buildPath *paths.Path, | ||
sketch *sketch.Sketch, | ||
customBuildProperties []string, | ||
fqbn *cores.FQBN, | ||
clean bool, | ||
compilerOptimizationFlags string, | ||
runtimePlatformPath, buildCorePath *paths.Path, | ||
buildLogger *logger.BuilderLogger, | ||
) *BuildOptionsManager { | ||
opts := properties.NewMap() | ||
|
||
opts.Set("hardwareFolders", strings.Join(hardwareDirs.AsStrings(), ",")) | ||
opts.Set("builtInToolsFolders", strings.Join(builtInToolsDirs.AsStrings(), ",")) | ||
opts.Set("otherLibrariesFolders", strings.Join(otherLibrariesDirs.AsStrings(), ",")) | ||
opts.SetPath("sketchLocation", sketch.FullPath) | ||
opts.Set("fqbn", fqbn.String()) | ||
opts.Set("customBuildProperties", strings.Join(customBuildProperties, ",")) | ||
opts.Set("compiler.optimization_flags", compilerOptimizationFlags) | ||
|
||
if builtInLibrariesDirs != nil { | ||
opts.Set("builtInLibrariesFolders", builtInLibrariesDirs.String()) | ||
} | ||
|
||
absPath := sketch.FullPath.Parent() | ||
var additionalFilesRelative []string | ||
for _, f := range sketch.AdditionalFiles { | ||
relPath, err := f.RelTo(absPath) | ||
if err != nil { | ||
continue // ignore | ||
} | ||
additionalFilesRelative = append(additionalFilesRelative, relPath.String()) | ||
} | ||
opts.Set("additionalFiles", strings.Join(additionalFilesRelative, ",")) | ||
|
||
return &BuildOptionsManager{ | ||
currentOptions: opts, | ||
hardwareDirs: hardwareDirs, | ||
builtInToolsDirs: builtInToolsDirs, | ||
otherLibrariesDirs: otherLibrariesDirs, | ||
builtInLibrariesDirs: builtInLibrariesDirs, | ||
buildPath: buildPath, | ||
runtimePlatformPath: runtimePlatformPath, | ||
buildCorePath: buildCorePath, | ||
sketch: sketch, | ||
customBuildProperties: customBuildProperties, | ||
compilerOptimizationFlags: compilerOptimizationFlags, | ||
clean: clean, | ||
builderLogger: buildLogger, | ||
} | ||
} | ||
|
||
// WipeBuildPath fixdoc | ||
func (m *BuildOptionsManager) WipeBuildPath() error { | ||
buildOptionsJSON, err := json.MarshalIndent(m.currentOptions, "", " ") | ||
if err != nil { | ||
return errors.WithStack(err) | ||
} | ||
m.currentBuildOptionsJSON = buildOptionsJSON | ||
|
||
if err := m.wipeBuildPath(); err != nil { | ||
return errors.WithStack(err) | ||
} | ||
return m.buildPath.Join("build.options.json").WriteFile(buildOptionsJSON) | ||
} | ||
|
||
func (m *BuildOptionsManager) wipeBuildPath() error { | ||
wipe := func() error { | ||
// FIXME: this should go outside legacy and behind a `logrus` call so users can | ||
// control when this should be printed. | ||
// logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_BUILD_OPTIONS_CHANGED + constants.MSG_REBUILD_ALL) | ||
if err := m.buildPath.RemoveAll(); err != nil { | ||
return errors.WithMessage(err, tr("cleaning build path")) | ||
} | ||
if err := m.buildPath.MkdirAll(); err != nil { | ||
return errors.WithMessage(err, tr("cleaning build path")) | ||
} | ||
return nil | ||
} | ||
|
||
if m.clean { | ||
return wipe() | ||
} | ||
|
||
// Load previous build options map | ||
var buildOptionsJSONPrevious []byte | ||
var _err error | ||
if buildOptionsFile := m.buildPath.Join("build.options.json"); buildOptionsFile.Exist() { | ||
buildOptionsJSONPrevious, _err = buildOptionsFile.ReadFile() | ||
if _err != nil { | ||
return errors.WithStack(_err) | ||
} | ||
} | ||
|
||
if len(buildOptionsJSONPrevious) == 0 { | ||
return nil | ||
} | ||
|
||
var prevOpts *properties.Map | ||
if err := json.Unmarshal(buildOptionsJSONPrevious, &prevOpts); err != nil || prevOpts == nil { | ||
m.builderLogger.Info(tr("%[1]s invalid, rebuilding all", "build.options.json")) | ||
return wipe() | ||
} | ||
|
||
// If SketchLocation path is different but filename is the same, consider it equal | ||
if filepath.Base(m.currentOptions.Get("sketchLocation")) == filepath.Base(prevOpts.Get("sketchLocation")) { | ||
m.currentOptions.Remove("sketchLocation") | ||
prevOpts.Remove("sketchLocation") | ||
} | ||
|
||
// If options are not changed check if core has | ||
if m.currentOptions.Equals(prevOpts) { | ||
// check if any of the files contained in the core folders has changed | ||
// since the json was generated - like platform.txt or similar | ||
// if so, trigger a "safety" wipe | ||
targetCoreFolder := m.runtimePlatformPath | ||
coreFolder := m.buildCorePath | ||
realCoreFolder := coreFolder.Parent().Parent() | ||
jsonPath := m.buildPath.Join("build.options.json") | ||
coreUnchanged, _ := utils.DirContentIsOlderThan(realCoreFolder, jsonPath, ".txt") | ||
if coreUnchanged && targetCoreFolder != nil && !realCoreFolder.EqualsTo(targetCoreFolder) { | ||
coreUnchanged, _ = utils.DirContentIsOlderThan(targetCoreFolder, jsonPath, ".txt") | ||
} | ||
if coreUnchanged { | ||
return nil | ||
} | ||
} | ||
|
||
return wipe() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.