forked from apple/swift-atomics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-sources
executable file
·72 lines (58 loc) · 2.26 KB
/
generate-sources
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
#!/bin/sh
#===----------------------------------------------------------------------===//
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2020 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
#===----------------------------------------------------------------------===//
set -eu
srcroot="$(dirname "$0")"
cd "$srcroot"
gyb="./Utilities/gyb"
# Disable line directives in gyb output. We commit generated sources
# into the package repository, so we do not want absolute file names
# in them.
lineDirective=''
# Uncomment the following line to enable #sourceLocation directives.
# This is useful for local development.
#lineDirective='#sourceLocation(file: "%(file)s", line: %(line)d)'
echo "Running gyb..."
# Create a temporary directory; remove it on exit.
tmpdir="$(mktemp -d -t "$(basename "$0")")"
trap "rm -rf \"$tmpdir\"" EXIT
# Run gyb on each gyb file in the source tree and put results in
# subdirectories named 'autogenerated'.
for input in ./Sources/*/*.gyb ./Tests/*/*.gyb; do
basename="$(basename "$input")"
targetdir="$(dirname "$input")/autogenerated"
output="$targetdir/"${basename%.gyb}
tmpfile="$tmpdir/${basename%.gyb}"
# Make sure the output directory exists.
mkdir -p "$targetdir"
# Run gyb, making sure to only update files when they change.
"$gyb" --line-directive "$lineDirective" -o "$tmpfile" "$input"
if [ -e "$output" ] && cmp -s "$tmpfile" "$output"; then
: Ignore unchanged file
else
echo "Updated $output"
cp "$tmpfile" "$output"
fi
echo "$output" >> "$tmpdir/generated-files.txt"
done
# Warn user if there are any autogenerated files without a corresponding gyb.
find . -path '*/autogenerated/*.swift' >> "$tmpdir/generated-files.txt"
sort "$tmpdir/generated-files.txt" | uniq -u | while read obsolete; do
echo "Removing $obsolete"
rm "$obsolete"
done
# Generate XCTest test registry for platforms without the Objective-C runtime.
if [ "$(uname)" = Darwin ]; then
echo "Registering tests..."
swift test --generate-linuxmain
fi
echo "All done!"