From 0c98beed25c41f7804cb95a5d5e6635a5d2c7065 Mon Sep 17 00:00:00 2001 From: Guy Margalit Date: Mon, 14 Nov 2016 00:34:32 +0200 Subject: [PATCH] gyp: Open the build file with universal-newlines mode To make sure platform specific newlines ('\r\n' or '\r') are converted to '\n' which otherwise will fail eval(). This should handle multiple issues reported on syntax error reading binding.gyp (partial list): https://github.com/nodejs/node-gyp/issues/979 https://github.com/nodejs/node-gyp/issues/199 https://github.com/stephenwvickers/node-net-ping/issues/24 https://github.com/stephenwvickers/node-net-ping/issues/21 https://github.com/mathiask88/node-snap7/issues/11 https://github.com/node-hid/node-hid/issues/28 https://github.com/xdenser/node-firebird-libfbclient/issues/24 PR-URL: https://github.com/nodejs/node-gyp/pull/1053 Reviewed-By: Ben Noordhuis --- gyp/pylib/gyp/input.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gyp/pylib/gyp/input.py b/gyp/pylib/gyp/input.py index a046a15cc1..56cdece0aa 100644 --- a/gyp/pylib/gyp/input.py +++ b/gyp/pylib/gyp/input.py @@ -231,7 +231,10 @@ def LoadOneBuildFile(build_file_path, data, aux_data, includes, return data[build_file_path] if os.path.exists(build_file_path): - build_file_contents = open(build_file_path).read() + # Open the build file for read ('r') with universal-newlines mode ('U') + # to make sure platform specific newlines ('\r\n' or '\r') are converted to '\n' + # which otherwise will fail eval() + build_file_contents = open(build_file_path, 'rU').read() else: raise GypError("%s not found (cwd: %s)" % (build_file_path, os.getcwd()))