Browse code

Add clone_cache setting to also cache git clones, which can be useful.

Nat! authored on 16/03/2017 21:43:47
Showing 6 changed files
... ...
@@ -72,12 +72,12 @@ fetch_brew_if_needed()
72 72
    case "${UNAME}" in
73 73
       darwin)
74 74
          log_info "Installing OS X brew"
75
-         exekutor git clone https://github.com/Homebrew/brew.git "${ADDICTIONS_DIR}"
75
+         _git_clone https://github.com/Homebrew/brew.git "${ADDICTIONS_DIR}"
76 76
       ;;
77 77
 
78 78
       linux)
79 79
          log_info "Installing Linux brew"
80
-         exekutor git clone https://github.com/Linuxbrew/brew.git "${ADDICTIONS_DIR}"
80
+         _git_clone https://github.com/Linuxbrew/brew.git "${ADDICTIONS_DIR}"
81 81
        ;;
82 82
 
83 83
       *)
... ...
@@ -90,6 +90,14 @@ fetch_brew_if_needed()
90 90
       fail "brew was not successfully installed (PATH=$PATH)"
91 91
    fi
92 92
 
93
+   #
94
+   # if brew is from clone cache update it
95
+   #
96
+   if [ ! -z "${CLONE_CACHE}" ]
97
+   then
98
+      "${BREW}" update
99
+   fi
100
+
93 101
    return 1
94 102
 }
95 103
 
... ...
@@ -2371,7 +2371,6 @@ build_main()
2371 2371
    [ -z "${MULLE_BOOTSTRAP_REPOSITORIES_SH}" ] && . mulle-bootstrap-repositories.sh
2372 2372
    [ -z "${MULLE_BOOTSTRAP_SCRIPTS_SH}" ] && . mulle-bootstrap-scripts.sh
2373 2373
 
2374
-
2375 2374
    #
2376 2375
    #
2377 2376
    #
... ...
@@ -2409,6 +2408,8 @@ build_main()
2409 2409
       write_protect_directory "${DEPENDENCIES_DIR}"
2410 2410
    else
2411 2411
       log_fluff "No dependencies have been generated"
2412
+
2413
+      remove_file_if_present "${REPOS_DIR}/.build_done"
2412 2414
    fi
2413 2415
 
2414 2416
    log_debug "::: build end :::"
... ...
@@ -311,25 +311,26 @@ search_for_git_repository_in_caches()
311 311
    do
312 312
       IFS="${DEFAULT_IFS}"
313 313
 
314
-      realdir="`realpath "${directory}"`"
315
-      if [ ! -z "${realdir}" ]
314
+      if [ ! -d "${directory}" ]
316 315
       then
317
-         if [ "${realdir}" = "${curdir}" ]
318
-         then
319
-            fail "config setting \"caches_path\" mistakenly contains \"${directory}\", which is the current directory"
320
-         fi
321
-
322
-         found="`_search_for_git_repository_in_cache "${realdir}" "$@"`" || exit 1
323
-         if [ ! -z "${found}" ]
324
-         then
325
-            symlink_relpath "${found}" "${ROOT_DIR}"
326
-            return
327
-         fi
328
-      else
329 316
          if [ "${MULLE_FLAG_LOG_CACHE}" = "YES" ]
330 317
          then
331 318
             log_trace2 "Cache path \"${realdir}\" does not exist"
332 319
          fi
320
+         continue
321
+      fi
322
+
323
+      realdir="`realpath "${directory}"`"
324
+      if [ "${realdir}" = "${curdir}" ]
325
+      then
326
+         fail "config setting \"caches_path\" mistakenly contains \"${directory}\", which is the current directory"
327
+      fi
328
+
329
+      found="`_search_for_git_repository_in_cache "${realdir}" "$@"`" || exit 1
330
+      if [ ! -z "${found}" ]
331
+      then
332
+         symlink_relpath "${found}" "${ROOT_DIR}"
333
+         return
333 334
       fi
334 335
    done
335 336
 
... ...
@@ -1591,6 +1592,7 @@ _common_main()
1591 1591
 
1592 1592
    local ROOT_DIR="`pwd -P`"
1593 1593
    local CACHES_PATH
1594
+   local CLONE_CACHE
1594 1595
 
1595 1596
    #
1596 1597
    # where we look for symlink sources
... ...
@@ -1600,6 +1602,10 @@ _common_main()
1600 1600
    # this can be multiple paths!
1601 1601
    CACHES_PATH="`read_config_setting "caches_path" "${MULLE_BOOTSTRAP_CACHES_PATH}"`"
1602 1602
 
1603
+   # stuff clones get intermediate saved too, default empty
1604
+   CLONE_CACHE="`read_config_setting "clone_cache"`"
1605
+   CACHES_PATH="`add_path "${CACHES_PATH}" "${CLONE_CACHE}"`"
1606
+
1603 1607
    OPTION_CHECK_USR_LOCAL_INCLUDE="`read_config_setting "check_usr_local_include" "NO"`"
