forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-rosetta.sh
executable file
·89 lines (79 loc) · 2.32 KB
/
run-rosetta.sh
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
#
# Run jsii-rosetta on all jsii packages, using the S3 build cache if available.
#
# Usage: run-rosetta [--infuse] [--pkgs-from PKGSFILE]
#
# Performs three steps, in that order:
#
# 1. Run `rosetta extract` to read and translate all examples from all JSII
# assemblies.
#
# 2. Run `rosetta infuse` to traverse all examples we have, and copy them
# to classes that don't have an example yet.
#
# 3. Run `cdk-generate-synthetic-examples` to find all types that *still*
# don't have associated examples, and generate synthetic examples.
#
# If you already have a file with a list of all the JSII package directories
# in it, pass it as the first argument. Otherwise, this script will run
# 'list-packages' to determine a list itself.
set -eu
scriptdir=$(cd $(dirname $0) && pwd)
ROSETTA=${ROSETTA:-npx jsii-rosetta}
infuse=false
jsii_pkgs_file=""
while [[ $# -gt 0 ]]; do
case $1 in
--infuse)
infuse="true"
;;
--pkgs-from)
jsii_pkgs_file="$2"
shift
;;
-h|--help)
echo "Usage: run-rosetta.sh [--infuse] [--pkgs-from FILE]" >&2
exit 1
;;
*)
echo "Unrecognized argument: $1" >&2
exit 1
;;
esac
shift
done
if [[ "${jsii_pkgs_file}" = "" ]]; then
echo "Collecting package list..." >&2
TMPDIR=${TMPDIR:-$(dirname $(mktemp -u))}
node $scriptdir/list-packages $TMPDIR/jsii.txt $TMPDIR/nonjsii.txt
jsii_pkgs_file=$TMPDIR/jsii.txt
fi
rosetta_cache_file=$HOME/.s3buildcache/rosetta-cache.tabl.json
extract_opts=""
if $infuse; then
extract_opts="--infuse"
fi
#----------------------------------------------------------------------
echo "💎 Extracting code samples" >&2
time $ROSETTA extract \
--compile \
--verbose \
--compress-tablet \
--cache ${rosetta_cache_file} \
${extract_opts} \
$(cat $jsii_pkgs_file)
if $infuse; then
echo "💎 Generating synthetic examples for the remainder" >&2
time npx cdk-generate-synthetic-examples@^0.1.291 \
$(cat $jsii_pkgs_file)
time $ROSETTA extract \
--compile \
--verbose \
--compress-tablet \
--cache ${rosetta_cache_file} \
$(cat $jsii_pkgs_file)
fi
time $ROSETTA trim-cache \
${rosetta_cache_file} \
$(cat $jsii_pkgs_file)