@@ -75,12 +75,18 @@ def init_defaults(config_tuple, path, defaults):
7575 "--inspector_protocol_dir" , type = unicode , required = True ,
7676 help = ("directory with code_generator.py and C++ encoding / binding "
7777 "libraries, relative to the root of the source tree." ))
78+ cmdline_parser .add_argument ("--depfile" , type = unicode , required = False )
79+ cmdline_parser .add_argument ("--stamp" , type = unicode , required = False )
7880 arg_options = cmdline_parser .parse_args ()
7981 jinja_dir = arg_options .jinja_dir
8082 output_base = arg_options .output_base
8183 config_file = arg_options .config
8284 config_base = os .path .dirname (config_file )
8385 config_values = arg_options .config_value
86+ if bool (arg_options .depfile ) != bool (arg_options .stamp ):
87+ raise Exception ("--depfile requires --stamp and vice versa" )
88+ depfile = arg_options .depfile
89+ stamp = arg_options .stamp
8490 inspector_protocol_dir = arg_options .inspector_protocol_dir .lstrip ('/' )
8591 except Exception :
8692 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html
@@ -122,7 +128,8 @@ def init_defaults(config_tuple, path, defaults):
122128 parts = key_value .split ("=" )
123129 if len (parts ) == 2 :
124130 defaults ["." + parts [0 ]] = parts [1 ]
125- return (jinja_dir , config_file , init_defaults (config_partial , "" , defaults ))
131+ return (jinja_dir , config_file , init_defaults (config_partial , "" , defaults ),
132+ depfile , stamp )
126133 except Exception :
127134 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html
128135 exc = sys .exc_info ()[1 ]
@@ -360,6 +367,7 @@ class Protocol(object):
360367 def __init__ (self , config ):
361368 self .config = config
362369 self .json_api = {"domains" : []}
370+ self .source_set = set ()
363371 self .imported_domains = []
364372 self .exported_domains = []
365373 self .generate_domains = self .read_protocol_file (config .protocol .path )
@@ -381,7 +389,8 @@ def __init__(self, config):
381389
382390 def read_protocol_file (self , file_name ):
383391 input_file = open (file_name , "r" )
384- parsed_json = pdl .loads (input_file .read (), file_name )
392+ parsed_json = pdl .loads (input_file .read (), file_name , False ,
393+ self .source_set )
385394 input_file .close ()
386395 version = '%s.%s' % (parsed_json ["version" ]["major" ],
387396 parsed_json ["version" ]["minor" ])
@@ -600,9 +609,10 @@ def is_imported_dependency(self, domain):
600609
601610
602611def main ():
603- jinja_dir , config_file , config = read_config ()
612+ jinja_dir , config_file , config , deps_filename , stamp_filename = read_config ()
604613
605614 protocol = Protocol (config )
615+ source_set = protocol .source_set
606616
607617 if not config .exported and len (protocol .exported_domains ):
608618 sys .stderr .write (("Domains [%s] are exported, but config is missing export "
@@ -648,18 +658,26 @@ def main():
648658 }
649659
650660 if domain ["domain" ] in protocol .generate_domains :
651- outputs [os .path .join (config .protocol .output , to_file_name (
652- config , file_name + ".h" ))] = h_template .render (template_context )
653- outputs [os .path .join (config .protocol .output , to_file_name (
654- config , file_name + ".cpp" ))] = cpp_template .render (template_context )
661+ output_h = os .path .join (config .protocol .output , to_file_name (
662+ config , file_name + ".h" ))
663+ outputs [output_h ] = h_template .render (template_context )
664+ source_set .add (h_template .filename )
665+ output_cpp = os .path .join (config .protocol .output , to_file_name (
666+ config , file_name + ".cpp" ))
667+ outputs [output_cpp ] = cpp_template .render (template_context )
668+ source_set .add (cpp_template .filename )
655669 if domain ["domain" ] in protocol .exported_domains :
656- outputs [os .path .join (config .exported .output , to_file_name (
657- config , file_name + ".h" ))] = exported_template .render (
670+ output_export_h = os .path .join (config .exported .output , to_file_name (
671+ config , file_name + ".h" ))
672+ outputs [output_export_h ] = exported_template .render (
658673 template_context )
674+ source_set .add (exported_template .filename )
659675 if domain ["domain" ] in protocol .imported_domains :
660- outputs [os .path .join (config .protocol .output , to_file_name (
661- config , file_name + ".h" ))] = imported_template .render (
676+ output_import_h = os .path .join (config .protocol .output , to_file_name (
677+ config , file_name + ".h" ))
678+ outputs [output_import_h ] = imported_template .render (
662679 template_context )
680+ source_set .add (imported_template .filename )
663681
664682 if config .lib :
665683 template_context = {
@@ -702,6 +720,7 @@ def generate_lib_file(file_name, template_files):
702720 inputs .append (os .path .join (lib_templates_dir , template_file ))
703721 template = jinja_env .get_template ("lib/" + template_file )
704722 parts .append (template .render (template_context ))
723+ source_set .add (template .filename )
705724 outputs [file_name ] = "\n \n " .join (parts )
706725
707726 generate_lib_file (os .path .join (config .lib .output , to_file_name (
@@ -713,17 +732,9 @@ def generate_lib_file(file_name, template_files):
713732 generate_lib_file (os .path .join (config .lib .output , to_file_name (
714733 config , "Protocol.cpp" )), protocol_cpp_templates )
715734
716- # Make gyp / make generatos happy, otherwise make rebuilds world.
717- inputs_ts = max (map (os .path .getmtime , inputs ))
718- up_to_date = True
719- for output_file in outputs .keys ():
720- if (not os .path .exists (output_file )
721- or os .path .getmtime (output_file ) < inputs_ts ):
722- up_to_date = False
723- break
724- if up_to_date :
725- sys .exit ()
726-
735+ if stamp_filename :
736+ with open (stamp_filename , "w" ):
737+ pass
727738 for file_name , content in outputs .items ():
728739 # Remove output file first to account for potential case changes.
729740 try :
@@ -734,6 +745,12 @@ def generate_lib_file(file_name, template_files):
734745 out_file .write (content )
735746 out_file .close ()
736747
748+ if deps_filename :
749+ assert stamp_filename
750+ with open (deps_filename , "w" ) as deps_file :
751+ deps_file .write ("%s: %s\n " % (
752+ stamp_filename , " " .join (sorted (source_set ))))
753+
737754
738755if __name__ == "__main__" :
739756 main ()
0 commit comments