1604 1608
    OVERRIDE_BRANCH="`read_config_setting "override_branch"`"
1605 1609
 
... ...
@@ -1163,7 +1163,7 @@ _create_file_if_missing()
1163 1163
    fi
1164 1164
 
1165 1165
    log_fluff "Creating \"${path}\""
1166
-   if [ -z "$*" ]
1166
+   if [ ! -z "$*" ]
1167 1167
    then
1168 1168
       redirect_exekutor "${path}" echo "$*" || fail "failed to create \"{path}\""
1169 1169
    else
... ...
@@ -184,17 +184,13 @@ git_checkout()
184 184
 }
185 185
 
186 186
 
187
-git_clone()
187
+_git_clone()
188 188
 {
189
-   [ $# -ge 7 ] || internal_fail "git_clone: parameters missing"
189
+   [ $# -ge 2 ] || internal_fail "_git_clone: parameters missing"
190 190
 
191
-   local reposdir="$1" ; shift
192
-   local name="$1"; shift
193 191
    local url="$1"; shift
194
-   local branch="$1"; shift
195
-   local scm="$1"; shift
196
-   local tag="$1"; shift
197 192
    local stashdir="$1"; shift
193
+   local branch="$1"; [ $# -ne 0 ] && shift
198 194
 
199 195
    [ ! -z "${url}" ]      || internal_fail "url is empty"
200 196
    [ ! -z "${stashdir}" ] || internal_fail "stashdir is empty"
... ...
@@ -210,6 +206,24 @@ git_clone()
210 210
       log_info "Cloning ${C_MAGENTA}${C_BOLD}${url}${C_INFO} ..."
211 211
    fi
212 212
 
213
+   local dstdir
214
+
215
+   dstdir="${stashdir}"
216
+
217
+   # "remote urls" go through caches
218
+   case "${url}" in
219
+      file:*|/*|~*|.*)
220
+      ;;
221
+
222
+      *:*)
223
+         if [ ! -z "${CLONE_CACHE}" ]
224
+         then
225
+            mkdir_if_missing "${CLONE_CACHE}"
226
+            dstdir="${CLONE_CACHE}/`basename ${url}`" # try to keep it global
227
+         fi
228
+      ;;
229
+   esac
230
+
213 231
 #
214 232
 # callers responsibility
215 233
 #
... ...
@@ -218,8 +232,17 @@ git_clone()
218 218
 #    parent="`dirname -- "${stashdir}"`"
219 219
 #   mkdir_if_missing "${parent}"
220 220
 
221
-   exekutor git ${GITFLAGS} clone ${options} ${GITOPTIONS} -- "${url}" "${stashdir}"  >&2 \
222
-    || fail "git clone of \"${url}\" into \"${stashdir}\" failed"
221
+   if [ ! -d "${dstdir}" ]
222
+   then
223
+      exekutor git ${GITFLAGS} clone ${options} ${GITOPTIONS} -- "${url}" "${dstdir}"  >&2 \
224
+         || fail "git clone of \"${url}\" into \"${dstdir}\" failed"
225
+   fi
226
+
227
+   if [ ! -z "${CLONE_CACHE}" -a "${stashdir}" != "${CLONE_CACHE}" ]
228
+   then
229
+      exekutor git ${GITFLAGS} clone ${options} ${GITOPTIONS} -- "${dstdir}" "${stashdir}"  >&2 \
230
+      || fail "git clone of \"${dstdir}\" into \"${stashdir}\" failed"
231
+   fi
223 232
 
224 233
    if [ ! -z "${tag}" ]
225 234
    then
... ...
@@ -228,6 +251,23 @@ git_clone()
228 228
 }
229 229
 
230 230
 
231
+
232
+git_clone()
233
+{
234
+   [ $# -ge 7 ] || internal_fail "git_clone: parameters missing"
235
+
236
+   local reposdir="$1" ; shift
237
+   local name="$1"; shift
238
+   local url="$1"; shift
239
+   local branch="$1"; shift
240
+   local scm="$1"; shift
241
+   local tag="$1"; shift
242
+   local stashdir="$1"; shift
243
+
244
+   _git_clone "${url}" "${stashdir}" "${branch}" "$@"
245
+}
246
+
247
+
231 248
 git_fetch()
232 249
 {
233 250
    [ $# -ge 7 ] || internal_fail "git_fetch: parameters missing"
... ...
@@ -108,6 +108,7 @@ build_dir
108 108
 build_log_dir
109 109
 build_preferences
110 110
 caches_path
111
+clone_cache
111 112
 check_usr_local_include
112 113
 clean_before_build
113 114
 clean_dependencies_before_build