|
| 1 | +#!/bin/zsh |
| 2 | + |
| 3 | +# A `realpath` alternative using the default C implementation. |
| 4 | +filepath() { |
| 5 | + [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" |
| 6 | +} |
| 7 | + |
| 8 | +gen_interface() { |
| 9 | + swift build -c release -Xswiftc -emit-module-interface -Xswiftc -enable-library-evolution -Xswiftc -no-verify-emitted-module-interface -Xswiftc -package-name -Xswiftc OpenGraph -Xswiftc -Osize |
| 10 | + |
| 11 | + mkdir -p .ag_template |
| 12 | + cp .build/release/Modules/OpenGraph.swiftinterface .ag_template/template.swiftinterface |
| 13 | + |
| 14 | + sed -i '' '1,4d' .ag_template/template.swiftinterface |
| 15 | + sed -i '' 's/@_exported public import OpenGraphCxx/@_exported public import AttributeGraph/g' .ag_template/template.swiftinterface |
| 16 | + sed -i '' 's/OpenGraphCxx\.//g' .ag_template/template.swiftinterface |
| 17 | + sed -i '' 's/OpenGraph/AttributeGraph/g' .ag_template/template.swiftinterface |
| 18 | + sed -i '' 's/OPENGRAPH/ATTRIBUTEGRAPH/g' .ag_template/template.swiftinterface |
| 19 | + sed -i '' 's/OG/AG/g' .ag_template/template.swiftinterface |
| 20 | + |
| 21 | + echo "Generated template.swiftinterface successfully" |
| 22 | +} |
| 23 | + |
| 24 | +gen_header() { |
| 25 | + mkdir -p .ag_template/Headers |
| 26 | + |
| 27 | + cp -r Sources/OpenGraphCxx/include/OpenGraph/* .ag_template/Headers/ |
| 28 | + |
| 29 | + # Rename files from OGxx to AGxx and OpenGraphxx to AttributeGraphxx |
| 30 | + find .ag_template/Headers -name "OG*" -type f | while read file; do |
| 31 | + new_name=$(echo "$file" | sed 's/OG/AG/g') |
| 32 | + mv "$file" "$new_name" |
| 33 | + done |
| 34 | + |
| 35 | + find .ag_template/Headers -name "OpenGraph*" -type f | while read file; do |
| 36 | + new_name=$(echo "$file" | sed 's/OpenGraph/AttributeGraph/g') |
| 37 | + mv "$file" "$new_name" |
| 38 | + done |
| 39 | + |
| 40 | + # Update content in all header files |
| 41 | + find .ag_template/Headers -name "*.h" -type f | while read file; do |
| 42 | + sed -i '' 's/OpenGraphCxx/AttributeGraph/g' "$file" |
| 43 | + sed -i '' 's/OpenGraph/AttributeGraph/g' "$file" |
| 44 | + sed -i '' 's/OPENGRAPH/ATTRIBUTEGRAPH/g' "$file" |
| 45 | + sed -i '' 's/OG/AG/g' "$file" |
| 46 | + done |
| 47 | + |
| 48 | + echo "Generated template headers successfully" |
| 49 | +} |
| 50 | + |
| 51 | +OPENGRAPH_ROOT="$(dirname $(dirname $(filepath $0)))" |
| 52 | + |
| 53 | +cd $OPENGRAPH_ROOT |
| 54 | + |
| 55 | +gen_interface |
| 56 | +gen_header |
0 commit comments