@@ -88,6 +88,68 @@ def _copy_docs(cfg: config.Config) -> None:
8888 _force_copy (cfg .source_dir , cfg .target_llvm_dir , 'README.md' )
8989
9090
91+ def _copy_licenses (cfg : config .Config ) -> None :
92+ """Copy licenses, including third-party licenses; create
93+ THIRD-PARTY-LICENSES.txt."""
94+ logging .info ('Copying license files' )
95+ _force_copy (cfg .source_dir , cfg .target_llvm_dir , 'LICENSE.txt' )
96+ # Contents of THIRD-PARTY-LICENSES.txt:
97+ tp_lic_lines = [
98+ 'This product embeds and uses the following pieces of software which '
99+ 'have' ,
100+ 'additional or alternate licenses:' ,
101+ ]
102+ tp_license_dir = os .path .join (cfg .target_llvm_dir , 'third-party-licenses' )
103+ if os .path .exists (tp_license_dir ):
104+ shutil .rmtree (tp_license_dir )
105+ os .makedirs (tp_license_dir )
106+
107+ def add_license (comp_name , src_path , dest_name ):
108+ tp_lic_lines .append (' - {}: third-party-licenses/{}' .format (comp_name ,
109+ dest_name ))
110+ dest_path = os .path .join (tp_license_dir , dest_name )
111+ if cfg .verbose :
112+ logging .info ('Copying %s to %s' , src_path , dest_path )
113+ shutil .copy2 (src_path , dest_path )
114+
115+ llvm_components = [
116+ ('LLVM' , 'llvm' ),
117+ ('Clang' , 'clang' ),
118+ ('lld' , 'lld' ),
119+ ('compiler-rt' , 'compiler-rt' ),
120+ ('libc++' , 'libcxx' ),
121+ ('libc++abi' , 'libcxxabi' ),
122+ ]
123+ for comp_name , comp_dir in llvm_components :
124+ src_path = os .path .join (cfg .llvm_repo_dir , comp_dir , 'LICENSE.TXT' )
125+ dest_name = '{}-LICENSE.txt' .format (comp_dir .upper ())
126+ add_license (comp_name , src_path , dest_name )
127+
128+ newlib_components = [
129+ ('newlib' , 'COPYING.NEWLIB' ),
130+ ('libgloss' , 'COPYING.LIBGLOSS' ),
131+ ]
132+ for comp_name , lic_name in newlib_components :
133+ src_path = os .path .join (cfg .newlib_repo_dir , lic_name )
134+ add_license (comp_name , src_path , lic_name )
135+
136+ tp_lic_lines += [
137+ '' ,
138+ 'Newlib and libgloss licenses refer to the source files of the '
139+ 'corresponding' ,
140+ 'libraries. To examine the source code please download the source '
141+ 'package of ' ,
142+ 'the LLVM Embedded Toolchain for Arm {} from' .format (cfg .revision ),
143+ 'https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/'
144+ 'releases.' ,
145+ ]
146+
147+ tp_lic_file = os .path .join (cfg .target_llvm_dir , 'THIRD-PARTY-LICENSES.txt' )
148+ if cfg .verbose :
149+ logging .info ('Creating %s' , tp_lic_file )
150+ util .write_lines (tp_lic_lines , tp_lic_file )
151+
152+
91153def _get_excluded_symlinks (cfg : config .Config ) -> FrozenSet [str ]:
92154 """Get a list of symlinks that should be excluded when symlinks are
93155 converted to copies (i.e. when targeting Windows or using zip as archive
@@ -174,6 +236,7 @@ def create_binary_package(cfg: config.Config,
174236 _write_version_file (cfg , version , cfg .target_llvm_dir )
175237 _copy_samples (cfg )
176238 _copy_docs (cfg )
239+ _copy_licenses (cfg )
177240 _create_archive (cfg , cfg .target_llvm_dir , cfg .bin_package_base_name )
178241
179242
0 commit comments