summaryrefslogtreecommitdiffstats
path: root/Tests/CMakeTests/CheckSourceTreeTest.cmake.in
blob: cd1934b33ec8dc39cf530de92819902e5870687d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# Check the CMake source tree and report anything suspicious...
#
message("=============================================================================")
message("CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
message("")
message("CMake_SOURCE_DIR='${CMake_SOURCE_DIR}'")
message("CVS_EXECUTABLE='${CVS_EXECUTABLE}'")
message("ENV{DASHBOARD_TEST_FROM_CTEST}='$ENV{DASHBOARD_TEST_FROM_CTEST}'")
message("")


# Check with "cvs -q -n up -dP" if there are any local modifications to the
# CMake source tree:
#
message("=============================================================================")
message("Copy/paste this command to reproduce:")
message("cd \"${CMake_SOURCE_DIR}\" && \"${CVS_EXECUTABLE}\" -q -n up -dP")
message("")
execute_process(COMMAND ${CVS_EXECUTABLE} -q -n up -dP
  WORKING_DIRECTORY ${CMake_SOURCE_DIR}
  OUTPUT_VARIABLE ov
  ERROR_VARIABLE ev
  RESULT_VARIABLE rv)

message("Results of running '${CVS_EXECUTABLE} -q -n up -dP'")
message("rv='${rv}'")
message("ov='${ov}'")
message("ev='${ev}'")
message("")

# Analyze cvs output:
#
set(additions 0)
set(conflicts 0)
set(modifications 0)
set(nonadditions 0)

if(NOT ov STREQUAL "")
  string(REPLACE ";" "\\\\;" lines "${ov}")
  string(REPLACE "\n" "E;" lines "${lines}")

  foreach(line ${lines})
    message("'${line}'")

    # But do not consider files that exist just because some user poked around
    # the file system with Windows Explorer or with the Finder from a Mac...
    # ('Thumbs.db' and '.DS_Store' files...)
    #
    set(consider 1)
    set(ignore_files_regex "^(. |.*(/|\\\\))(\\.DS_Store|Thumbs.db)E$")
    if(line MATCHES "${ignore_files_regex}")
      message("   line matches '${ignore_files_regex}' -- not considered")
      set(consider 0)
    endif()

    if(consider)
      if(line MATCHES "^A ")
        message("   locally added file/directory detected...")
        set(additions 1)
      endif()

      if(line MATCHES "^C ")
        message("   conflict detected...")
        set(conflicts 1)
      endif()

      if(line MATCHES "^M ")
        message("   locally modified file detected...")
        set(modifications 1)
      endif()

      if(line MATCHES "^\\? ")
        message("   locally non-added file/directory detected...")
        set(nonadditions 1)
      endif()
    endif()
  endforeach()
endif()

message("=============================================================================")
message("additions='${additions}'")
message("conflicts='${conflicts}'")
message("modifications='${modifications}'")
message("nonadditions='${nonadditions}'")
message("")


# Decide if the test passes or fails:
#
message("=============================================================================")

if("$ENV{DASHBOARD_TEST_FROM_CTEST}" STREQUAL "")

  # developers are allowed to have local additions and modifications...
  message("interactive test run")
  message("")

else()

  message("dashboard test run")
  message("")

  # but dashboard machines are not allowed to have local additions or modifications...
  if(additions)
    message(FATAL_ERROR "test fails: local source tree additions")
  endif()

  if(modifications)
    message(FATAL_ERROR "test fails: local source tree modifications")
  endif()

  #
  # It's a dashboard run if ctest was run with '-D ExperimentalTest' or some other
  # -D arg on its command line or if ctest is running a -S script to run a dashboard...
  # Running ctest like that causes the DASHBOARD_TEST_FROM_CTEST env var to be set.
  #

endif()


# ...and nobody is allowed to have local non-additions or conflicts...
# Not even developers.
#
if(nonadditions)
  message(FATAL_ERROR "test fails: local source tree non-additions: use cvs add before committing, or remove the files from the source tree")
endif()

if(conflicts)
  message(FATAL_ERROR "test fails: local source tree conflicts: resolve before committing")
endif()


# Still here? Good then...
#
message("test passes")
message("")