Skip to content

Conversation

@Badlazzor
Copy link
Contributor

No description provided.

Stderr: loggingIO.ToolStderr,
})

defer func() {

Choose a reason for hiding this comment

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

What was the reason for this? Using defer() is safer usually to clean up things as it is called from all exit points

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comment left there is the key, we have to close the logging before we use the xcbuild raw output. We could leave xcpretty in defer, but at this point we could just explicitly close it with the others.

Choose a reason for hiding this comment

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

The way how defer works is it will be executed just before exiting the method, so it will first execute the commands below if that's what you mean.
What was the reason you wanted to change this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, with defer the loggingIO.XcbuildRawout.Bytes(), wasn't getting the right data (actually it wasn't getting any data). It was caught by the e2e tests of steps. The problem is exactly what you write, it will execute the below stuff first and the loggingIO.Close() is where we wait for the buffers to flush.

Choose a reason for hiding this comment

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

Ah I see, so we need loggingIO.XcbuildRawout.Bytes() to execute after the closure, gotcha. Can you drop this in a comment on that line (91) please?

So // Wait for the filtering to finish before calling loggingIO.XcbuildRawout.Bytes()

// Always close xcpretty outputs
defer func() {
if err := loggingIO.Close(); err != nil {
fmt.Printf("logging IO failure, error: %s", err)

Choose a reason for hiding this comment

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

Don't we want to close logging in these cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comment left there is the key, we have to close the logging before we use the xcbuild raw output. We could leave xcpretty in defer, but at this point we could just explicitly close it with the others.

Choose a reason for hiding this comment

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

In this case we're not explicitly calling these in lines 82, 86, 91. But if we opened the pipes we should close them in those cases too, no?

This is why defer is preferable as you don't need to maintain explicit closing, it will just execute after the method exits

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I forgot about the other exit points. I get how defer works.

Choose a reason for hiding this comment

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

👍🏻 Ok, I see what we want to achieve here now.
In this case I suggest to create an anon method to avoid a lot of duplication

@Badlazzor Badlazzor merged commit e1380c0 into master Oct 13, 2025
3 checks passed
@Badlazzor Badlazzor deleted the bitrise-logging-optimisation-v2 branch October 13, 2025 09:40
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.

3 participants