22# The .NET Foundation licenses this file to you under the Apache 2.0 License.
33# See the LICENSE file in the project root for more information.
44
5+ import functools
56import re
67import sys
78import os
@@ -23,7 +24,8 @@ def get_root_dir():
2324 os .path .join (root_dir , "Src" , "StdLib" ),
2425]
2526
26- START = "#region Generated %s"
27+ START_COMMON = "#region Generated"
28+ START = START_COMMON + " %s"
2729END = "#endregion"
2830PREFIX = r"^([ \t]*)"
2931
@@ -131,6 +133,27 @@ def text(self):
131133 def conditions (self ):
132134 return ConditionWriter (self )
133135
136+ @functools .lru_cache ()
137+ def find_candidates (dirname ):
138+ def listdir (dirname ):
139+ if dirname in exclude_directories :
140+ return
141+
142+ for file in os .listdir (dirname ):
143+ if file == "obj" : continue # obj folders are not interesting...
144+ filename = os .path .join (dirname , file )
145+ if os .path .isdir (filename ):
146+ yield from listdir (filename )
147+ elif filename .endswith (".cs" ) and not file == "StandardTestStrings.cs" : # TODO: fix encoding of StandardTestStrings.cs
148+ yield filename
149+
150+ res = []
151+ for file in listdir (dirname ):
152+ with open (file , encoding = 'latin-1' ) as f :
153+ if START_COMMON in f .read ():
154+ res .append (file )
155+ return res
156+
134157class CodeGenerator :
135158 def __init__ (self , name , generator ):
136159 self .generator = generator
@@ -151,19 +174,10 @@ def do_generate(self):
151174 result .append (g .generate ())
152175 return result
153176
154- def do_dir (self , dirname ):
155- if dirname in exclude_directories :
156- return
157- for file in os .listdir (dirname ):
158- filename = os .path .join (dirname , file )
159- if os .path .isdir (filename ):
160- self .do_dir (filename )
161- elif filename .endswith (".cs" ) and not file == "StandardTestStrings.cs" : # TODO: fix encoding of StandardTestStrings.cs
162- self .do_file (filename )
163-
164177 def doit (self ):
165178 for src_dir in source_directories :
166- self .do_dir (src_dir )
179+ for file in find_candidates (src_dir ):
180+ self .do_file (file )
167181 for g in self .generators :
168182 g .collect_info ()
169183 return self .do_generate ()
0 commit comments