From 439a8e86013b987e1fd93ade81ac1968543b6378 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Wed, 16 Oct 2019 16:29:38 +0200 Subject: [PATCH 1/7] sys.stderr.write(p_stderr) with python 3 errors out with: `TypeError: write() argument must be str, not bytes`. It seems to me that its unneccesary, and it should simply throw the exception instead. --- gyp/pylib/gyp/input.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/gyp/pylib/gyp/input.py b/gyp/pylib/gyp/input.py index aba81cf654..c4d3b56c54 100644 --- a/gyp/pylib/gyp/input.py +++ b/gyp/pylib/gyp/input.py @@ -911,9 +911,6 @@ def ExpandVariables(input, phase, variables, build_file): p_stdout, p_stderr = p.communicate('') if p.wait() != 0 or p_stderr: - sys.stderr.write(p_stderr) - # Simulate check_call behavior, since check_call only exists - # in python 2.5 and later. raise GypError("Call to '%s' returned exit status %d while in %s." % (contents, p.returncode, build_file)) replacement = p_stdout.rstrip() From 25c6a6953357c5d72e5af4c7b501ca281acce0a5 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Wed, 16 Oct 2019 16:31:22 +0200 Subject: [PATCH 2/7] It seems python 3 doesn't linke `None` as a parameter here, it will throw: `Exception: 'NoneType' object is not subscriptable`. --- gyp/pylib/gyp/input.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gyp/pylib/gyp/input.py b/gyp/pylib/gyp/input.py index c4d3b56c54..968f36ac0a 100644 --- a/gyp/pylib/gyp/input.py +++ b/gyp/pylib/gyp/input.py @@ -239,7 +239,7 @@ def LoadOneBuildFile(build_file_path, data, aux_data, includes, if check: build_file_data = CheckedEval(build_file_contents) else: - build_file_data = eval(build_file_contents, {'__builtins__': None}, + build_file_data = eval(build_file_contents, {'__builtins__': {}}, None) except SyntaxError as e: e.filename = build_file_path @@ -1087,7 +1087,7 @@ def EvalSingleCondition( else: ast_code = compile(cond_expr_expanded, '', 'eval') cached_conditions_asts[cond_expr_expanded] = ast_code - if eval(ast_code, {'__builtins__': None}, variables): + if eval(ast_code, {'__builtins__': {}}, variables): return true_dict return false_dict except SyntaxError as e: From 19012c801fcf68085f161ce5faeaea28fa4f625e Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Wed, 16 Oct 2019 16:53:41 +0200 Subject: [PATCH 3/7] properly encode strings before handing them over to hashlib.sha --- gyp/pylib/gyp/generator/make.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gyp/pylib/gyp/generator/make.py b/gyp/pylib/gyp/generator/make.py index bdf7134537..a7639ad6e2 100644 --- a/gyp/pylib/gyp/generator/make.py +++ b/gyp/pylib/gyp/generator/make.py @@ -1776,7 +1776,7 @@ def WriteMakeRule(self, outputs, inputs, actions=None, comment=None, # - The multi-output rule will have an do-nothing recipe. # Hash the target name to avoid generating overlong filenames. - cmddigest = hashlib.sha1(command if command else self.target).hexdigest() + cmddigest = hashlib.sha1(command.encode('utf-8') if command else self.target.encode('utf-8')).hexdigest() intermediate = "%s.intermediate" % cmddigest self.WriteLn('%s: %s' % (' '.join(outputs), intermediate)) self.WriteLn('\t%s' % '@:') From 34dcfad82f0a2e944a009ba0ff4aa1f44ad2a12f Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Thu, 17 Oct 2019 10:39:51 +0200 Subject: [PATCH 4/7] fix encoding as sugested by @cclaus --- gyp/pylib/gyp/generator/make.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gyp/pylib/gyp/generator/make.py b/gyp/pylib/gyp/generator/make.py index a7639ad6e2..48d0f55a02 100644 --- a/gyp/pylib/gyp/generator/make.py +++ b/gyp/pylib/gyp/generator/make.py @@ -1776,7 +1776,8 @@ def WriteMakeRule(self, outputs, inputs, actions=None, comment=None, # - The multi-output rule will have an do-nothing recipe. # Hash the target name to avoid generating overlong filenames. - cmddigest = hashlib.sha1(command.encode('utf-8') if command else self.target.encode('utf-8')).hexdigest() + + cmddigest = hashlib.sha1((command or self.target).encode('utf-8')).hexdigest() intermediate = "%s.intermediate" % cmddigest self.WriteLn('%s: %s' % (' '.join(outputs), intermediate)) self.WriteLn('\t%s' % '@:') From b69589886d349ef009e625d9e9f56bf61cbac91e Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Thu, 17 Oct 2019 11:16:54 +0200 Subject: [PATCH 5/7] as seen in GYP3 this seems to be the solution here too --- gyp/pylib/gyp/input.py | 1 + 1 file changed, 1 insertion(+) diff --git a/gyp/pylib/gyp/input.py b/gyp/pylib/gyp/input.py index 968f36ac0a..42390f23eb 100644 --- a/gyp/pylib/gyp/input.py +++ b/gyp/pylib/gyp/input.py @@ -911,6 +911,7 @@ def ExpandVariables(input, phase, variables, build_file): p_stdout, p_stderr = p.communicate('') if p.wait() != 0 or p_stderr: + sys.stderr.write(p_stderr.decode('utf-8')) raise GypError("Call to '%s' returned exit status %d while in %s." % (contents, p.returncode, build_file)) replacement = p_stdout.rstrip() From 15a0dedd2dc70acbaf0eeb52b1e711bc2486586d Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 30 Oct 2019 15:27:26 +0100 Subject: [PATCH 6/7] Revert the addition of a blank line --- gyp/pylib/gyp/generator/make.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gyp/pylib/gyp/generator/make.py b/gyp/pylib/gyp/generator/make.py index 48d0f55a02..1960536794 100644 --- a/gyp/pylib/gyp/generator/make.py +++ b/gyp/pylib/gyp/generator/make.py @@ -1776,7 +1776,6 @@ def WriteMakeRule(self, outputs, inputs, actions=None, comment=None, # - The multi-output rule will have an do-nothing recipe. # Hash the target name to avoid generating overlong filenames. - cmddigest = hashlib.sha1((command or self.target).encode('utf-8')).hexdigest() intermediate = "%s.intermediate" % cmddigest self.WriteLn('%s: %s' % (' '.join(outputs), intermediate)) From cea42a4df40109d3b7f10e9ffc82c6d16acf626d Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 30 Oct 2019 15:31:43 +0100 Subject: [PATCH 7/7] Revert stderr.decode("utf-8") that was landed in #1937 #1937 --- gyp/pylib/gyp/input.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gyp/pylib/gyp/input.py b/gyp/pylib/gyp/input.py index 42390f23eb..309959ef75 100644 --- a/gyp/pylib/gyp/input.py +++ b/gyp/pylib/gyp/input.py @@ -911,7 +911,9 @@ def ExpandVariables(input, phase, variables, build_file): p_stdout, p_stderr = p.communicate('') if p.wait() != 0 or p_stderr: - sys.stderr.write(p_stderr.decode('utf-8')) + sys.stderr.write(p_stderr) + # Simulate check_call behavior, since check_call only exists + # in python 2.5 and later. raise GypError("Call to '%s' returned exit status %d while in %s." % (contents, p.returncode, build_file)) replacement = p_stdout.rstrip()