66from copy import copy
77import functools
88import importlib
9- import importlib .abc
109import importlib .util
1110from importlib .machinery import (
1211 SourceFileLoader ,
1918import hashlib
2019import re
2120import ast
22- import os
2321from collections import namedtuple
2422
25- COMPRESS_MK_FILE = True
23+ VERBOSE_MK_FILE = False
2624
2725verbose = False
2826quiet = False
@@ -225,16 +223,13 @@ def format_field(self, value, format_spec):
225223 if not value :
226224 return ""
227225 if type (value ) == str :
228- return compressf ( value )
226+ return value
229227 if _isiterable (value ):
230228 value = list (value )
231229 if type (value ) != list :
232230 value = [value ]
233231 return " " .join (
234- [
235- compressf (selfi .templateexpand (f ))
236- for f in filenamesof (value )
237- ]
232+ [selfi .templateexpand (f ) for f in filenamesof (value )]
238233 )
239234
240235 return Formatter ().format (s )
@@ -467,30 +462,6 @@ def filenameof(x):
467462 return xs [0 ]
468463
469464
470- def compressf (a ):
471- if not COMPRESS_MK_FILE :
472- return a
473- global globalId
474- if len (a ) > 5 :
475- if a not in wordCache :
476- wordCache [a ] = globalId
477- outputFp .write (f"f{ globalId } ={ a } \n " )
478- globalId = globalId + 1
479- a = f"$(f{ wordCache [a ]} )"
480- return a
481-
482-
483- def compress (args ):
484- if not COMPRESS_MK_FILE :
485- return args
486-
487- compressed = []
488- for a in args :
489- compressed += [compressf (a )]
490-
491- return compressed
492-
493-
494465def emit (* args , into = None ):
495466 s = " " .join (args ) + "\n "
496467 if into is not None :
@@ -507,77 +478,61 @@ def emit_rule(self, ins, outs, cmds=[], label=None):
507478 nonobjs = [f for f in fouts if not f .startswith ("$(OBJ)" )]
508479
509480 emit ("" )
510- for k , v in self .args .items ():
511- emit (f"# { k } = { v } " )
481+ if VERBOSE_MK_FILE :
482+ for k , v in self .args .items ():
483+ emit (f"# { k } = { v } " )
512484
513485 lines = []
514486 if nonobjs :
515487 emit ("clean::" , into = lines )
516- emit ("\t $(hide) rm -f" , * compress ( nonobjs ) , into = lines )
488+ emit ("\t $(hide) rm -f" , * nonobjs , into = lines )
517489
518490 hashable = cmds + fins_list + fouts
519491 hash = hashlib .sha1 (bytes ("\n " .join (hashable ), "utf-8" )).hexdigest ()
520492 hashfile = join (self .dir , f"hash_{ hash } " )
521493
522494 global globalId
523- emit (".PHONY:" , compressf ( name ) , into = lines )
495+ emit (".PHONY:" , name , into = lines )
524496 if outs :
525497 outsn = globalId
526498 globalId = globalId + 1
527499 insn = globalId
528500 globalId = globalId + 1
529501
530- emit (f"OUTS_{ outsn } " , "=" , * compress (fouts ), into = lines )
531- emit (f"INS_{ insn } " , "=" , * compress (fins ), into = lines )
532- emit (
533- compressf (name ),
534- ":" ,
535- compressf (hashfile ),
536- f"$(OUTS_{ outsn } )" ,
537- into = lines ,
538- )
539- emit ("ifeq ($(MAKE4.3),yes)" , into = lines )
540- emit (
541- compressf (hashfile ),
542- f"$(OUTS_{ outsn } )" ,
543- "&:" ,
544- f"$(INS_{ insn } )" ,
545- into = lines ,
546- )
547- emit ("else" , into = lines )
548- emit (f"$(OUTS_{ outsn } )" , ":" , compressf (hashfile ), into = lines )
549- emit (compressf (hashfile ), ":" , f"$(INS_{ insn } )" , into = lines )
550- emit ("endif" , into = lines )
502+ emit (f"OUTS_{ outsn } " , "=" , * fouts , into = lines )
503+ emit (f"INS_{ insn } " , "=" , * fins , into = lines )
504+ emit (name , ":" , f"$(OUTS_{ outsn } )" )
505+ emit (hashfile , ":" )
506+ emit (f"\t @mkdir -p { self .dir } " )
507+ emit (f"\t @touch { hashfile } " )
508+ emit (f"$(OUTS_{ outsn } )" , "&:" ,f"$(INS_{ insn } )" , hashfile , into = lines )
551509
552510 if label :
553511 emit ("\t $(hide)" , "$(ECHO) $(PROGRESSINFO)" + label , into = lines )
554512
555513 sandbox = join (self .dir , "sandbox" )
556- emit ("\t $(hide)" , f"rm -rf { compressf ( sandbox ) } " , into = lines )
514+ emit ("\t $(hide)" , f"rm -rf { sandbox } " , into = lines )
557515 emit (
558516 "\t $(hide)" ,
559- compressf ( "$(PYTHON) build/_sandbox.py --link -s" ) ,
560- compressf ( sandbox ) ,
517+ "$(PYTHON) build/_sandbox.py --link -s" ,
518+ sandbox ,
561519 f"$(INS_{ insn } )" ,
562520 into = lines ,
563521 )
564522 for c in cmds :
565- emit (f"\t $(hide) cd { compressf ( sandbox ) } && (" , c , ")" , into = lines )
523+ emit (f"\t $(hide) cd { sandbox } && (" , c , ")" , into = lines )
566524 emit (
567525 "\t $(hide)" ,
568- compressf ( "$(PYTHON) build/_sandbox.py --export -s" ) ,
569- compressf ( sandbox ) ,
526+ "$(PYTHON) build/_sandbox.py --export -s" ,
527+ sandbox ,
570528 f"$(OUTS_{ outsn } )" ,
571529 into = lines ,
572530 )
573531 else :
574532 assert len (cmds ) == 0 , "rules with no outputs cannot have commands"
575- emit (compressf ( name ) , ":" , * compress ( fins ) , into = lines )
533+ emit (name , ":" , * fins , into = lines )
576534
577535 outputFp .write ("" .join (lines ))
578-
579- if outs :
580- emit (f"\t $(hide) touch { compressf (hashfile )} " )
581536 emit ("" )
582537
583538
@@ -645,8 +600,8 @@ def export(self, name=None, items: TargetsMap = {}, deps: Targets = []):
645600 self .outs = deps + outs
646601
647602 emit ("" )
648- emit (".PHONY:" , compressf ( name ) )
649- emit (compressf ( name ) , ":" , * compress ( filenamesof (outs + deps ) ))
603+ emit (".PHONY:" , name )
604+ emit (name , ":" , * filenamesof (outs + deps ))
650605
651606
652607def main ():
0 commit comments