Browse code

More code to figure out when to run what. Still need some code, that at the end of a refresh says: fetch needed or rebuild needed.

Nat! authored on 29-09-2016 14:51:40
Showing 5 changed files
... ...
@@ -40,7 +40,7 @@ project tree
40 40
 * improved comments in repositories` and `embedded_repositories` templates
41 41
 * pass ADDICTIONS_DIR to build systems
42 42
 * improve optimistic support, by memorizing if a fetch, refresh, build went
43
-thru successfully
43
+thru successfully. The automatic refresh should run much less often now.
44 44
 
45 45
 ### Cmake
46 46
 
... ...
@@ -127,19 +127,24 @@ bootstrap_nomagic_main()
127 127
 
128 128
    warn_scripts_main "${BOOTSTRAP_SUBDIR}" || exit 1
129 129
 
130
-   if [ -z "${DONT_RECURSE}" ]
130
+   if fetch_needed
131 131
    then
132
-      fetch_main "$@" || exit 1
133
-      refresh_main    || exit 1
134
-   else
135
-      fetch_main --non-recursive "$@" || exit 1
136
-      refresh_main nonrecursive       || exit 1
132
+      if [ -z "${DONT_RECURSE}" ]
133
+      then
134
+         fetch_main "$@" || exit 1
135
+         refresh_main    || exit 1
136
+      else
137
+         fetch_main --non-recursive "$@" || exit 1
138
+         refresh_main nonrecursive       || exit 1
139
+      fi
140
+      # used for option handling only
141
+      MULLE_BOOTSTRAP_DID_FETCH="YES"
137 142
    fi
138 143
 
139
-   # used for option handling only
140
-   MULLE_BOOTSTRAP_DID_FETCH="YES"
141
-
142
-   build_main "$@" || exit 1
144
+   if build_needed
145
+   then
146
+      build_main "$@" || exit 1
147
+   fi
143 148
 }
144 149
 
145 150
 
... ...
@@ -168,7 +173,6 @@ bootstrap_main()
168 173
       ;;
169 174
    esac
170 175
 
171
-
172 176
    MULLE_BOOTSTRAP_PID="$$"
173 177
    export MULLE_BOOTSTRAP_PID
174 178
 
... ...
@@ -202,6 +206,9 @@ bootstrap_main()
202 206
             MULLE_BOOTSTRAP_DIRTY_HARRY="NO"
203 207
          ;;
204 208
 
209
+         -fr|--force-refresh)
210
+            MULLE_BOOTSTRAP_NEEDS_REFRESH="YES"
211
+         ;;
205 212
          -n|--dry-run)
206 213
             MULLE_EXECUTOR_DRY_RUN="YES"
207 214
          ;;
... ...
@@ -293,7 +300,7 @@ bootstrap_main()
293 300
          then
294 301
             MULLE_BOOTSTRAP_VERBOSE_BUILD="NO"
295 302
          fi
296
-         ;;
303
+      ;;
297 304
 
298 305
       FLUFF)
299 306
          MULLE_BOOTSTRAP_FLUFF="YES"
... ...
@@ -303,7 +310,7 @@ bootstrap_main()
303 310
          then
304 311
             MULLE_BOOTSTRAP_VERBOSE_BUILD="NO"
305 312
          fi
306
-         ;;
313
+      ;;
307 314
 
308 315
       TRACE)
309 316
          MULLE_BOOTSTRAP_TRACE_SETTINGS="YES"
... ...
@@ -315,7 +322,7 @@ bootstrap_main()
315 322
             MULLE_BOOTSTRAP_VERBOSE_BUILD="NO"
316 323
          fi
317 324
          log_trace "FULL trace started"
318
-         ;;
325
+      ;;
319 326
 
320 327
       1848)
321 328
          MULLE_BOOTSTRAP_TRACE_SETTINGS="NO"
... ...
@@ -328,7 +335,7 @@ bootstrap_main()
328 335
          fi
329 336
          log_trace "1848 trace (set -x) started"
330 337
          set -x
331
-         ;;
338
+      ;;
332 339
    esac
333 340
 
334 341
    if [ "${MULLE_EXECUTOR_DRY_RUN}" = "YES" ]
... ...
@@ -362,20 +369,11 @@ bootstrap_main()
362 369
       esac
363 370
    fi
364 371
 
365
-   local do_refresh
366
-
367
-   do_refresh="YES"
368
-
369
-   if [ "${MULLE_BOOTSTRAP_OPTIMISTIC}" = "YES" ]
370
-   then
371
-      if [ -e "${CLONESFETCH_SUBDIR}/.refresh_done" ]
372
-      then
373
-         do_refresh="NO"
374
-      fi
375
-   fi
376
-
377
-   # some commands refresh before execution
378
-   if [ "${do_refresh}" = "YES" ]
372
+   #
373
+   # some commands should refresh before execution
374
+   # try to avoid pulling in the header if not needed
375
+   #
376
+   if [ "${MULLE_BOOTSTRAP_NEEDS_REFRESH}" = "YES" ] || refresh_needed
379 377
    then
380 378
       case "${command}" in
381 379
          bootstrap|nomagic|fetch)
... ...
@@ -456,13 +454,17 @@ bootstrap_main()
456 454
       ;;
457 455
 
458 456
       refresh)
457
+         [ -z "${MULLE_BOOTSTRAP_REFRESH_SH}" ] && . mulle-bootstrap-refresh.sh
458
+
459 459
          refresh_main "$@" || exit 1
460 460
       ;;
461 461
 
462
-      update)
462
+      update|pull)
463 463
          . mulle-bootstrap-fetch.sh
464 464
 
465 465
          update_main "$@" || exit 1
466
+
467
+         [ -z "${MULLE_BOOTSTRAP_REFRESH_SH}" ] && . mulle-bootstrap-refresh.sh
466 468
          refresh_main || exit 1
467 469
       ;;
468 470
 
... ...
@@ -1372,6 +1372,7 @@ _common_main()
1372 1372
    [ -z "${MULLE_BOOTSTRAP_WARN_SCRIPTS_SH}" ] && . mulle-bootstrap-warn-scripts.sh
1373 1373
    [ -z "${MULLE_BOOTSTRAP_AUTO_UPDATE_SH}" ]  && . mulle-bootstrap-auto-update.sh
1374 1374
    [ -z "${MULLE_BOOTSTRAP_REPOSITORIES_SH}" ] && . mulle-bootstrap-repositories.sh
1375
+   [ -z "${MULLE_BOOTSTRAP_REFRESH_SH}" ]      && . mulle-bootstrap-refresh.sh
1375 1376
 
1376 1377
    #
1377 1378
    # should we check for '/usr/local/include/<name>' and don't fetch if
... ...
@@ -1436,7 +1437,6 @@ _common_main()
1436 1437
    fetch__run_fetch_settings_script "post-${COMMAND}" "$@"
1437 1438
 
1438 1439
    remove_file_if_present "${CLONESFETCH_SUBDIR}/.fetch_update_started"
1439
-   create_file_if_missing "${CLONESFETCH_SUBDIR}/.fetch_done"
1440 1440
 
1441 1441
    if read_yes_no_config_setting "update_gitignore" "YES"
1442 1442
    then
... ...
@@ -1449,6 +1449,14 @@ _common_main()
1449 1449
          append_dir_to_gitignore_if_needed "${CLONES_SUBDIR}"
1450 1450
       fi
1451 1451
    fi
1452
+
1453
+   refresh_main || exit 1
1454
+
1455
+   #
1456
+   # if fetch_done is older than refresh_done, we know we should
1457
+   # fetch again
1458
+   #
1459
+   create_file_if_missing "${CLONESFETCH_SUBDIR}/.fetch_done"
1452 1460
 }
1453 1461
 
1454 1462
 
... ...
@@ -83,6 +83,85 @@ get_core_count()
83 83
 }
84 84
 
85 85
 
86
+# figure out if we need to run refresh
87
+build_needed()
88
+{
89
+   if [ ! -f "${CLONESFETCH_SUBDIR}/.build_done" ]
90
+   then
91
+      log_fluff "Need build because ${CLONESFETCH_SUBDIR}/.build_done does not exist."
92
+      return 0
93
+   fi
94
+
95
+   if [ "${CLONESFETCH_SUBDIR}/.build_done" -ot "${CLONESFETCH_SUBDIR}/.refresh_done" ]
96
+   then
97
+      log_fluff "Need build because \"${CLONESFETCH_SUBDIR}/.build_done\" is older than \"${CLONESFETCH_SUBDIR}/.refresh_done\""
98
+      return 0
99
+   fi
100
+
101
+   return 1
102
+}
103
+
104
+
105
+fetch_needed()
106
+{
107
+   if [ ! -f "${CLONESFETCH_SUBDIR}/.fetch_done" ]
108
+   then
109
+      log_fluff "Need fetch because ${CLONESFETCH_SUBDIR}/.fetch_done does not exist."
110
+      return 0
111
+   fi
112
+
113
+   if [ "${CLONESFETCH_SUBDIR}/.fetch_done" -ot "${CLONESFETCH_SUBDIR}/.refresh_done" ]
114
+   then
115
+      log_fluff "Need fetch because \"${CLONESFETCH_SUBDIR}/.fetch_done\" is older than \"${CLONESFETCH_SUBDIR}/.refresh_done\""
116
+      return 0
117
+   fi
118
+
119
+   return 1
120
+}
121
+
122
+
123
+refresh_needed()
124
+{
125
+   if [ ! -d "${BOOTSTRAP_SUBDIR}.auto" ]
126
+   then
127
+     log_fluff "Need refresh because ${BOOTSTRAP_SUBDIR}.auto does not exist."
128
+     return 0
129
+   fi
130
+
131
+   if [ ! -f "${CLONESFETCH_SUBDIR}/.refresh_done" ]
132
+   then
133
+      log_fluff "Need refresh because ${CLONESFETCH_SUBDIR}/.refresh_done does not exist."
134
+      return 0
135
+   fi
136
+
137
+   if [ "${CLONESFETCH_SUBDIR}/.refresh_done" -ot "${BOOTSTRAP_SUBDIR}/embedded_repositories" ]
138
+   then
139
+      log_fluff "Need refresh because \"${BOOTSTRAP_SUBDIR}/embedded_repositories\" is modified"
140
+      return 0
141
+   fi
142
+
143
+   if [ "${CLONESFETCH_SUBDIR}/.refresh_done" -ot "${BOOTSTRAP_SUBDIR}/repositories" ]
144
+   then
145
+      log_fluff "Need refresh because \"${BOOTSTRAP_SUBDIR}/repositories\" is modified"
146
+      return 0
147
+   fi
148
+
149
+   if [ "${CLONESFETCH_SUBDIR}/.refresh_done" -ot "${BOOTSTRAP_SUBDIR}.local/embedded_repositories" ]
150
+   then
151
+      log_fluff "Need refresh because \"${BOOTSTRAP_SUBDIR}.local/embedded_repositories\" is modified"
152
+      return 0
153
+   fi
154
+
155
+   if [ "${CLONESFETCH_SUBDIR}/.refresh_done" -ot "${BOOTSTRAP_SUBDIR}.local/repositories" ]
156
+   then
157
+      log_fluff "Need refresh because \"${BOOTSTRAP_SUBDIR}.local/repositories\" is modified"
158
+      return 0
159
+   fi
160
+
161
+   return 1
162
+}
163
+
164
+
86 165
 local_environment_initialize()
87 166
 {
88 167
    #
... ...
@@ -531,23 +531,25 @@ refresh_embedded_repositories()
531 531
 
532 532
 refresh_deeply_embedded_repositories()
533 533
 {
534
-   local branch
535 534
    local clone
536 535
    local clones
537 536
    local dstprefix
538
-   local name
539 537
    local old
540 538
    local previous_bootstrap
541 539
    local previous_clones
542
-   local scm
543
-   local subdir
544
-   local tag
545
-   local url
546 540
 
547 541
    MULLE_BOOTSTRAP_SETTINGS_NO_AUTO="YES"
548 542
 
549 543
    old="${IFS:-" "}"
550 544
 
545
+   # __parse_embedded_clone
546
+   local name
547
+   local url
548
+   local branch
549
+   local scm
550
+   local tag
551
+   local subdir
552
+
551 553
    clones="`read_fetch_setting "repositories"`"
552 554
    if [ "${clones}" != "" ]
553 555
    then
... ...
@@ -584,9 +586,9 @@ refresh_deeply_embedded_repositories()
584 586
 }
585 587
 
586 588
 
587
-
588 589
 # -------------------
589
-
590
+# TODO: check that refresh actually changed something in repositoires or
591
+#       embedded repositories and refetch as needed
590 592
 refresh_main()
591 593
 {
592 594
    log_fluff "::: refresh begin :::"