diff --git a/builder.go b/builder.go index 6c143996..d8578f5d 100644 --- a/builder.go +++ b/builder.go @@ -151,7 +151,7 @@ func (s *PreprocessSketch) Run(ctx *types.Context) error { } else { commands = append(commands, &ContainerAddPrototypes{}) } - return runCommands(ctx, commands, true) + return runCommands(ctx, commands, false) } type Preprocess struct{} @@ -198,12 +198,14 @@ func (s *ParseHardwareAndDumpBuildProperties) Run(ctx *types.Context) error { func runCommands(ctx *types.Context, commands []types.Command, progressEnabled bool) error { ctx.Progress.PrintEnabled = progressEnabled - ctx.Progress.Progress = 0 for _, command := range commands { PrintRingNameIfDebug(ctx, command) - ctx.Progress.Steps = 100.0 / float64(len(commands)) - builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx) + + stepSize := float64(100-(6*len(ctx.ImportedLibraries))) / float64(len(commands)) + ctx.Progress.Steps = stepSize + + builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx, progressEnabled, stepSize) err := command.Run(ctx) if err != nil { return i18n.WrapError(err) diff --git a/builder_utils/utils.go b/builder_utils/utils.go index 276cfd19..1e2012d1 100644 --- a/builder_utils/utils.go +++ b/builder_utils/utils.go @@ -46,16 +46,21 @@ import ( "github.com/arduino/go-properties-map" ) -func PrintProgressIfProgressEnabledAndMachineLogger(ctx *types.Context) { +var mut sync.Mutex - if !ctx.Progress.PrintEnabled { +func PrintProgressIfProgressEnabledAndMachineLogger(ctx *types.Context, progressEnabled bool, stepSize float64) { + + if !progressEnabled { return } log := ctx.GetLogger() if log.Name() == "machine" { + mut.Lock() log.Println(constants.LOG_LEVEL_INFO, constants.MSG_PROGRESS, strconv.FormatFloat(ctx.Progress.Progress, 'f', 2, 32)) - ctx.Progress.Progress += ctx.Progress.Steps + ctx.Progress.Progress += stepSize + log.Flush() + mut.Unlock() } } @@ -168,14 +173,14 @@ func compileFilesWithRecipe(ctx *types.Context, objectFiles []string, sourcePath errorsChan := make(chan error) doneChan := make(chan struct{}) - ctx.Progress.Steps = ctx.Progress.Steps / float64(len(sources)) + stepSize := ctx.Progress.Steps / float64(len(sources)) var wg sync.WaitGroup wg.Add(len(sources)) for _, source := range sources { go func(source string) { defer wg.Done() - PrintProgressIfProgressEnabledAndMachineLogger(ctx) + go PrintProgressIfProgressEnabledAndMachineLogger(ctx, true, stepSize) objectFile, err := compileFileWithRecipe(ctx, sourcePath, source, buildPath, buildProperties, includes, recipe) if err != nil { errorsChan <- err diff --git a/container_find_includes.go b/container_find_includes.go index df0fca81..fb3db3f3 100644 --- a/container_find_includes.go +++ b/container_find_includes.go @@ -148,8 +148,11 @@ func (s *ContainerFindIncludes) Run(ctx *types.Context) error { queueSourceFilesFromFolder(ctx, sourceFilePaths, sketch, srcSubfolderPath, true /* recurse */) } + stepSize := ctx.Progress.Steps / 20.0 + stepLimit := ctx.Progress.Progress + ctx.Progress.Steps + for !sourceFilePaths.Empty() { - err := findIncludesUntilDone(ctx, cache, sourceFilePaths.Pop()) + err := findIncludesUntilDone(ctx, cache, sourceFilePaths.Pop(), stepSize, stepLimit) if err != nil { os.Remove(cachePath) return i18n.WrapError(err) @@ -290,7 +293,7 @@ func writeCache(cache *includeCache, path string) error { return nil } -func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile types.SourceFile) error { +func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile types.SourceFile, stepSize, stepLimit float64) error { sourcePath := sourceFile.SourcePath(ctx) depPath := sourceFile.DepfilePath(ctx) objPath := sourceFile.ObjectPath(ctx) @@ -318,6 +321,8 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t var include string cache.ExpectFile(sourcePath) + go builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx, ctx.Progress.Progress < stepLimit, stepSize) + includes := ctx.IncludeFolders if library, ok := sourceFile.Origin.(*types.Library); ok && library.UtilityFolder != "" { includes = append(includes, library.UtilityFolder) diff --git a/container_setup.go b/container_setup.go index 57749aa2..a8cc72da 100644 --- a/container_setup.go +++ b/container_setup.go @@ -55,10 +55,11 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context) &AddMissingBuildPropertiesFromParentPlatformTxtFiles{}, } - ctx.Progress.Steps = ctx.Progress.Steps / float64(len(commands)) + stepSize := ctx.Progress.Steps / float64(len(commands)) + ctx.Progress.Steps = stepSize for _, command := range commands { - builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx) + builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx, ctx.Progress.PrintEnabled, stepSize) PrintRingNameIfDebug(ctx, command) err := command.Run(ctx) if err != nil {