Browse Source

SCons: properly close files when reading controller mappings

Fixup to #17296.
Rémi Verschelde 7 years ago
parent
commit
cc617dc5d1
2 changed files with 6 additions and 6 deletions
  1. 4 4
      main/SCsub
  2. 2 2
      main/default_controller_mappings.h

+ 4 - 4
main/SCsub

@@ -74,10 +74,9 @@ def make_default_controller_mappings(target, source, env):
     platform_mappings = OrderedDict()
     platform_mappings = OrderedDict()
     for src in source:
     for src in source:
         src_path = src.srcnode().abspath
         src_path = src.srcnode().abspath
-        f = open(src_path, "rb")
-
-        # read mapping file and skip header
-        mapping_file_lines = f.readlines()[2:]
+        with open(src_path, "rb") as f:
+            # read mapping file and skip header
+            mapping_file_lines = f.readlines()[2:]
 
 
         current_platform = None
         current_platform = None
         for line in mapping_file_lines:
         for line in mapping_file_lines:
@@ -123,6 +122,7 @@ def make_default_controller_mappings(target, source, env):
         g.write("#endif\n")
         g.write("#endif\n")
 
 
     g.write("};\n")
     g.write("};\n")
+    g.close()
 
 
 env.main_sources = []
 env.main_sources = []
 env.add_source_files(env.main_sources, "*.cpp")
 env.add_source_files(env.main_sources, "*.cpp")

+ 2 - 2
main/default_controller_mappings.h

@@ -1,5 +1,5 @@
 /*************************************************************************/
 /*************************************************************************/
-/*  input_default.h                                                      */
+/*  default_controller_mappings.h                                        */
 /*************************************************************************/
 /*************************************************************************/
 /*                       This file is part of:                           */
 /*                       This file is part of:                           */
 /*                           GODOT ENGINE                                */
 /*                           GODOT ENGINE                                */
@@ -36,4 +36,4 @@ public:
 	static const char *mappings[];
 	static const char *mappings[];
 };
 };
 
 
-#endif // DEFAULT_CONTROLLER_MAPPINGS_H
+#endif // DEFAULT_CONTROLLER_MAPPINGS_H