Browse code

improved mirroring, symlink bugfixes and more modernize homebrew formula generation

Nat! authored on 20-06-2017 17:05:10
Showing 10 changed files
... ...
@@ -1,6 +1,8 @@
1 1
 .DS_Store
2 2
 *~.*
3 3
 *.chk
4
+*.bak
5
+*.old
4 6
 *.xcworkspace
5 7
 xcuserdata/
6 8
 build/
... ...
@@ -13,6 +15,7 @@ addictions/
13 15
 mulle-bootstrap.sublime-workspace
14 16
 relpath-python.sh
15 17
 relpath.sh
18
+tap-info.sh
16 19
 
17 20
 tutorial/*/.bootstrap
18 21
 
... ...
@@ -1,14 +1,16 @@
1
-### 3.7.0
1
+## 3.7.0
2 2
 
3 3
 * experimentally added ${GITHUB_REMOTE_ORIGIN} expansion, so you can specify
4 4
 dependencies relative to the original project.
5 5
 * when moving embedded directories around, mulle-bootstrap will now create
6 6
 missing target directories
7
-* renamed `clone_cache` to `git_mirror` because that's better, but old key
8
-will work too. `refresh_cache` is now `refresh_git_mirror`.
7
+* renamed `clone_cache` to `git_mirror` because that's better. `refresh_cache` is now `refresh_git_mirror`.
9 8
 * added option `--no-git-mirror
10 9
 * added `type` command to introspect the bootstrap topology easier
11
-
10
+* avoid superflous updating of mirrored git clones during one session, which
11
+speeds up things considerably, when mirroring
12
+* fix bug of failing symlinks, when the destination itself is accessed via a
13
+symlink
12 14
 
13 15
 ### 3.6.7
14 16
 
15 17
new file mode 100755
... ...
@@ -0,0 +1,9 @@
1
+# -- Formula Info --
2
+# If you don't have this file, there will be no homebrew
3
+# formula operations.
4
+#
5
+PROJECT="mulle-bootstrap"      # your project/repository name
6
+DESC="👢 Cross platform dependency manager - using bash and cmake"
7
+LANGUAGE="bash"                # c,cpp, objc, bash ...
8
+# NAME="${PROJECT}"        # formula filename without .rb extension
9
+
0 10
deleted file mode 100755
... ...
@@ -1,63 +0,0 @@
1
-#! /bin/sh
2
-#
3
-# Generate a formula formulle-xcode-settings stand alone
4
-#
5
-PROJECT=MulleBootstrap
6
-TARGET=mulle-bootstrap
7
-HOMEPAGE="http://www.mulle-kybernetik.com/software/git/${TARGET}"
8
-DESC="Dependency manager for cross-platform projects"
9
-
10
-VERSION="${1:-`./mulle-bootstrap version`}"
11
-[ $# -eq 0 ] || shift
12
-ARCHIVEURL="${1:-http://www.mulle-kybernetik.com/software/git/${TARGET}/tarball/$VERSION}"
13
-[ $# -eq 0 ] || shift
14
-
15
-[ "$VERSION" = "" ] && exit 1
16
-[ "$ARCHIVEURL" = "" ] && exit 1
17
-
18
-
19
-TMPARCHIVE="/tmp/${PROJECT}-${VERSION}-archive"
20
-
21
-if [ ! -f  "${TMPARCHIVE}" ]
22
-then
23
-   curl -L -o "${TMPARCHIVE}" "${ARCHIVEURL}"
24
-   if [ $? -ne 0 -o ! -f "${TMPARCHIVE}" ]
25
-   then
26
-      echo "Download failed" >&2
27
-      exit 1
28
-   fi
29
-else
30
-   echo "using cached file ${TMPARCHIVE} instead of downloading again" >&2
31
-fi
32
-
33
-#
34
-# anything less than 17 KB is wrong
35
-#
36
-size="`du -k "${TMPARCHIVE}" | awk '{ print $ 1}'`"
37
-if [ $size -lt 17 ]
38
-then
39
-   echo "Archive truncated or missing" >&2
40
-   cat "${TMPARCHIVE}" >&2
41
-   rm "${TMPARCHIVE}"
42
-   exit 1
43
-fi
44
-
45
-HASH="`shasum -p -a 256 "${TMPARCHIVE}" | awk '{ print $1 }'`"
46
-
47
-cat <<EOF
48
-class ${PROJECT} < Formula
49
-  homepage "${HOMEPAGE}"
50
-  desc "${DESC}"
51
-  url "${ARCHIVEURL}"
52
-  version "${VERSION}"
53
-  sha256 "${HASH}"
54
-
55
-  def install
56
-     system "./install.sh", "#{prefix}"
57
-  end
58
-
59
-  test do
60
-  end
61
-end
62
-# FORMULA ${TARGET}.rb
63
-EOF
... ...
@@ -1,64 +1,152 @@
1
-#! /bin/sh
2
-
3
-TAP="${1:-software}"
4
-[ $# -ne 0 ] && shift
5
-BRANCH="${1:-release}"
6
-[ $# -ne 0 ] && shift
7
-TAG="${1:-`./mulle-bootstrap version`}"
8
-[ $# -ne 0 ] && shift
9
-
10
-. src/mulle-bootstrap-logging.sh
1
+#! /usr/bin/env bash
2
+#
3
+#   Copyright (c) 2017 Nat! - Mulle kybernetiK
4
+#   All rights reserved.
5
+#
6
+#   Redistribution and use in source and binary forms, with or without
7
+#   modification, are permitted provided that the following conditions are met:
8
+#
9
+#   Redistributions of source code must retain the above copyright notice, this
10
+#   list of conditions and the following disclaimer.
11
+#
12
+#   Redistributions in binary form must reproduce the above copyright notice,
13
+#   this list of conditions and the following disclaimer in the documentation
14
+#   and/or other materials provided with the distribution.
15
+#
16
+#   Neither the name of Mulle kybernetiK nor the names of its contributors
17
+#   may be used to endorse or promote products derived from this software
18
+#   without specific prior written permission.
19
+#
20
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+#   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+#   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+#   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24
+#   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+#   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+#   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+#   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+#   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+#   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+#   POSSIBILITY OF SUCH DAMAGE.
31
+#
32
+#
33
+# For documentation and help see:
34
+#    https://github.com/mulle-nat/mulle-homebrew
35
+#
36
+# Run this somewhat like this (for real: remove -n):
37
+#   ./bin/release.sh -v -n --publisher mulle-nat --publisher-tap mulle-kybernetik/software/
38
+#
39
+
40
+#######
41
+# If you are using mulle-build, you don't hafta change anything
42
+#######
43
+
44
+#
45
+# Generate your `def install` `test do` lines here. echo them to stdout.
46
+#
47
+generate_brew_formula_build()
48
+{
49
+   cat <<EOF
50
+  def install
51
+     system "./install.sh", "#{prefix}"
52
+  end
53
+
54
+  test do
55
+  end
56
+EOF
57
+}
11 58
 
12 59
 
13
-git_must_be_clean()
60
+#
61
+# If you are unhappy with the formula in general, then change
62
+# this function. Print your formula to stdout.
63
+#
64
+generate_brew_formula()
14 65
 {
15
-   local name
16
-   local clean
66
+#   local project="$1"
67
+#   local name="$2"
68
+#   local version="$3"
69
+#   local dependencies="$4"
70
+#   local builddependencies="$5"
71
+#   local homepage="$6"
72
+#   local desc="$7"
73
+#   local archiveurl="$8"
74
+
75
+   _generate_brew_formula "$@"
76
+}
17 77
 
18
-   name="${1:-${PWD}}"
19 78
 
20
-   if [ ! -d .git ]
21
-   then
22
-      fail "\"${name}\" is not a git repository"
23
-   fi
79
+#######
80
+# Ideally changes to the following values are done with the command line
81
+# which makes it easier for forks.
82
+#######
24 83
 
25
-   clean=`git status -s --untracked-files=no`
26
-   if [ ! -z "${clean}" ]
27
-   then
28
-      fail "repository \"${name}\" is tainted"
29
-   fi
30
-}
84
+MULLE_BOOTSTRAP_FAIL_PREFIX="`basename -- $0`"
85
+MULLE_HOMEBREW_VERSION="4.1.0"
31 86
 
87
+#
88
+# prefer local mulle-homebrew if available
89
+# Do not embed it anymore!
90
+#
91
+if [ -z "`command -v mulle-homebrew-env`" ]
92
+then
93
+   cat <<EOF >&2
94
+mulle-homebrew-env not found in PATH.
95
+Visit the homepage for installation instructions:
96
+   https://github.com/mulle-nat/mulle-homebrew
97
+EOF
98
+   exit 1
99
+fi
32 100
 
33
-[ -d "../homebrew-$TAP" ] || fail "tap $TAP is invalid"
101
+INSTALLED_MULLE_HOMEBREW_VERSION="`mulle-homebrew-env version`" || exit 1
102
+LIBEXEC_DIR="`mulle-homebrew-env libexec-path`" || exit 1
34 103
 
35
-git_must_be_clean
104
+. "${LIBEXEC_DIR}/mulle-files.sh"       || exit 1
105
+. "${LIBEXEC_DIR}/mulle-homebrew.sh"    || exit 1
106
+. "${LIBEXEC_DIR}/mulle-git.sh"         || exit 1
107
+. "${LIBEXEC_DIR}/mulle-version.sh"     || exit 1
108
+. "${LIBEXEC_DIR}/mulle-environment.sh" || exit 1
36 109
 
37
-devbranch="`git rev-parse --abbrev-ref HEAD`"
38 110
 
39
-(
40
-   git checkout "${BRANCH}"    &&
41
-   git rebase "${devbranch}"   &&
42
-   git push public "${BRANCH}"
43
-) || exit 1
111
+main()
112
+{
113
+   if [ "${DO_GIT_RELEASE}" != "YES" -a "${DO_GENERATE_FORMULA}" != "YES" ]
114
+   then
115
+      fail "Nothing to do! bin/version-info.sh and bin/formula-info.sh are missing"
116
+   fi
44 117
 
118
+   if [ "${DO_GIT_RELEASE}" = "YES" ]
119
+   then
120
+     # do the release
121
+      git_main "${BRANCH}" "${ORIGIN}" "${TAG}" "${GITHUB}" || exit 1
122
+   fi
45 123
 
46
-# seperate step, as it's tedious to remove tag when
47
-# previous push fails
124
+   if [ "${DO_GENERATE_FORMULA}" != "YES" ]
125
+   then
126
+       return
127
+   fi
48 128
 
49
-(
50
-   git tag "${TAG}"                    &&
51
-   git push public "${BRANCH}" --tags  &&
52
-   git push github "${BRANCH}" --tags
53
-) || exit 1
129
+   if [ -z "${PUBLISHER}" ]
130
+   then
131
+      fail "You need to specify a publisher with --publisher (hint: https://github.com/<publisher>)"
132
+   fi
54 133
 
134
+   if [ -z "${PUBLISHER_TAP}" ]
135
+   then
136
+      fail "You need to specify a publisher tap with --tap (hint: <mulle-kybernetik/software>)"
137
+   fi
55 138
 
56
-./bin/generate-brew-formula.sh  > ../homebrew-$TAP/mulle-bootstrap.rb
57
-(
58
-	cd ../homebrew-$TAP ; \
59
-   git add mulle-bootstrap.rb ; \
60
- 	git commit -m "${TAG} ${BRANCH} of mulle-bootstrap" mulle-bootstrap.rb ; \
61
- 	git push origin master
62
-)
139
+   # generate the formula and push it
140
+   homebrew_main "${PROJECT}" \
141
+                 "${NAME}" \
142
+                 "${VERSION}" \
143
+                 "${DEPENDENCIES}" \
144
+                 "${BUILD_DEPENDENCIES}" \
145
+                 "${HOMEPAGE_URL}" \
146
+                 "${DESC}" \
147
+                 "${ARCHIVE_URL}" \
148
+                 "${HOMEBREW_TAP}" \
149
+                 "${RBFILE}"
150
+}
63 151
 
64
-git checkout "${devbranch}"
152
+main "$@"
65 153
new file mode 100755
... ...
@@ -0,0 +1,8 @@
1
+# -- Version Info --
2
+#
3
+# Keep these commented out, if the automatic detection works well
4
+# enough for you. If you don't have this file, there will be
5
+# not git operations.
6
+#
7
+VERSION="`./mulle-bootstrap version`"
8
+# VERSIONNAME=
... ...
@@ -1668,6 +1668,7 @@ _common_main()
1668 1668
    local OPTION_ALLOW_CREATING_EMBEDDED_SYMLINKS="NO"
1669 1669
    local OPTION_ALLOW_SEARCH_CACHES="YES"
1670 1670
    local OPTION_ALLOW_GIT_MIRROR="YES"
1671
+   local OPTION_ALLOW_REFRESH_GIT_MIRROR="YES"
1671 1672
    local OPTION_EMBEDDED_ONLY="NO"
1672 1673
    local OVERRIDE_BRANCH
1673 1674
    local DONT_WARN_SCRIPTS="NO"
... ...
@@ -1738,6 +1739,10 @@ _common_main()
1738 1739
             OPTION_ALLOW_GIT_MIRROR="NO"
1739 1740
          ;;
1740 1741
 
1742
+         --no-refresh-git_mirror)
1743
+            OPTION_ALLOW_REFRESH_GIT_MIRROR="NO"
1744
+         ;;
1745
+
1741 1746
          --no-caches)
1742 1747
             OPTION_ALLOW_SEARCH_CACHES="NO"
1743 1748
          ;;
... ...
@@ -1797,15 +1802,15 @@ _common_main()
1797 1802
    #
1798 1803
    # "repository" caches can and usually are outside the project folder
1799 1804
    # this can be multiple paths!
1800
-   if [ "OPTION_ALLOW_SEARCH_CACHES" = "YES" ]
1805
+   if [ "${OPTION_ALLOW_SEARCH_CACHES}" = "YES" ]
1801 1806
    then
1802 1807
       CACHES_PATH="`read_config_setting "search_path" "${MULLE_BOOTSTRAP_CACHES_PATH}"`"
1803 1808
       CACHES_PATH="`add_path "${CACHES_PATH}" "${CLONE_CACHE}"`"
1804 1809
    fi
1805 1810
 
1806
-   if [ "OPTION_ALLOW_GIT_MIRROR" = "YES" ]
1811
+   if [ "${OPTION_ALLOW_GIT_MIRROR}" = "YES" ]
1807 1812
    then
1808
-      git_enable_mirroring
1813
+      git_enable_mirroring "${OPTION_ALLOW_REFRESH_GIT_MIRROR}"
1809 1814
    fi
1810 1815
 
1811 1816
    #
... ...
@@ -1864,6 +1869,7 @@ _common_main()
1864 1869
    remove_file_if_present "${REPOS_DIR}/.build_done.orig"
1865 1870
    remove_file_if_present "${REPOS_DIR}/.build_done"
1866 1871
    remove_file_if_present "${REPOS_DIR}/.fetch_done"
1872
+   remove_file_if_present "${REPOS_DIR}/.uptodate-mirrors"
1867 1873
    create_file_if_missing "${REPOS_DIR}/.fetch_started"
1868 1874
 
1869 1875
    if [ "${BREW_PERMISSIONS}" != "none" ]
... ...
@@ -1242,10 +1242,13 @@ create_symlink()
1242 1242
    url="`absolutepath "${url}"`"
1243 1243
    url="`realpath "${url}"`"  # resolve symlinks
1244 1244
 
1245
+   # need to do this otherwise the symlink fails
1246
+
1245 1247
    srcname="`basename -- ${url}`"
1246 1248
    directory="`dirname -- "${stashdir}"`"
1247 1249
 
1248 1250
    mkdir_if_missing "${directory}"
1251
+   directory="`realpath "${directory}"`"  # resolve symlinks
1249 1252
 
1250 1253
    #
1251 1254
    # relative paths look nicer, but could fail in more complicated
... ...
@@ -467,7 +467,6 @@ add_path_if_exists()
467 467
 }
468 468
 
469 469
 
470
-
471 470
 #
472 471
 # this is for constructing filesystem paths
473 472
 #
... ...
@@ -171,7 +171,11 @@ git_checkout()
171 171
 }
172 172
 
173 173
 
174
-_git_clone_cacheurl()
174
+
175
+# global variable __GIT_MIRROR_URLS__ used to avoid refetching
176
+# repos in one setting
177
+#
178
+_git_get_mirror_url()
175 179
 {
176 180
    local url="$1"; shift
177 181
 
... ...
@@ -180,8 +184,26 @@ _git_clone_cacheurl()
180 184
    mkdir_if_missing "${GIT_MIRROR}"
181 185
    mirrordir="${GIT_MIRROR}/`basename ${url}`" # try to keep it global
182 186
 
187
+   local match
188
+   local filelistpath
189
+
190
+   # use global reposdir
191
+   [ -z "${REPOS_DIR}" ] && internal_fail "REPOS_DIR undefined"
192
+
193
+   filelistpath="${REPOS_DIR}/.uptodate-mirrors"
194
+   log_debug "Mirror URLS: `cat "${filelistpath}"  2>/dev/null`"
195
+
196
+   match="`fgrep -s -x "${mirrordir}" "${filelistpath}" 2>/dev/null`"
197
+   if [ ! -z "${match}" ]
198
+   then
199
+      log_fluff "Repository \"${mirrordir}\" already up-to-date for this session"
200
+      echo "${mirrordir}"
201
+      return 0
202
+   fi
203
+
183 204
    if [ ! -d "${mirrordir}" ]
184 205
    then
206
+      log_verbose "Set up git-mirror \"${mirrordir}\""
185 207
       if ! exekutor git ${GITFLAGS} clone --mirror ${options} ${GITOPTIONS} -- "${url}" "${mirrordir}" >&2
186 208
       then
187 209
          log_error "git clone of \"${url}\" into \"${mirrordir}\" failed"
... ...
@@ -189,12 +211,11 @@ _git_clone_cacheurl()
189 211
       fi
190 212
    else
191 213
       # refetch
192
-      local refresh_git_mirror
193 214
 
194
-      refresh_git_mirror="`read_config_setting "refresh_git_mirror" "YES"`"
195
-      if [ "${refresh_git_mirror}" = "YES" ]
215
+      if [ "${REFRESH_GIT_MIRROR}" = "YES" ]
196 216
       then
197 217
       (
218
+         log_verbose "Refreshing git-mirror \"${mirrordir}\""
198 219
          cd "${mirrordir}";
199 220
          if ! exekutor git ${GITFLAGS} fetch >&2
200 221
          then
... ...
@@ -204,6 +225,9 @@ _git_clone_cacheurl()
204 225
       fi
205 226
    fi
206 227
 
228
+   # for embedded we are otherwise too early
229
+   mkdir_if_missing "${reposdir}"
230
+   echo "${mirrordir}" >> "${filelistpath}"
207 231
    echo "${mirrordir}"
208 232
 }
209 233
 
... ...
@@ -242,7 +266,7 @@ _git_clone()
242 266
       *:*)
243 267
          if [ ! -z "${GIT_MIRROR}" ]
244 268
          then
245
-            url="`_git_clone_cacheurl ${url}`"
269
+            url="`_git_get_mirror_url "${url}"`"
246 270
          fi
247 271
       ;;
248 272
    esac
... ...
@@ -275,7 +299,7 @@ git_clone()
275 299
 {
276 300
    [ $# -ge 7 ] || internal_fail "git_clone: parameters missing"
277 301
 
278
-#   local reposdir="$1"
302
+   local reposdir="$1"
279 303
 #   local name="$2"
280 304
    local url="$3"
281 305
    local branch="$4"
... ...
@@ -283,7 +307,7 @@ git_clone()
283 307
    local tag="$6"
284 308
    local stashdir="$7"
285 309
 
286
-   if ! _git_clone "${url}" "${stashdir}" "${branch}"
310
+   if ! _git_clone "${url}" "${stashdir}" "${branch}" "${reposdir}"
287 311
    then
288 312
       return 1
289 313
    fi
... ...
@@ -315,7 +339,7 @@ git_fetch()
315 339
       *:*)
316 340
          if [ ! -z "${GIT_MIRROR}" ]
317 341
          then
318
-            url="`_git_clone_cacheurl ${url}`"
342
+            url="`_git_get_mirror_url ${url}`"
319 343
          fi
320 344
       ;;
321 345
    esac
... ...
@@ -349,7 +373,7 @@ git_pull()
349 373
       *:*)
350 374
          if [ ! -z "${GIT_MIRROR}" ]
351 375
          then
352
-            url="`_git_clone_cacheurl ${url}`"
376
+            url="`_git_get_mirror_url ${url}`"
353 377
          fi
354 378
       ;;
355 379
    esac
... ...
@@ -890,11 +914,13 @@ zip_unpack()
890 914
 
891 915
 git_enable_mirroring()
892 916
 {
893
-   # stuff clones get intermediate saved too, default empty
917
+   local allow_refresh="${1:-YES}"
918
+
919
+   # stuff clones get intermediate saved too, default is empty
894 920
    GIT_MIRROR="`read_config_setting "git_mirror"`"
895
-   if [ -z "${GIT_MIRROR}" ]
921
+   if [ "${allow_refresh}" = "YES" ]
896 922
    then
897
-      GIT_MIRROR="`read_config_setting "clone_cache"`"  # old value
923
+      REFRESH_GIT_MIRROR="`read_config_setting "refresh_git_mirror" "YES"`"
898 924
    fi
899 925
 }
900 926