@@ -53,23 +53,39 @@ def _write_versions_yml(cfg: config.Config, dest_dir: str) -> None:
5353 'Revision: "{}"\n ' .format (source_type , cfg .revision ))
5454
5555
56+ def _force_copy (src : str , dest : str , name : str , ignore = None ) -> None :
57+ """Remove 'dest/name' if it exists and copy 'src/name' to 'dest/name'."""
58+ src = os .path .join (src , name )
59+ dest = os .path .join (dest , name )
60+ logging .info ('Copying "%s" to "%s"' , src , dest )
61+ if os .path .exists (dest ):
62+ if os .path .isdir (dest ):
63+ shutil .rmtree (dest )
64+ else :
65+ os .remove (dest )
66+ if os .path .isdir (src ):
67+ shutil .copytree (src , dest , ignore = ignore )
68+ else :
69+ shutil .copy2 (src , dest )
70+
71+
5672def _copy_samples (cfg : config .Config ) -> None :
5773 """Copy code samples, filter out files that are not usable on the target
5874 platform."""
59- src = os .path .join (cfg .source_dir , 'samples' )
60- dest = os .path .join (cfg .target_llvm_dir , 'samples' )
61- if os .path .exists (dest ):
62- shutil .rmtree (dest )
63-
6475 if cfg .is_windows :
6576 # We don't filter out Makefile and Makefile.conf because we support
6677 # using Windows+MSYS2
6778 ignore = shutil .ignore_patterns ('.gitignore' )
6879 else :
6980 # make.bat is useless on Linux/Mac
7081 ignore = shutil .ignore_patterns ('.gitignore' , 'make.bat' )
71- logging .info ('Copying "%s" to "%s"' , src , dest )
72- shutil .copytree (src , dest , ignore = ignore )
82+ _force_copy (cfg .source_dir , cfg .target_llvm_dir , 'samples' , ignore )
83+
84+
85+ def _copy_docs (cfg : config .Config ) -> None :
86+ """Copy documentation."""
87+ _force_copy (cfg .source_dir , cfg .target_llvm_dir , 'docs' )
88+ _force_copy (cfg .source_dir , cfg .target_llvm_dir , 'README.md' )
7389
7490
7591def _get_excluded_symlinks (cfg : config .Config ) -> FrozenSet [str ]:
@@ -152,15 +168,12 @@ def create_binary_package(cfg: config.Config,
152168 version : Optional [repos .LLVMBMTC ]) -> None :
153169 """Create a binary package with a newly built toolchain."""
154170 if cfg .is_source_package :
155- ver_file_src = os .path .join (cfg .source_dir , 'VERSION.txt' )
156- ver_file_dest = os .path .join (cfg .target_llvm_dir , 'VERSION.txt' )
157- logging .info ('Copying version file from %s to %s' , ver_file_src ,
158- ver_file_dest )
159- shutil .copy2 (ver_file_src , ver_file_dest )
171+ _force_copy (cfg .source_dir , cfg .target_llvm_dir , 'VERSION.txt' )
160172 else :
161173 assert version is not None
162174 _write_version_file (cfg , version , cfg .target_llvm_dir )
163175 _copy_samples (cfg )
176+ _copy_docs (cfg )
164177 _create_archive (cfg , cfg .target_llvm_dir , cfg .bin_package_base_name )
165178
166179
0 commit comments