Debian Codegraph @

cmake/tribits/core/package_arch/TribitsFindMostRecentFileTimestamp.cmake

raw
1 # @HEADER
2 # *****************************************************************************
3 # TriBITS: Tribal Build, Integrate, and Test System
4 #
5 # Copyright 2013-2016 NTESS and the TriBITS contributors.
6 # SPDX-License-Identifier: BSD-3-Clause
7 # *****************************************************************************
8 # @HEADER
9
10
11 include(TribitsConfigureTiming)
12
13 include(CMakeParseArguments)
14
15
16 # @FUNCTION: tribits_find_most_recent_file_timestamp()
17 #
18 # Find the most modified file in a set of base directories and return its
19 # timestamp.
20 #
21 # Usage::
22 #
23 # tribits_find_most_recent_file_timestamp(
24 # BASE_DIRS <dir0> <dir1> ...
25 # [BASE_BASE_DIR <dir>]
26 # [EXCLUDE_REGEXES "<re0>" "<re1>" ...
27 # [SHOW_MOST_RECENT_FILES]
28 # [SHOW_OVERALL_MOST_RECENT_FILE]
29 # [MOST_RECENT_TIMESTAMP_OUT <mostRecentTimestamp>]
30 # [MOST_RECENT_FILEPATH_BASE_DIR_OUT <mostRecentFilepathBaseDir>]
31 # [MOST_RECENT_RELATIVE_FILEPATH_OUT <mostRecentRelativeFilePath>]
32 # )
33 #
34 # **Arguments:**
35 #
36 # ``BASE_DIRS <dir0> <dir1> ...``
37 #
38 # Gives the absolute base directory paths that will be searched for the
39 # most recently modified files, as described above.
40 #
41 # ``BASE_BASE_DIR <dir>```
42 #
43 # Absolute path for which to print file paths relative to. This makes
44 # outputting less verbose and easier to read (optional).
45 #
46 # ``EXCLUDE_REGEXES "<re0>" "<re1>" ...``
47 #
48 # Gives the regular expressions that are used to exclude files from
49 # consideration. Each "<rei>" regex is used with a `grep -v "<rei>"`
50 # filter to exclude files before sorting by time stamp.
51 #
52 # ``SHOW_MOST_RECENT_FILES``
53 #
54 # If specified, then the most recently modified file for each individual
55 # directory ``<dir0>``, ``<dir1``, ... will be printed the STDOUT.
56 # Setting this implies ``SHOW_OVERALL_MOST_RECENT_FILE``.
57 #
58 # ``SHOW_OVERALL_MOST_RECENT_FILE``
59 #
60 # If specified, then only the most recent modified file over all of the
61 # individual directories is printed to STDOUT.
62 #
63 # ``MOST_RECENT_TIMESTAMP_OUT <mostRecentTimestamp>``
64 #
65 # On output, the variable `<mostRecentTimestamp>` is set that gives the
66 # timestamp of the most recently modified file over all the directories.
67 # This number is given as the number of seconds since Jan. 1, 1970, 00:00
68 # GMT.
69 #
70 # ``MOST_RECENT_FILEPATH_BASE_DIR_OUT <mostRecentFilepathBaseDir>``
71 #
72 # On output, the variable `<mostRecentFilepathBaseDir>` gives absolute base
73 # directory of the file with the most recent timestamp over all
74 # directories.
75 #
76 # ``MOST_RECENT_RELATIVE_FILEPATH_OUT <mostRecentRelativeFilePath>``
77 #
78 # On output, the variable `<mostRecentFilepathBaseDir>` gives the file
79 # name with relative path to the file with the most recent timestamp over
80 # all directories.
81 #
82 # **Description:**
83 #
84 # This function uses the Linux/Unix command::
85 #
86 # $ find . -type f -printf '%T@ %p\n' \
87 # | grep -v "<re0>" | grep -v "<re1>" | ... \
88 # | sort -n | tail -1
89 #
90 # to return the most recent file in each listed directory ``<dir0>``,
91 # ``<dir1>``, etc. It then determines the most recently modified file over
92 # all of the directories and prints and returns in the variables
93 # ``<mostRecentTimestamp>``, ``<mostRecentFilepathBaseDir>``, and
94 # ``<mostRecentRelativeFilePath>``.
95 #
96 function(tribits_find_most_recent_file_timestamp)
97
98 if (TRIBITS_FIND_MOST_RECENT_FILE_TIMESTAMP_DEBUG_DUMP)
99 message("\nSearching for most modified files in base dirs:")
100 endif()
101
102 #
103 # A) Parse the input arguments
104 #
105
106 cmake_parse_arguments(
107 #prefix
108 PARSE
109 #options
110 "SHOW_MOST_RECENT_FILES;SHOW_OVERALL_MOST_RECENT_FILES"
111 #one_value_keywords
112 ""
113 #mulit_value_keywords
114 "BASE_DIRS;BASE_BASE_DIR;EXCLUDE_REGEXES;MOST_RECENT_TIMESTAMP_OUT;MOST_RECENT_FILEPATH_BASE_DIR_OUT;MOST_RECENT_RELATIVE_FILEPATH_OUT"
115 ${ARGN}
116 )
117
118 tribits_check_for_unparsed_arguments()
119
120 if (PARSE_SHOW_MOST_RECENT_FILES)
121 set(PARSE_SHOW_OVERALL_MOST_RECENT_FILE ON)
122 endif()
123
124 #
125 # B) Loop over each directory and find the most modified file
126 #
127
128 set(OVERALL_MOST_RECENT_TIMESTAMP "0000000000.0000000000")
129 set(OVERALL_MOST_RECENT_FILEPATH "")
130 set(OVERALL_MOST_RECENT_FILEPATH_DIR "")
131 set(OVERALL_MOST_RECENT_RELATEIVE_FILEPATH_DIR "")
132 set(OVERALL_MOST_RECENT_FILEPATH_TIMESTAMP_HUMAN_READABLE "")
133
134 foreach(BASE_DIR ${PARSE_BASE_DIRS})
135
136 if (TRIBITS_FIND_MOST_RECENT_FILE_TIMESTAMP_DEBUG_DUMP)
137 message("\nSearching '${BASE_DIR}' ...")
138 endif()
139
140 if (IS_DIRECTORY "${BASE_DIR}")
141
142 # Build up commands for grep -v
143 set(GREP_V_COMMANDS)
144 foreach(EXCLUDE_REGEX ${PARSE_EXCLUDE_REGEXES})
145 append_set(GREP_V_COMMANDS COMMAND grep -v "${EXCLUDE_REGEX}")
146 endforeach()
147
148 # Get the time stamp and the file name of the most recently modified file
149 # in current directory.
150 execute_process(
151 WORKING_DIRECTORY "${BASE_DIR}"
152 COMMAND find . -type f -printf "%T@ %p\n"
153 ${GREP_V_COMMANDS}
154 COMMAND sort -n
155 COMMAND tail -1
156 OUTPUT_VARIABLE MOST_RECENT_TIMESTAMP_AND_FILE
157 OUTPUT_STRIP_TRAILING_WHITESPACE
158 )
159 # Here, note that %T@ gives the modification time stamp in seconds since
160 # Jan. 1, 1970, 00:00 GMT. The -printf argument %p gives the file path.
161 # This results in the return a string with the modification date (in
162 # fractional seconds) and the file name of the form:
163 #
164 # 1407353359.5651538200 ./<relative-dir>/<some-file-name>
165
166 if (TRIBITS_FIND_MOST_RECENT_FILE_TIMESTAMP_DEBUG_DUMP)
167 print_var(MOST_RECENT_TIMESTAMP_AND_FILE)
168 endif()
169
170 if (MOST_RECENT_TIMESTAMP_AND_FILE)
171
172 split("${MOST_RECENT_TIMESTAMP_AND_FILE}" " "
173 MOST_RECENT_TIMESTAMP_AND_FILE_SPLIT)
174
175 # Get the time stamp part
176 list(GET MOST_RECENT_TIMESTAMP_AND_FILE_SPLIT 0
177 CURRENT_TIMESTAMP)
178
179 # Get the relative file path
180 list(GET MOST_RECENT_TIMESTAMP_AND_FILE_SPLIT 1
181 CURRENT_FILEPATH)
182
183 # Get the directory relative to the base base dir
184 string(REPLACE "${PARSE_BASE_BASE_DIR}/" "./" RELATIVE_FILEPATH_DIR
185 "${BASE_DIR}")
186
187 if (TRIBITS_FIND_MOST_RECENT_FILE_TIMESTAMP_DEBUG_DUMP)
188 print_var(CURRENT_TIMESTAMP)
189 print_var(CURRENT_FILEPATH)
190 endif()
191
192 if (PARSE_SHOW_MOST_RECENT_FILES)
193 tribits_get_human_readable_file_and_timestamp(
194 "${BASE_DIR}" "${CURRENT_FILEPATH}"
195 HUMAN_READABLE_FILE_AND_TIMESTAMP
196 )
197 message("-- " "Most recent file in ${RELATIVE_FILEPATH_DIR}/"
198 " is ${CURRENT_FILEPATH}\n"
199 " ${HUMAN_READABLE_FILE_AND_TIMESTAMP}")
200 endif()
201
202 if ("${CURRENT_TIMESTAMP}" GREATER "${OVERALL_MOST_RECENT_TIMESTAMP}")
203 if (TRIBITS_FIND_MOST_RECENT_FILE_TIMESTAMP_DEBUG_DUMP)
204 message(" New most recent file path!")
205 endif()
206 set(OVERALL_MOST_RECENT_TIMESTAMP "${CURRENT_TIMESTAMP}")
207 set(OVERALL_MOST_RECENT_RELATIVE_FILEPATH "${CURRENT_FILEPATH}")
208 set(OVERALL_MOST_RECENT_FILEPATH_DIR "${BASE_DIR}")
209 set(OVERALL_MOST_RECENT_RELATEIVE_FILEPATH_DIR "${RELATIVE_FILEPATH_DIR}")
210 if (PARSE_SHOW_OVERALL_MOST_RECENT_FILES)
211 set(OVERALL_MOST_RECENT_FILEPATH_TIMESTAMP_HUMAN_READABLE
212 "${HUMAN_READABLE_FILE_AND_TIMESTAMP}")
213 endif()
214 endif()
215
216 endif()
217
218 else()
219
220 if (TRIBITS_FIND_MOST_RECENT_FILE_TIMESTAMP_DEBUG_DUMP)
221 message("Directory does not exist, skipping ...")
222 endif()
223
224 endif()
225
226 endforeach()
227
228 if (TRIBITS_FIND_MOST_RECENT_FILE_TIMESTAMP_DEBUG_DUMP)
229 print_var(OVERALL_MOST_RECENT_TIMESTAMP)
230 print_var(OVERALL_MOST_RECENT_RELATIVE_FILEPATH)
231 endif()
232
233 if (PARSE_SHOW_OVERALL_MOST_RECENT_FILES)
234 if (OVERALL_MOST_RECENT_FILEPATH_DIR)
235 if (NOT OVERALL_MOST_RECENT_FILEPATH_TIMESTAMP_HUMAN_READABLE)
236 tribits_get_human_readable_file_and_timestamp(
237 "${OVERALL_MOST_RECENT_FILEPATH_DIR}"
238 "${OVERALL_MOST_RECENT_RELATIVE_FILEPATH}"
239 OVERALL_MOST_RECENT_FILEPATH_TIMESTAMP_HUMAN_READABLE
240 )
241 endif()
242 message("-- " "Overall most recent modified file is in"
243 " ${OVERALL_MOST_RECENT_RELATEIVE_FILEPATH_DIR}/ and is ${OVERALL_MOST_RECENT_RELATIVE_FILEPATH}\n"
244 " ${OVERALL_MOST_RECENT_FILEPATH_TIMESTAMP_HUMAN_READABLE}")
245 else()
246 message("-- There are no unfiltered files!")
247 endif()
248 endif()
249
250 set(${PARSE_MOST_RECENT_TIMESTAMP_OUT}
251 ${OVERALL_MOST_RECENT_TIMESTAMP}
252 PARENT_SCOPE)
253
254 if (PARSE_MOST_RECENT_FILEPATH_BASE_DIR_OUT)
255 set(${PARSE_MOST_RECENT_FILEPATH_BASE_DIR_OUT}
256 ${OVERALL_MOST_RECENT_FILEPATH_DIR}
257 PARENT_SCOPE)
258 endif()
259
260 if (PARSE_MOST_RECENT_RELATIVE_FILEPATH_OUT)
261 set(${PARSE_MOST_RECENT_RELATIVE_FILEPATH_OUT}
262 ${OVERALL_MOST_RECENT_RELATIVE_FILEPATH}
263 PARENT_SCOPE )
264 endif()
265
266 endfunction()
267
268
269 # @FUNCTION: tribits_find_most_recent_source_file_timestamp()
270 #
271 # Find the most modified source file in a set of base directories and return
272 # its timestamp.
273 #
274 # Usage::
275 #
276 # tribits_find_most_recent_source_file_timestamp(
277 # SOURCE_BASE_DIRS <dir0> <dir1> ...
278 # [SOURCE_BASE_BASE_DIR <dir>]
279 # [SHOW_MOST_RECENT_FILES]
280 # [SHOW_OVERALL_MOST_RECENT_FILE]
281 # [MOST_RECENT_TIMESTAMP_OUT <mostRecentTimestamp>]
282 # [MOST_RECENT_FILEPATH_BASE_DIR_OUT <mostRecentFilepathBaseDir>]
283 # [MOST_RECENT_RELATIVE_FILEPATH_OUT <mostRecentRelativeFilePath>]
284 # )
285 #
286 # This function just calls `tribits_find_most_recent_file_timestamp()`_
287 # passing in a set of basic exclude regexes like ``[.]git/``, ``[.]svn/``,
288 # etc. These types of version control files can not possibly directly impact
289 # the source code.
290 #
291 function(tribits_find_most_recent_source_file_timestamp)
292
293 #
294 # A) Parse the input arguments
295 #
296
297 cmake_parse_arguments(
298 #prefix
299 PARSE
300 #options
301 "SHOW_MOST_RECENT_FILES;SHOW_OVERALL_MOST_RECENT_FILES"
302 #one_value_keywords
303 ""
304 #multi_value_keywords
305 "SOURCE_BASE_DIRS;SOURCE_BASE_BASE_DIR;MOST_RECENT_TIMESTAMP_OUT;MOST_RECENT_FILEPATH_BASE_DIR_OUT;MOST_RECENT_RELATIVE_FILEPATH_OUT"
306 ${ARGN}
307 )
308
309 tribits_check_for_unparsed_arguments()
310
311 #
312 # B) Call the function tribits_find_most_recent_file_timestamp()
313 #
314
315 set(FILTER_OUT_SOURCE_FILE_REGEXS
316 "/[.]git/"
317 )
318
319 set(VARIABLE_ARGS)
320 if (PARSE_SHOW_MOST_RECENT_FILES)
321 append_set(VARIABLE_ARGS SHOW_MOST_RECENT_FILES)
322 endif()
323 if (PARSE_SHOW_OVERALL_MOST_RECENT_FILES)
324 append_set(VARIABLE_ARGS SHOW_OVERALL_MOST_RECENT_FILES)
325 endif()
326
327 #print_var(VARIABLE_ARGS)
328 tribits_find_most_recent_file_timestamp(
329 BASE_DIRS ${PARSE_SOURCE_BASE_DIRS}
330 BASE_BASE_DIR ${PARSE_SOURCE_BASE_BASE_DIR}
331 EXCLUDE_REGEXES ${FILTER_OUT_SOURCE_FILE_REGEXS}
332 MOST_RECENT_TIMESTAMP_OUT MOST_RECENT_TIMESTAMP
333 MOST_RECENT_FILEPATH_BASE_DIR_OUT MOST_RECENT_UPSTREAM_SOURCE_TIMESTAMP
334 MOST_RECENT_RELATIVE_FILEPATH_OUT MOST_RECENT_RELATIVE_FILEPATH
335 ${VARIABLE_ARGS}
336 )
337 #print_var(MOST_RECENT_TIMESTAMP)
338
339 set(${PARSE_MOST_RECENT_TIMESTAMP_OUT} ${MOST_RECENT_TIMESTAMP}
340 PARENT_SCOPE)
341
342 if (PARSE_MOST_RECENT_FILEPATH_BASE_DIR_OUT)
343 set(${PARSE_MOST_RECENT_FILEPATH_BASE_DIR_OUT} ${MOST_RECENT_UPSTREAM_SOURCE_TIMESTAMP}
344 PARENT_SCOPE)
345 endif()
346
347 if (PARSE_MOST_RECENT_RELATIVE_FILEPATH_OUT)
348 set(${PARSE_MOST_RECENT_RELATIVE_FILEPATH_OUT} ${MOST_RECENT_RELATIVE_FILEPATH}
349 PARENT_SCOPE )
350 endif()
351
352 endfunction()
353
354
355 # @FUNCTION: tribits_find_most_recent_binary_file_timestamp()
356 #
357 # Find the most modified binary file in a set of base directories and return
358 # its timestamp.
359 #
360 # Usage::
361 #
362 # tribits_find_most_recent_binary_file_timestamp(
363 # BINARY_BASE_DIRS <dir0> <dir1> ...
364 # [BINARY_BASE_BASE_DIR <dir>]
365 # [MOST_RECENT_TIMESTAMP_OUT <mostRecentTimestamp>]
366 # [MOST_RECENT_FILEPATH_BASE_DIR_OUT <mostRecentFilepathBaseDir>]
367 # [MOST_RECENT_RELATIVE_FILEPATH_OUT <mostRecentRelativeFilePath>]
368 # [SHOW_MOST_RECENT_FILES]
369 # [SHOW_OVERALL_MOST_RECENT_FILE]
370 # )
371 #
372 # This function just calls `tribits_find_most_recent_file_timestamp()`_
373 # passing in a set of basic exclude regexes like ``CMakeFiles/``,
374 # ``[.]cmake$``, and ``/Makefile$``, etc. These types of files usually don't
375 # impact the build of downstream software in CMake projects.
376 #
377 function(tribits_find_most_recent_binary_file_timestamp)
378
379 #
380 # A) Parse the input arguments
381 #
382
383 cmake_parse_arguments(
384 #prefix
385 PARSE
386 #options
387 "SHOW_MOST_RECENT_FILES;SHOW_OVERALL_MOST_RECENT_FILES"
388 #one_value_keywords
389 ""
390 #multi_value_keywords
391 "BINARY_BASE_DIRS;BINARY_BASE_BASE_DIR;MOST_RECENT_TIMESTAMP_OUT;MOST_RECENT_FILEPATH_BASE_DIR_OUT;MOST_RECENT_RELATIVE_FILEPATH_OUT"
392 ${ARGN}
393 )
394
395 tribits_check_for_unparsed_arguments()
396
397 #
398 # B) Define filters for binary files we know are not significant
399 #
400
401 set(FILTER_OUT_BINARY_FILE_REGEXS
402 "CMakeFiles/" "[.]cmake$" "/Makefile$"
403 )
404
405 #
406 # C) Call the function tribits_find_most_recent_file_timestamp()
407 #
408
409 set(VARIABLE_ARGS)
410 if (PARSE_SHOW_MOST_RECENT_FILES)
411 append_set(VARIABLE_ARGS SHOW_MOST_RECENT_FILES)
412 endif()
413 if (PARSE_SHOW_OVERALL_MOST_RECENT_FILES)
414 append_set(VARIABLE_ARGS SHOW_OVERALL_MOST_RECENT_FILES)
415 endif()
416
417 #print_var(VARIABLE_ARGS)
418 tribits_find_most_recent_file_timestamp(
419 BASE_DIRS ${PARSE_BINARY_BASE_DIRS}
420 BASE_BASE_DIR ${PARSE_BINARY_BASE_BASE_DIR}
421 EXCLUDE_REGEXES ${FILTER_OUT_BINARY_FILE_REGEXS}
422 MOST_RECENT_TIMESTAMP_OUT MOST_RECENT_TIMESTAMP
423 MOST_RECENT_RELATIVE_FILEPATH_OUT MOST_RECENT_RELATIVE_FILEPATH
424 ${VARIABLE_ARGS}
425 )
426 #print_var(MOST_RECENT_TIMESTAMP)
427
428 set(${PARSE_MOST_RECENT_TIMESTAMP_OUT} ${MOST_RECENT_TIMESTAMP}
429 PARENT_SCOPE)
430
431 if (PARSE_MOST_RECENT_FILEPATH_BASE_DIR_OUT)
432 set(${PARSE_MOST_RECENT_FILEPATH_BASE_DIR_OUT} ${MOST_RECENT_UPSTREAM_SOURCE_TIMESTAMP}
433 PARENT_SCOPE)
434 endif()
435
436 if (PARSE_MOST_RECENT_RELATIVE_FILEPATH_OUT)
437 set(${PARSE_MOST_RECENT_RELATIVE_FILEPATH_OUT} ${MOST_RECENT_RELATIVE_FILEPATH}
438 PARENT_SCOPE )
439 endif()
440
441 endfunction()
442
443
444 # @FUNCTION: tribits_determine_if_current_package_needs_rebuilt()
445 #
446 # Determine at configure time if any of the upstream dependencies for a
447 # package require the current package to be rebuilt.
448 #
449 # Usage::
450 #
451 # tribits_determine_if_current_package_needs_rebuilt(
452 # [SHOW_MOST_RECENT_FILES]
453 # [SHOW_OVERALL_MOST_RECENT_FILES]
454 # CURRENT_PACKAGE_OUT_OF_DATE_OUT <currentPackageOutOfDate>
455 # )
456 #
457 # **Arguments:**
458 #
459 # ``SHOW_MOST_RECENT_FILES``
460 #
461 # If specified, then the most recently modified file for each individual
462 # base source and binary directory searched will be will be printed the
463 # STDOUT. Setting this implies ``SHOW_OVERALL_MOST_RECENT_FILE``.
464 #
465 # ``SHOW_OVERALL_MOST_RECENT_FILE``
466 #
467 # If specified, then only the most recent modified file over all of the
468 # individual directories for each category (i.e. one for upstream package
469 # source dirs, one for upstream package binary dirs, one for the package's
470 # source dir, and one for the package's own binary dir) is printed to
471 # STDOUT.
472 #
473 # ``CURRENT_PACKAGE_OUT_OF_DATE_OUT <currentPackageOutOfDate>``
474 #
475 # On output, the local variable ``<currentPackageOutOfDate>`` will be set
476 # to ``TRUE`` if any of the upstream most modified files are more recent
477 # than the most modified file in the package's binary directory.
478 # Otherwise, this variable is set to ``FALSE``.
479 #
480 # **Description:**
481 #
482 # This function is designed to help take an externally configured and built
483 # piece of software (that generates libraries) and wrap it as a TriBITS
484 # package or subpackage. This function uses the lower-level functions:
485 #
486 # * `tribits_find_most_recent_source_file_timestamp()`_
487 # * `tribits_find_most_recent_binary_file_timestamp()`_
488 #
489 # to determine the most recent modified files in the upstream TriBITS
490 # packages' source and binary directories as well as the most recent source
491 # file for the current package. It then compares these timestamps to the most
492 # recent binary file timestamp in this package's binary directory. If any of
493 # these three files are more recent than this package's most recent binary
494 # file, then the output variable ``<currentPackageOutOfDate>`` is set to
495 # ``TRUE``. Otherwise, it is set to ``FALSE``.
496 #
497 # NOTE: The source and binary directories for full packages are searched, not
498 # individual subpackage dirs. This is to reduce the number of dirs searched.
499 # This will, however, result in changes in non-dependent subpackages being
500 # considered as well.
501 #
502 # See the demonstration of the usage of this function in the ``WrapExternal``
503 # package in `TribitsExampleProject`_.
504 #
505 function(tribits_determine_if_current_package_needs_rebuilt)
506
507 tribits_config_code_start_timer(TIMER_START_SECONDS)
508
509 #
510 # A) Parse the input arguments
511 #
512
513 cmake_parse_arguments(
514 #prefix
515 PARSE
516 #options
517 "SHOW_MOST_RECENT_FILES;SHOW_OVERALL_MOST_RECENT_FILES"
518 #one_value_keywords
519 ""
520 #mulit_value_keywords
521 "CURRENT_PACKAGE_OUT_OF_DATE_OUT"
522 ${ARGN}
523 )
524
525 tribits_check_for_unparsed_arguments()
526
527 # Get pass through print level options
528 set(SHOW_MOST_RECENT_FILES_ARGS)
529 if (PARSE_SHOW_MOST_RECENT_FILES)
530 append_set(SHOW_MOST_RECENT_FILES_ARGS SHOW_MOST_RECENT_FILES)
531 endif()
532 if (PARSE_SHOW_OVERALL_MOST_RECENT_FILES)
533 append_set(SHOW_MOST_RECENT_FILES_ARGS SHOW_OVERALL_MOST_RECENT_FILES)
534 endif()
535 #print_var(SHOW_MOST_RECENT_FILES_ARGS)
536
537 if (PARSE_SHOW_MOST_RECENT_FILES)
538 set(PARSE_SHOW_OVERALL_MOST_RECENT_FILES TRUE)
539 endif()
540
541 #
542 # B) Get the list of enabled upstream packages
543 #
544
545 # Only search parent packages to cut down on dirs searched
546 set(ENABLED_UPSTREAM_PACKAGES)
547 set(CURRENT_PARENT_PACKAGE)
548 foreach(upstreamPackage ${${PACKAGE_NAME}_FULL_ENABLED_DEP_PACKAGES})
549 # Assume we will append
550 set(APPEND_PACKAGE ${upstreamPackage})
551 # If is a subpackage we only append the parent packages
552 set(PARENT_PACKAGE ${${upstreamPackage}_PARENT_PACKAGE})
553 if (PARENT_PACKAGE)
554 set(APPEND_PACKAGE ${PARENT_PACKAGE})
555 endif()
556 # Append
557 append_set(ENABLED_UPSTREAM_PACKAGES ${APPEND_PACKAGE})
558 endforeach()
559 list(REMOVE_DUPLICATES ENABLED_UPSTREAM_PACKAGES)
560 #print_var(ENABLED_UPSTREAM_PACKAGES)
561
562 #
563 # C) Determine the most recent files on the upstream packages
564 #
565
566 if (PARSE_SHOW_OVERALL_MOST_RECENT_FILES)
567 message("\nDetermining most recent source file in upstream packages"
568 " from ${PACKAGE_NAME}:")
569 endif()
570 set(UPSTREAM_SOURCE_BASE_DIRS)
571 foreach(UPSTREAM_PACKAGE ${ENABLED_UPSTREAM_PACKAGES})
572 append_set(UPSTREAM_SOURCE_BASE_DIRS "${${UPSTREAM_PACKAGE}_SOURCE_DIR}")
573 endforeach()
574 tribits_find_most_recent_source_file_timestamp(
575 SOURCE_BASE_DIRS ${UPSTREAM_SOURCE_BASE_DIRS}
576 SOURCE_BASE_BASE_DIR "${PROJECT_SOURCE_DIR}"
577 ${SHOW_MOST_RECENT_FILES_ARGS}
578 MOST_RECENT_TIMESTAMP_OUT MOST_RECENT_UPSTREAM_SOURCE_TIMESTAMP
579 MOST_RECENT_RELATIVE_FILEPATH_OUT MOST_RECENT_UPSTREAM_SOURCE_FILEPATH
580 )
581 #print_var(MOST_RECENT_UPSTREAM_SOURCE_FILEPATH)
582
583 if (PARSE_SHOW_OVERALL_MOST_RECENT_FILES)
584 message("\nDetermining most recent binary file in upstream packages"
585 " from ${PACKAGE_NAME}:")
586 endif()
587 set(UPSTREAM_BINARY_BASE_DIRS)
588 foreach(UPSTREAM_PACKAGE ${ENABLED_UPSTREAM_PACKAGES})
589 append_set(UPSTREAM_BINARY_BASE_DIRS "${${UPSTREAM_PACKAGE}_BINARY_DIR}")
590 endforeach()
591 tribits_find_most_recent_binary_file_timestamp(
592 BINARY_BASE_DIRS ${UPSTREAM_BINARY_BASE_DIRS}
593 BINARY_BASE_BASE_DIR "${PROJECT_BINARY_DIR}"
594 ${SHOW_MOST_RECENT_FILES_ARGS}
595 MOST_RECENT_TIMESTAMP_OUT MOST_RECENT_UPSTREAM_BINARY_TIMESTAMP
596 MOST_RECENT_RELATIVE_FILEPATH_OUT MOST_RECENT_UPSTREAM_BINARY_FILEPATH
597 )
598 #print_var(MOST_RECENT_UPSTREAM_BINARY_FILEPATH)
599
600 #
601 # D) Determine the most recent files for the current package
602 #
603
604 if (PARSE_SHOW_OVERALL_MOST_RECENT_FILES)
605 message("\nDetermining most recent source file for current"
606 " package ${PACKAGE_NAME}:")
607 endif()
608 tribits_find_most_recent_source_file_timestamp(
609 SOURCE_BASE_DIRS ${${PACKAGE_NAME}_SOURCE_DIR}
610 SOURCE_BASE_BASE_DIR "${PROJECT_SOURCE_DIR}"
611 ${SHOW_MOST_RECENT_FILES_ARGS}
612 MOST_RECENT_TIMESTAMP_OUT MOST_RECENT_THIS_PACKAGE_SOURCE_TIMESTAMP
613 MOST_RECENT_RELATIVE_FILEPATH_OUT MOST_RECENT_THIS_SOURCE_FILEPATH
614 )
615
616 if (PARSE_SHOW_OVERALL_MOST_RECENT_FILES)
617 message("\nDetermining most recent binary file for current"
618 " package ${PACKAGE_NAME}:")
619 endif()
620 tribits_find_most_recent_binary_file_timestamp(
621 BINARY_BASE_DIRS ${${PACKAGE_NAME}_BINARY_DIR}
622 BINARY_BASE_BASE_DIR "${PROJECT_BINARY_DIR}"
623 ${SHOW_MOST_RECENT_FILES_ARGS}
624 MOST_RECENT_TIMESTAMP_OUT MOST_RECENT_THIS_PACKAGE_BINARY_TIMESTAMP
625 MOST_RECENT_RELATIVE_FILEPATH_OUT MOST_RECENT_THIS_BINARY_FILEPATH
626 )
627
628 #
629 # E) Compare most recent file time stamps to determine if a rebuild is needed
630 #
631
632 set(CURRENT_PACKAGE_OUT_OF_DATE_OUT FALSE)
633
634 message("\nComparing timestamps of recently updated files:")
635
636 if (MOST_RECENT_THIS_BINARY_FILEPATH)
637
638 tribits_update_package_out_of_date(
639 "upstream package source" ${MOST_RECENT_UPSTREAM_SOURCE_TIMESTAMP}
640 "${MOST_RECENT_UPSTREAM_SOURCE_FILEPATH}"
641 ${MOST_RECENT_THIS_PACKAGE_BINARY_TIMESTAMP} "${MOST_RECENT_THIS_BINARY_FILEPATH}"
642 CURRENT_PACKAGE_OUT_OF_DATE_OUT )
643
644 tribits_update_package_out_of_date(
645 "upstream package binary" ${MOST_RECENT_UPSTREAM_BINARY_TIMESTAMP}
646 "${MOST_RECENT_UPSTREAM_BINARY_FILEPATH}"
647 ${MOST_RECENT_THIS_PACKAGE_BINARY_TIMESTAMP} "${MOST_RECENT_THIS_BINARY_FILEPATH}"
648 CURRENT_PACKAGE_OUT_OF_DATE_OUT )
649
650 tribits_update_package_out_of_date(
651 "this package's source" ${MOST_RECENT_THIS_PACKAGE_SOURCE_TIMESTAMP}
652 "${MOST_RECENT_THIS_SOURCE_FILEPATH}"
653 ${MOST_RECENT_THIS_PACKAGE_BINARY_TIMESTAMP} "${MOST_RECENT_THIS_BINARY_FILEPATH}"
654 CURRENT_PACKAGE_OUT_OF_DATE_OUT )
655
656 if (NOT CURRENT_PACKAGE_OUT_OF_DATE_OUT)
657 message("-- This package's most recent binary file"
658 " ${MOST_RECENT_THIS_BINARY_FILEPATH}"
659 " is more recent than its upstream package source or binary files"
660 " or this package's source files!")
661 endif()
662
663 else()
664
665 message("-- This package has no unfiltered binary files so consider out of date!")
666
667 endif()
668
669 set(${PARSE_CURRENT_PACKAGE_OUT_OF_DATE_OUT} ${CURRENT_PACKAGE_OUT_OF_DATE_OUT}
670 PARENT_SCOPE)
671
672 tribits_config_code_stop_timer(TIMER_START_SECONDS
673 "\nTotal time to check for most recent modified files")
674
675 endfunction()
676
677
678 #
679 # Utility functions
680 #
681
682
683 function(tribits_update_package_out_of_date
684 DEPENDENCY_TYPE_STRING DEP_FILE_TIMESTAMP DEP_FILEPATH
685 THIS_BINARY_FILE_TIMESTAMP THIS_BINARY_FILEPATH
686 CURRENT_PACKAGE_IS_OUT_OF_DATE_INOUT
687 )
688 if ("${DEP_FILE_TIMESTAMP}" GREATER "${THIS_BINARY_FILE_TIMESTAMP}")
689 message("-- The ${DEPENDENCY_TYPE_STRING} file ${DEP_FILEPATH} is more recent than"
690 " this package's binary file ${THIS_BINARY_FILEPATH}!")
691 set(${CURRENT_PACKAGE_IS_OUT_OF_DATE_INOUT} TRUE PARENT_SCOPE)
692 endif()
693 endfunction()
694
695
696 function(tribits_get_human_readable_file_and_timestamp
697 BASE_DIR CURRENT_FILEPATH
698 HUMAN_READABLE_FILE_AND_TIMESTAMP_OUT
699 )
700 execute_process(
701 WORKING_DIRECTORY "${BASE_DIR}"
702 COMMAND ls --full-time "${CURRENT_FILEPATH}"
703 OUTPUT_STRIP_TRAILING_WHITESPACE
704 OUTPUT_VARIABLE HUMAN_READABLE_FILE_AND_TIMESTAMP
705 )
706 set(${HUMAN_READABLE_FILE_AND_TIMESTAMP_OUT}
707 ${HUMAN_READABLE_FILE_AND_TIMESTAMP}
708 PARENT_SCOPE)
709 endfunction()
710
711
712
713
714
715 # LocalWords: ENDFOREACH subpackage subpackages TriBITS timestamp