1919""" 
2020
2121import  argparse 
22+ from  collections .abc  import  Iterable 
2223import  glob 
2324import  os 
2425import  os .path 
@@ -35,32 +36,35 @@ def main() -> None:
3536    parser .add_argument ('--release' , action = 'store_true' )
3637    parser .add_argument ('--readme' , type = pathlib .Path , required = True )
3738    parser .add_argument ('--install' , type = pathlib .Path , required = True )
39+     parser .add_argument (
40+         '--srcs' , type = argparse .FileType ('rt' , encoding = 'utf-8' ), required = True )
3841    parser .add_argument ('--bash' , type = pathlib .Path )
3942    parser .add_argument ('--cc' , type = pathlib .Path )
4043    parser .add_argument ('--cflags' )
4144    parser .add_argument ('--ldflags' )
4245    parser .add_argument ('--module-header' , type = pathlib .Path )
4346    args  =  parser .parse_args ()
44-     source  =  args .readme .resolve (). parent 
47+     source  =  args .readme .parent 
4548    install  =  args .install .resolve ()
4649
4750    if  args .release :
48-         _unpack (source = source , install = install )
51+         _unpack (source = source , install = install ,  lines = args . srcs )
4952    else :
50-         _build (source = source , install = install , bash = args .bash ,
53+         _build (source = source , install = install , lines = args . srcs ,  bash = args .bash ,
5154               cc = args .cc , cflags = args .cflags , ldflags = args .ldflags )
5255
5356    if  args .module_header :
5457        # Copy emacs-module.h to the desired location. 
5558        shutil .copy (install  /  'include'  /  'emacs-module.h' , args .module_header )
5659
5760
58- def  _build (* , source : pathlib .Path , install : pathlib .Path , bash : pathlib .Path ,
61+ def  _build (* , source : pathlib .Path , install : pathlib .Path ,
62+            lines : Iterable [str ], bash : pathlib .Path ,
5963           cc : pathlib .Path , cflags : str , ldflags : str ) ->  None :
6064    windows  =  platform .system () ==  'Windows' 
6165    temp  =  pathlib .Path (tempfile .mkdtemp (prefix = 'emacs-build-' ))
6266    build  =  temp  /  'build' 
63-     shutil . copytree (source ,  build )
67+     _unpack (source = source ,  install = build ,  lines = lines )
6468
6569    def  run (* command : str ) ->  None :
6670        env  =  None 
@@ -121,15 +125,14 @@ def run(*command: str) -> None:
121125    _rename (shared  /  'lisp' , install  /  'lisp' )
122126
123127
124- def  _unpack (* , source : pathlib .Path , install : pathlib .Path ) ->  None :
125-     try :
126-         # Bazel sometimes creates the output directory; remove it so that 
127-         # _unpack_archive works correctly. 
128-         install .rmdir ()
129-     except  FileNotFoundError :
130-         pass 
131- 
132-     shutil .copytree (source , install )
128+ def  _unpack (* , source : pathlib .Path , install : pathlib .Path ,
129+             lines : Iterable [str ]) ->  None :
130+     for  line  in  lines :
131+         src  =  pathlib .Path (line .rstrip ('\n ' ))
132+         rel  =  src .relative_to (source )
133+         dest  =  install  /  rel 
134+         dest .parent .mkdir (parents = True , exist_ok = True )
135+         shutil .copy2 (src , dest )
133136
134137
135138def  _glob_unique (pattern : pathlib .PurePath ) ->  pathlib .Path :
0 commit comments