Skip to content

Commit c893514

Browse files
committed
Added open file argument and vars
1 parent 22d0b70 commit c893514

File tree

4 files changed

+59
-36
lines changed

4 files changed

+59
-36
lines changed

EZBuild.sublime-build

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"shell_cmd": "ezbuild -co $file_name",
3+
"working_dir": "${file_path}",
4+
5+
"variants":
6+
[
7+
{
8+
"name": "Run",
9+
"shell_cmd": "ezbuild -ro $file_name"
10+
},
11+
{
12+
"name": "Run Terminal",
13+
"shell_cmd": "ezbuild -epro $file_name"
14+
}
15+
]
16+
}

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ The files option will include the relevant directory path to every token when me
1818
Multiple build commands can be used, and the script will run through from 1-num.
1919
build commands without a number will be counted as build1.
2020

21-
Option |Merging|Desc |Vars
22-
----- |----- |----- |-----
21+
Option |Merging|Desc |Vars
22+
----- |----- |----- |-----
2323
cd |none |move to directory and use its config |
2424
files |path |lists all files passed to the build command |
2525
output |none |sets the output file given to the other commands |
2626
num |none |number of build commands to run |
27-
builder\# |none |build command run |%files, %cached, %output
27+
builder\# |none |build command run |%files, %ncfiles, %cached, %output, %open, %openc
2828
buildargs\# |basic |added to end of build command |
2929
caching |none |sed regex to convert src file paths to cached versions |
3030
depfinder|none |sed -n regex for locating the dependencies of a src file |
3131
terminal|none |emulator command used for -e |
32-
tester |none |command used with -r |%output
32+
tester |none |command used with -r |%output, %open, %openc
3333
testargs|basic |added to end of test command |
3434
testdir |basic |directory to run test from |
3535
parent |none |provides additional config file to check |

config

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ num=3
77
caching=s/.cpp/.o/g ; s: [^ ]*/: ../obj/:g
88
depfinder=s:#include \":../obj/:pg
99

10-
builder1=g++ -c %files -std=c++17 -Wall -fpermissive
10+
builder1=g++ -c %ncfiles -std=c++17 -Wall -fpermissive
1111
buildargs1=""
1212

1313
builder2=mv *.o ../obj/

ezbuild.sh

+38-31
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ TEST=""
88
CACHED=""
99
EXTRA=""
1010
NUMBER=""
11+
OPEN=""
12+
FILE=""
1113

1214
# Retrieve variable from recursive config files
1315
grab() {
@@ -84,34 +86,30 @@ headers() {
8486
}
8587

8688
# Parse command arguments
87-
while getopts ":eprca:n:f:" options; do
89+
while getopts ":eprca:n:o:f:" options; do
8890
case "${options}" in
8991
e )
90-
EMULATOR="-e"
91-
;;
92+
EMULATOR="-e";;
9293
p )
93-
PAUSE="-p"
94-
;;
94+
PAUSE="-p";;
9595
r )
96-
TEST="-r"
97-
;;
96+
TEST="-r";;
9897
c )
99-
CACHED="-c"
100-
;;
98+
CACHED="-c";;
10199
a )
102-
EXTRA=$OPTARG
103-
;;
100+
EXTRA=$OPTARG;;
104101
n )
105-
NUMBER=$OPTARG
106-
;;
102+
NUMBER=$OPTARG;;
103+
o )
104+
OPEN=$OPTARG;;
107105
f )
108106
if [ -e "$BASE" ]; then
109107
BASE=$OPTARG
108+
FILE="-f"
110109
else
111110
echo "Selected config file not found"
112111
exit 1
113-
fi
114-
;;
112+
fi;;
115113
\?)
116114
;;
117115
esac
@@ -120,7 +118,12 @@ done
120118
shift $((OPTIND -1))
121119
EXTRA="$EXTRA $@"
122120

