Skip to content
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

Cache gcc warnings #302

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Cache gcc warnings #302

wants to merge 3 commits into from

Conversation

facchinm
Copy link
Member

... and display them even if the file is not being recompiled.
Should allow removing 48aa042 from #301
There's a concurrency issue on cached prints that should be solved before merging.

Copy link
Collaborator

@matthijskooijman matthijskooijman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this looks good to me. I did leave quite some smaller remarks inline.

I don't understand the concurrency issue exactly: If this interleaves output from multiple concurrent processes, then why doesn't that happen in the original compilation run? Is that perhaps just a coincidence, that the chances of interleaving are small when each compilation command actually takes some time? Or is there some mechanism in place to actually properly interleave output from multiple processes? I can actually imagine that, for multi-process compilation, it would make sense to (only) capture all output from a single compilation command and then write that output atomically (rather than letting the compiler write to os.stdout/stderr directly, with the risk of interleaving)?

utils/utils.go Outdated Show resolved Hide resolved
utils/utils.go Outdated Show resolved Hide resolved
utils/utils.go Outdated Show resolved Hide resolved
@@ -230,12 +230,18 @@ func compileFileWithRecipe(ctx *types.Context, sourcePath string, source string,
}

if !objIsUpToDate {
_, _, err = ExecRecipe(ctx, properties, recipe, false /* stdout */, utils.ShowIfVerbose /* stderr */, utils.Show)
_, stderrCache, err := ExecRecipe(ctx, properties, recipe, false /* stdout */, utils.ShowIfVerbose /* stderr */, utils.Show)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stderrCache implies (to me) that this is a previously cached value, whereas I believe this is the value to be cached. Perhaps stderr or errOutput is a better name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if err != nil {
return "", i18n.WrapError(err)
}
} else if ctx.Verbose {
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_PREVIOUS_COMPILED_FILE, properties[constants.BUILD_PROPERTIES_OBJECT_FILE])
ctx.WarningsCache[source] = string(stderrCache)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we convert this to string? Can we not marshal a byte slice in JSON? Converting to string here, requires the use of UTF-8 (I think, at least). Probably not a problem in practice, but just keeping this a byte slice could be more transparent?

builder_utils/utils.go Outdated Show resolved Hide resolved
constants/constants.go Outdated Show resolved Hide resolved
@facchinm
Copy link
Member Author

@matthijskooijman there's a mutex that prevents interleaving when printing via logger stream, but the fact that warnings are not getting interleaved right now looks like pure luck (or something I can't understand) 🙂 .
However, compilers are quite normal beasts, they don't mess up with terminal magic like some uploaders do, so I believe we can safely cache everything and print atomically when the command returns.

@ArduinoBot
Copy link
Contributor

✅ Build completed.

⬇️ Build URL: http://downloads.arduino.cc/PR/arduino-builder/arduino-builder-302.zip

ℹ️ To test this build:

  1. Replace arduino-builder binary (you can find it where you installed the IDE) with the provided one

@facchinm
Copy link
Member Author

@matthijskooijman I think I addressed all you concerns. At the end the interleaving only happens when the streams are crunched by the Java IDE (I'll take a closer look later), but they're fine when launched on a terminal.
Thanks a lot for the review!

@arduino arduino deleted a comment from ArduinoBot Oct 16, 2018
@arduino arduino deleted a comment from ArduinoBot Oct 16, 2018
Copy link
Collaborator

@matthijskooijman matthijskooijman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Two more minor remarks added.

Are you planning to squash some of thes commits together before merging?

utils/utils.go Outdated
Show = 1 // Show on stdout/stderr as normal
ShowIfVerbose = 2 // Show if verbose is set, Ignore otherwise
Capture = 3 // Capture into buffer
Show = 1 // Print the stream
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps clarify that Show and ShowIfVerbose captures and then prints?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm planning to cleanup the patchset as soon as all the issues are fixed 😉 Good catch!

types/context.go Outdated
@@ -65,6 +65,7 @@ type Context struct {
CodeCompletions string

WarningsLevel string
WarningsCache map[string]string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should also be renamed to OutputCache or CompilerOutputCache or something?

This commits doesn't change the functionality of ExecCommand EXCEPT for programs that show progress bars or similar.
For this kind of utilities, please use Stream "type"
This file should cache warnings and other compiler output between compilations.
Directly maps to ctx.OutputCache map
The mutex is needed because the map could be concurrently accessed (when using parallel compilation)
@ArduinoBot
Copy link
Contributor

✅ Build completed.

⬇️ Build URL: http://downloads.arduino.cc/PR/arduino-builder/arduino-builder-302.zip

ℹ️ To test this build:

  1. Replace arduino-builder binary (you can find it where you installed the IDE) with the provided one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants