Skip to content

Commit 9e7b7c4

Browse files
authored
Update Build Script for Multiple Targets (#41)
1 parent 4707baa commit 9e7b7c4

File tree

4 files changed

+66
-9
lines changed

4 files changed

+66
-9
lines changed
-6.18 KB
Binary file not shown.

Sources/CodeEditLanguages/Documentation.docc/Add-Languages.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ In order to add a language to ``CodeEditLanguages`` you need to open the `.xcode
117117
```bash
118118
$ ./build_framework.sh
119119
```
120+
> Note: To run the script, you need to install `jq` by downloading it [here](https://stedolan.github.io/jq/) or with Homebrew using:
121+
> ```bash
122+
> $ brew install jq
123+
> ```
120124

121125
5. Check the output of the script. It should say `Done!` at the end.
122126
![build_framework.sh console output](build-output)

Sources/CodeEditLanguages/Documentation.docc/Update-Languages.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ From time to time the `tree-sitter` languages need to be updated to their latest
3232
```bash
3333
$ ./build_framework.sh
3434
```
35+
> Note: To run the script, you need to install `jq` by downloading it [here](https://stedolan.github.io/jq/) or with Homebrew using:
36+
> ```bash
37+
> $ brew install jq
38+
> ```
39+
3540
> Note: This script automatically removes old artifacts and replaces them with the new ones.
3641
3742
3. Check the console output. It should say `Done!` at the end.

build_framework.sh

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# convenience function to print a status message in green
1414
status () {
1515
local GREEN='\033[0;32m'
16-
local NC='\033[0m' # No Color
16+
local NC='\033[0m' # No Color
1717
echo "${GREEN}$1${NC}"
1818
}
1919

@@ -75,21 +75,69 @@ RESOURCES_PATH="$PWD/Sources/CodeEditLanguages/Resources"
7575
status "Copying language queries to package resources..."
7676
rm -rf "$RESOURCES_PATH"
7777

78-
# find and copy language queries
78+
# find and copy language queries
7979
LIST=$( echo $CHECKOUTS_PATH/tree-* )
8080

81+
OLD_PWD="$PWD"
82+
8183
for lang in $LIST ; do
82-
name=${lang##*/}
83-
mkdir -p $RESOURCES_PATH/$name
84-
highlights=$( find $lang -type f -name "*.scm" )
85-
for highlight in $highlights ; do
86-
highlight_name=${highlight##*/}
87-
cp $highlight $RESOURCES_PATH/$name/$highlight_name
84+
# determine how many targets a given package has
85+
cd $lang
86+
87+
# get package info as JSON
88+
manifest=$(swift package dump-package)
89+
90+
# use jq to get the target path
91+
targets=$(echo $manifest | jq -r '.targets[].path')
92+
93+
# use jq to count number of targets
94+
count=$(echo $manifest | jq '.targets | length')
95+
96+
# Determine if target paths are all '.'
97+
same=1
98+
for target in $targets; do
99+
if [[ $target != "." ]]; then
100+
same=0
101+
break
102+
fi
103+
done
104+
105+
# loop through targets
106+
for target in $targets; do
107+
name=${lang##*/}
108+
109+
# if there is only one target, use name
110+
# otherwise use target
111+
if [[ $count -eq 1 || ($count -ne 1 && $same -eq 1) ]]; then
112+
mkdir -p $RESOURCES_PATH/$name
113+
else
114+
mkdir -p $RESOURCES_PATH/$target
115+
fi
116+
117+
highlights=$( find $lang/$target -type f -name "*.scm" )
118+
for highlight in $highlights ; do
119+
highlight_name=${highlight##*/}
120+
121+
# if there is only one target, use name
122+
# otherwise use target
123+
if [[ $count -eq 1 || ($count -ne 1 && $same -eq 1) ]]; then
124+
cp $highlight $RESOURCES_PATH/$name/$highlight_name
125+
else
126+
cp $highlight $RESOURCES_PATH/$target/$highlight_name
127+
fi
128+
done
129+
130+
# If target paths are all '.', break out of loop
131+
if [[ $same -eq 1 || ($count -ne 1 && $same -eq 1) ]]; then
132+
break
133+
fi
88134
done
89135
done
90136
status "Language queries copied to package resources!"
91137

92-
# cleanup derived derived data
138+
# cleanup derived derived data
139+
140+
cd $OLD_PWD
93141

94142
if [ -d "$PWD/DerivedData" ]; then
95143
status "Cleaning up DerivedData..."

0 commit comments

Comments
 (0)