@@ -235,9 +235,20 @@ def emit_dir_content(base_dir):
235
235
yield os .path .normpath (os .path .join (root , name ))
236
236
237
237
238
- def generate_content_hash (source_paths , hash_func = hashlib .sha256 , log = None ):
238
+ def generate_content_hash (
239
+ source_paths ,
240
+ content_filter ,
241
+ hash_func = hashlib .sha256 ,
242
+ log = None ,
243
+ ):
239
244
"""
240
245
Generate a content hash of the source paths.
246
+
247
+ :param content_filter: Callable[[str], Iterable[str]
248
+ A function that filters the content of the source paths. Given a path
249
+ to a file or directory, it should return an iterable of paths to files
250
+ that should be included in the hash. At present we pass in the
251
+ ZipContentFilter.filter method for this purpose.
241
252
"""
242
253
243
254
if log :
@@ -248,8 +259,7 @@ def generate_content_hash(source_paths, hash_func=hashlib.sha256, log=None):
248
259
for source_path in source_paths :
249
260
if os .path .isdir (source_path ):
250
261
source_dir = source_path
251
- _log = log if log .isEnabledFor (DEBUG3 ) else None
252
- for source_file in list_files (source_dir , log = _log ):
262
+ for source_file in content_filter (source_dir ):
253
263
update_hash (hash_obj , source_dir , source_file )
254
264
if log :
255
265
log .debug (os .path .join (source_dir , source_file ))
@@ -589,10 +599,8 @@ def apply(path):
589
599
op , regex = r
590
600
neg = op is operator .not_
591
601
m = regex .fullmatch (path )
592
- if neg and m :
593
- d = False
594
- elif m :
595
- d = True
602
+ m = bool (m )
603
+ d = not m if neg else m
596
604
if d :
597
605
return path
598
606
@@ -648,6 +656,7 @@ class BuildPlanManager:
648
656
def __init__ (self , args , log = None ):
649
657
self ._args = args
650
658
self ._source_paths = None
659
+ self ._patterns = []
651
660
self ._log = log or logging .root
652
661
653
662
def hash (self , extra_paths ):
@@ -660,7 +669,11 @@ def hash(self, extra_paths):
660
669
# runtime value, build command, and content of the build paths
661
670
# because they can have an effect on the resulting archive.
662
671
self ._log .debug ("Computing content hash on files..." )
663
- content_hash = generate_content_hash (content_hash_paths , log = self ._log )
672
+ content_filter = ZipContentFilter (args = self ._args )
673
+ content_filter .compile (self ._patterns )
674
+ content_hash = generate_content_hash (
675
+ content_hash_paths , content_filter .filter , log = self ._log
676
+ )
664
677
return content_hash
665
678
666
679
def plan (self , source_path , query ):
@@ -800,7 +813,9 @@ def commands_step(path, commands):
800
813
patterns = claim .get ("patterns" )
801
814
commands = claim .get ("commands" )
802
815
if patterns :
803
- step ("set:filter" , patterns_list (self ._args , patterns ))
816
+ patterns_as_list = patterns_list (self ._args , patterns )
817
+ self ._patterns .extend (patterns_as_list )
818
+ step ("set:filter" , patterns_as_list )
804
819
if commands :
805
820
commands_step (path , commands )
806
821
else :
0 commit comments