blob: e4641049da494dcc578fda2f5477c2e50ef3cb71 [file] [log] [blame]
Tom Finegan4f7e1042017-03-01 10:25:16 -08001##
2## Copyright (c) 2017, Alliance for Open Media. All rights reserved
3##
4## This source code is subject to the terms of the BSD 2 Clause License and
5## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6## was not distributed with this source code in the LICENSE file, you can
7## obtain it at www.aomedia.org/license/software. If the Alliance for Open
8## Media Patent License 1.0 was not distributed with this source code in the
9## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10##
11
12# Parses test/test-data.sha1 and writes captured file names and checksums to
13# $out_files and $out_checksums as lists.
Tom Finegane9d70c92017-05-10 11:31:05 -070014function (make_test_data_lists test_data_file out_files out_checksums)
15 if (NOT test_data_file OR NOT EXISTS "${test_data_file}")
16 message(FATAL_ERROR "Test info file missing or empty (${test_data_file})")
Tom Finegan4f7e1042017-03-01 10:25:16 -080017 endif ()
18
Tom Finegane9d70c92017-05-10 11:31:05 -070019 # Read $test_data_file into $files_and_checksums. $files_and_checksums becomes
20 # a list with an entry for each line from $test_data_file.
21 file(STRINGS "${test_data_file}" files_and_checksums)
Tom Finegan4f7e1042017-03-01 10:25:16 -080022
23 # Iterate over the list of lines and split it into $checksums and $filenames.
24 foreach (line ${files_and_checksums})
25 string(FIND "${line}" " *" delim_pos)
26
27 math(EXPR filename_pos "${delim_pos} + 2")
28 string(SUBSTRING "${line}" 0 ${delim_pos} checksum)
29 string(SUBSTRING "${line}" ${filename_pos} -1 filename)
30
31 set(checksums ${checksums} ${checksum})
32 set(filenames ${filenames} ${filename})
33 endforeach ()
34
Tom Finegane9d70c92017-05-10 11:31:05 -070035 list(LENGTH filenames num_files)
36 list(LENGTH checksums num_checksums)
37 if (NOT checksums OR NOT filenames OR NOT num_files EQUAL num_checksums)
38 message(FATAL_ERROR "Parsing of ${test_data_file} failed.")
Tom Finegan4f7e1042017-03-01 10:25:16 -080039 endif ()
40
41 set(${out_checksums} ${checksums} PARENT_SCOPE)
42 set(${out_files} ${filenames} PARENT_SCOPE)
43endfunction ()
44
45# Appends each file name in $test_files to $test_dir and adds the result path to
46# $out_path_list.
47function (expand_test_file_paths test_files test_dir out_path_list)
48 foreach (filename ${${test_files}})
49 set(path_list ${path_list} "${test_dir}/${filename}")
50 endforeach ()
51 set(${out_path_list} ${path_list} PARENT_SCOPE)
52endfunction ()
53
54function (check_file local_path expected_checksum out_needs_update)
55 if (EXISTS "${local_path}")
56 file(SHA1 "${local_path}" file_checksum)
57 else ()
58 set(${out_needs_update} 1 PARENT_SCOPE)
59 return ()
60 endif ()
61
62 if ("${file_checksum}" STREQUAL "${expected_checksum}")
63 unset(${out_needs_update} PARENT_SCOPE)
64 else ()
65 set(${out_needs_update} 1 PARENT_SCOPE)
Tom Finegane9d70c92017-05-10 11:31:05 -070066 return ()
Tom Finegan4f7e1042017-03-01 10:25:16 -080067 endif ()
Tom Finegane9d70c92017-05-10 11:31:05 -070068 message("${local_path} up to date.")
Tom Finegan4f7e1042017-03-01 10:25:16 -080069endfunction ()
70
71# Downloads data from $file_url, confirms that $file_checksum matches, and
72# writes it to $local_path.
73function (download_test_file file_url file_checksum local_path)
74 message("Downloading ${file_url} ...")
75 file(DOWNLOAD "${file_url}" "${local_path}"
76 SHOW_PROGRESS
77 EXPECTED_HASH SHA1=${file_checksum})
78 message("Download of ${file_url} complete.")
79endfunction ()