@@ -215,6 +215,8 @@ def write_spdx(
215215 package_name = '' ,
216216 download_location = NoAssert (),
217217 as_tagvalue = True ,
218+ spdx_version = (2 , 2 ),
219+ with_notice_text = False ,
218220):
219221 """
220222 Write scan output as SPDX Tag/value to ``output_file`` file-like
@@ -231,19 +233,25 @@ def write_spdx(
231233
232234 ns_prefix = '_' .join (package_name .lower ().split ())
233235 comment = notice + f'\n SPDX License List: { scancode_config .spdx_license_list_version } '
236+
234237 doc = Document (
235- version = Version (2 , 1 ),
238+ version = Version (* spdx_version ),
236239 data_license = License .from_identifier ('CC0-1.0' ),
237240 comment = notice ,
238241 namespace = f'http://spdx.org/spdxdocs/{ ns_prefix } -{ uuid .uuid4 ()} ' ,
242+ license_list_version = scancode_config .spdx_license_list_version ,
243+ name = 'SPDX Document created by ScanCode Toolkit'
239244 )
245+
240246 tool_name = tool_name or 'ScanCode'
241247 doc .creation_info .add_creator (Tool (f'{ tool_name } { tool_version } ' ))
242248 doc .creation_info .set_created_now ()
243249
250+ package_id = '001'
244251 package = doc .package = Package (
245252 name = package_name ,
246- download_location = download_location
253+ download_location = download_location ,
254+ spdx_id = f'SPDXRef-{ package_id } ' ,
247255 )
248256
249257 # Use a set of unique copyrights for the package.
@@ -253,7 +261,7 @@ def write_spdx(
253261 all_files_have_no_copyright = True
254262
255263 # FIXME: this should walk the codebase instead!!!
256- for file_data in files :
264+ for sid , file_data in enumerate ( files , 1 ) :
257265
258266 # Skip directories.
259267 if file_data .get ('type' ) != 'file' :
@@ -263,6 +271,7 @@ def write_spdx(
263271 # SPDX output (with explicit leading './').
264272 name = './' + file_data .get ('path' )
265273 file_entry = File (
274+ spdx_id = f'SPDXRef-{ sid } ' ,
266275 name = name ,
267276 chk_sum = Algorithm ('SHA1' , file_data .get ('sha1' ) or '' )
268277 )
0 commit comments