daemon: Fix 'HashSink::currentHash()'.
[jackhill/guix/guix.git] / nix / sync-with-upstream
1 #!/bin/sh
2 # GNU Guix --- Functional package management for GNU
3 # Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
4 #
5 # This file is part of GNU Guix.
6 #
7 # GNU Guix is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or (at
10 # your option) any later version.
11 #
12 # GNU Guix is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20 #
21 # Update the local copy of Nix source code needed to build the daemon.
22 # Assume GNU Coreutils and Git are available.
23 #
24
25 top_srcdir="${top_srcdir:-..}"
26
27 log()
28 {
29 echo "sync-with-upstream: $@" >&2
30 }
31
32 # checked_in_p FILE
33 checked_in_p()
34 {
35 ( cd "$top_srcdir" ;
36 git ls-tree HEAD -- "nix/$1" | grep "$1" > /dev/null )
37 }
38
39 if [ ! -d "$top_srcdir/build-aux" ]
40 then
41 log "\`$top_srcdir' is not the valid top-level source directory"
42 exit 1
43 fi
44
45 set -e
46 for upstream_file in `cd "$top_srcdir/nix-upstream/src" ;
47 find . -name \*.c -or -name \*.h -or -name \*.cc -or -name \*.hh \
48 -or -name \*.cpp -or -name \*.hpp -or -name \*.sql`
49 do
50 if grep "$upstream_file" "$top_srcdir/daemon.am" > /dev/null
51 then
52 if checked_in_p "$upstream_file"
53 then
54 log "skipping \`$upstream_file', which has a checked-in copy"
55 else
56 ( cd "$top_srcdir/nix-upstream/src" && \
57 cp -v --parents "$upstream_file" ../../nix )
58 fi
59 else
60 log "skipping \`$upstream_file', which is not used"
61 fi
62 done
63
64 # This file should be generated by our build system so remove it.
65 rm -fv "$top_srcdir/nix/libstore/schema.sql.hh"
66
67 cp -v "$top_srcdir/nix-upstream/COPYING" "$top_srcdir/nix"
68 cp -v "$top_srcdir/nix-upstream/AUTHORS" "$top_srcdir/nix"
69
70 # Substitutions.
71 sed -i "$top_srcdir/nix/libstore/gc.cc" \
72 -e 's|/nix/find-runtime-roots\.pl|/guix/list-runtime-roots|g'
73
74 # Our 'guix_hash_context' structure has a copy constructor, specifically to
75 # handle the use case in 'HashSink::currentHash()' where the copy of the
76 # context is expected to truly copy the underlying hash context. The copy
77 # constructor cannot be used in 'Ctx' if that's a union, so turn it into a
78 # structure (we can afford to two wasted words.)
79 sed -i "$top_srcdir/nix/libutil/hash".{cc,hh} \
80 -e 's|union Ctx|struct Ctx|g'