123-
# Find config in parent
121+
# Test for open config file
122+
if [ -z "$FILE" ] && echo "$OPEN" | grep -q -E '*includes$'; then
123+
BASE=$OPEN
124+
fi
125+
126+
# Check for config in parent dir
124127
if [ ! -e "$BASE" ]; then
125128
if [ -e "../$BASE" ]; then
126129
echo "Using parent dir config"
@@ -133,19 +136,25 @@ fi
133136
# Redirect command to new window
134137
if [ -n "$EMULATOR" ]; then
135138
if [ -n "$NUMBER" ]; then
136-
$(grab terminal) ezbuild $PAUSE $TEST $CACHED -n $NUMBER $EXTRA
137-
else
138-
$(grab terminal) ezbuild $PAUSE $TEST $CACHED $EXTRA
139+
NUMBER="-n $NUMBER"
139140
fi
141+
if [ -n "$OPEN" ]; then
142+
OPEN="-o $OPEN"
143+
fi
144+
FILE="-f $BASE"
145+
146+
$(grab terminal) ezbuild $PAUSE $TEST $CACHED $NUMBER $OPEN $FILE $EXTRA
140147
exit 0
141148
fi
142149

143150
cd $(grab cd)
151+
caching=$(grab caching)
152+
OPENC=$(echo " $OPEN" | sed "$caching")
144153

145154
if [ -n "$TEST" ]; then
146155
# Run latest build
147-
runcmd=$(echo $(grab tester) | sed "s:%output:$(grab output):")
148-
runargs=$(grab testargs)
156+
runcmd=$(echo $(grab tester) | sed "s:%output:$(grab output): ; s:%openc:$OPENC: ; s:%open:$OPEN:")
157+
runargs=$(grab testargs 1)
149158
rundir=$(grab testdir)
150159
cd $rundir
151160
echo "$runcmd $EXTRA $runargs"
@@ -156,23 +165,23 @@ else
156165
output=$(grab output)
157166
num=$(grab num)
158167

159-
# Run caching reg on files
160-
caching=$(grab caching)
168+
# Run caching regex on files
161169
cached=$(echo " $files" | sed "$caching")
162170
depfinder=$(grab depfinder)
171+
filesc=$files
163172

173+
# Remove cached items from file list
164174
if [ -n "$CACHED" ]; then
165-
# Remove cached items from file list
166175
if [ -n "$caching" ]; then
167176
IFS=' '
168-
for val in $files; do
177+
for val in $filesc; do
169178
cacheval=$(echo " $val" | sed "$caching ; s:^ ::")
170179
# If source or header files newer than cache
171180
if [ -e "$cacheval" -a "$val" -ot "$cacheval" ]; then
172181
echo "Checking headers for $val"
173182
h=$(headers "$depfinder" "$cacheval" "$val")
174183
if [ -z "$h" ]; then
175-
files=$(echo $files | sed "s:$val::g")
184+
filesc=$(echo $filesc | sed "s:$val::g")
176185
else
177186
echo $h
178187
fi
@@ -181,9 +190,9 @@ else
181190
fi
182191
fi
183192

184-
# Check if all files in cache
193+
# Check if all files are in cache
185194
echo ""
186-
if [ -z "$files" -a -n "$cached" ]; then
195+
if [ -z "$filesc" -a -n "$cached" ]; then
187196
if [ -e $output ]; then
188197
echo "No files changed"
189198
exit 2
@@ -207,13 +216,11 @@ else
207216
fi
208217

209218
# Run command with substitutions
210-
buildcmd=$(echo $buildcmd | sed "s:%files:$files: ; s:%cached:$cached: ; s:%output:$output:")
219+
buildcmd=$(echo $buildcmd | sed "s:%ncfiles:$filesc: ; s:%files:$files: ; s:%cached:$cached: ; s:%output:$output: ; s:%openc:$OPENC: ; s:%open:$OPEN:")
211220
echo "$buildcmd$buildargs"
212221
$buildcmd $buildargs
213222
fi
214223
done
215-
216-
chmod +x $output
217224
fi
218225

219226
# Pause at end

0 commit comments

Comments
 (0)