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

Fix build script with python 3 where each line starting with 'b and ends with \n' making it hard to read the log. #768

Merged
merged 1 commit into from
Sep 11, 2020
Merged
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
5 changes: 3 additions & 2 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import argparse
import contextlib
import codecs
import datetime
import distutils
import multiprocessing
Expand Down Expand Up @@ -124,7 +125,7 @@ def Run(context, cmd):
"""Run the specified command in a subprocess."""
PrintInfo('Running "{cmd}"'.format(cmd=cmd))

with open(context.logFileLocation, "a") as logfile:
with codecs.open(context.logFileLocation, "a", "utf-8") as logfile:
Copy link

Choose a reason for hiding this comment

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

I had a fix locally for it as well...but I didn't have to change anything else than line 150, i.e. remove encode and write simply content of l.

How can I see the issue which forced you to use codecs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had a fix locally for it as well...but I didn't have to change anything else than line 150, i.e. remove encode and write simply content of l.

If I recall correctly, I had the code originally that way and it was working on some platforms but not others.

How can I see the issue which forced you to use codecs?
Use python 3 to run the build script.

e.g
C:\Python37\python.exe build.py .....

Copy link

Choose a reason for hiding this comment

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

That is exactly what I'm doing...and all I needed is a change to switch from logfile.write(str(l.encode("utf8"))) to logfile.write(l).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I see but we had random failures with that approach. I think the codecs approach should be fine. I did a few tests and seems to be working.

Please give it a try and see if it solves things for you as well.

Choose a reason for hiding this comment

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

From offline discussion - this looks to be platform-specific and this is why I only required a smaller fix on MacOS.

logfile.write("#####################################################################################" + "\n")
logfile.write("log date: " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M") + "\n")
commitID,commitData = GetGitHeadInfo(context)
Expand All @@ -146,7 +147,7 @@ def Run(context, cmd):
if l != "":
# Avoid "UnicodeEncodeError: 'ascii' codec can't encode
# character" errors by serializing utf8 byte strings.
logfile.write(str(l.encode("utf8")))
logfile.write(l)
PrintCommandOutput(l)
elif p.poll() is not None:
break
Expand Down