Migrate to Python 3

Python 2 will not be maintained past April 2020. Fortunately our scripts
require almost no changes to continue working under Python 3.

This patch forces the use of `python3` binary for all `action*` build
targets in GN and updates hashbang directives in our scripts.

Change-Id: Ic34ac547dfe5f85023ddcf4d1a969818f94a72fb
diff --git a/.gn b/.gn
index 50fa2cc..b5eecc7 100644
--- a/.gn
+++ b/.gn
@@ -14,3 +14,6 @@
 
 # The location of the build configuration file.
 buildconfig = "//build/BUILDCONFIG.gn"
+
+# Force use of Python 3
+script_executable = "python3"
diff --git a/build/image/check_elf.py b/build/image/check_elf.py
index cbc6454..1dc0cec 100644
--- a/build/image/check_elf.py
+++ b/build/image/check_elf.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Copyright 2019 The Hafnium Authors.
 #
@@ -14,7 +14,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-#!/usr/bin/env python
 """Check ELF file for assembly-level regressions.
 
 Objdumps the given ELF file and detects known assembly patterns, checking for
@@ -79,7 +78,7 @@
 
 	objdump_stdout = subprocess.check_output([
 		OBJDUMP, "-d", args.input_elf ])
-	objdump_stdout = objdump_stdout.splitlines()
+	objdump_stdout = objdump_stdout.decode("utf-8").splitlines()
 
 	check_eret_speculation_barrier(objdump_stdout)
 
diff --git a/build/image/convert_to_binary.py b/build/image/convert_to_binary.py
index 482b70e..978d359 100644
--- a/build/image/convert_to_binary.py
+++ b/build/image/convert_to_binary.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Copyright 2018 The Hafnium Authors.
 #
@@ -14,7 +14,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-#!/usr/bin/env python
 """Convert a file to binary format.
 
 Calls objcopy to convert a file into raw binary format.
diff --git a/build/image/dtc.py b/build/image/dtc.py
index 2ae8efe..c0caff8 100755
--- a/build/image/dtc.py
+++ b/build/image/dtc.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Copyright 2019 The Hafnium Authors.
 #
diff --git a/build/image/generate_initrd.py b/build/image/generate_initrd.py
index aba5ec1..901bc68 100644
--- a/build/image/generate_initrd.py
+++ b/build/image/generate_initrd.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Copyright 2018 The Hafnium Authors.
 #
diff --git a/build/image/generate_linux_initrd.py b/build/image/generate_linux_initrd.py
index 06f6502..c93e19a 100644
--- a/build/image/generate_linux_initrd.py
+++ b/build/image/generate_linux_initrd.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Copyright 2019 The Hafnium Authors.
 #
diff --git a/build/license.py b/build/license.py
index e09cbea..ee1b5e9 100644
--- a/build/license.py
+++ b/build/license.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Copyright 2018 The Hafnium Authors.
 #
diff --git a/build/linux/copy_dirs.py b/build/linux/copy_dirs.py
index e44128e..3e8ccf6 100644
--- a/build/linux/copy_dirs.py
+++ b/build/linux/copy_dirs.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Copyright 2019 The Hafnium Authors.
 #
@@ -14,7 +14,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-#!/usr/bin/env python
 """Copies all files inside one folder to another, preserving subfolders."""
 
 import argparse
diff --git a/build/linux/gen_depfile.py b/build/linux/gen_depfile.py
index 7290840..12fbd51 100755
--- a/build/linux/gen_depfile.py
+++ b/build/linux/gen_depfile.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Copyright 2019 The Hafnium Authors.
 #
@@ -14,7 +14,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-#!/usr/bin/env python
 """Generate a depfile for a folder."""
 
 import argparse
diff --git a/build/make.py b/build/make.py
index 75f0b7b..15cce9b 100644
--- a/build/make.py
+++ b/build/make.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Copyright 2019 The Hafnium Authors.
 #
diff --git a/build/parse_strace_open.py b/build/parse_strace_open.py
index 5dd878b..a971220 100755
--- a/build/parse_strace_open.py
+++ b/build/parse_strace_open.py
@@ -1,4 +1,5 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
+#
 # Copyright 2019 The Hafnium Authors.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/build/toolchain/gen_offset_size_header.py b/build/toolchain/gen_offset_size_header.py
index f9e73cb..72c4c93 100755
--- a/build/toolchain/gen_offset_size_header.py
+++ b/build/toolchain/gen_offset_size_header.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Copyright 2019 The Hafnium Authors.
 #
@@ -14,7 +14,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-#!/usr/bin/env python
 """Generate a header file with definitions of constants parsed from a binary."""
 
 import argparse
@@ -41,7 +40,7 @@
 	parser = argparse.ArgumentParser()
 	parser.add_argument("bin_file",
 		help="binary file to be parsed for definitions of constants")
-        parser.add_argument("out_file", help="output file");
+	parser.add_argument("out_file", help="output file");
 	args = parser.parse_args()
 
 	# Regex for finding definitions: <HAFNIUM_DEFINE name #value />