Skip to content

Commit 85fa519

Browse files
committed
v0.7.0
2 parents 5db90d8 + 6cb9603 commit 85fa519

File tree

5 files changed

+57
-21
lines changed

5 files changed

+57
-21
lines changed

ChangeLog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ This project adheres to [Semantic Versioning](http://semver.org/).
77
## Unreleased
88

99

10+
11+
12+
## [0.7.0][0.7.0] - 20/12/2016
13+
14+
Added:
15+
16+
* add support for C++ files
17+
18+
1019
## [0.6.0][0.6.0] - 29/03/2016
1120

1221
Changed:
@@ -80,3 +89,4 @@ This is the very first version of `crun`.
8089
[0.4.0]:https://github.com/GochoMugo/crun/releases/tag/v0.4.0
8190
[0.5.0]:https://github.com/GochoMugo/crun/releases/tag/v0.5.0
8291
[0.6.0]:https://github.com/GochoMugo/crun/releases/tag/v0.6.0
92+
[0.7.0]:https://github.com/GochoMugo/crun/releases/tag/v0.7.0

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ test: clean
1313
bats ./test/*.sh
1414
@echo " !! testing using CRUN_CACHE_DIR"
1515
CRUN_CACHE_DIR=/tmp/crun-cache ./test/cache.c
16+
@echo " !! testing compiling CPP code"
17+
./test/cpp.cc
1618

1719
deps: bats clib
1820
clib install

README.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
21
# crun
32

4-
> Run **C** scripts, just like you would do with Python, Ruby etc.
3+
> Run **C/C++** scripts, just like you would do with Python, Ruby etc.
54
>
65
> [![Build Status](https://travis-ci.org/GochoMugo/crun.svg?branch=master)](https://travis-ci.org/GochoMugo/crun)
76
@@ -45,10 +44,12 @@
4544
I just love C! (and why not?!) Okay! This allows me to write more C code
4645
for day-to-day tasks, not just when you want to speed up some component
4746
of an application. It makes C more practical for use. Also, it is really
48-
handy when you are learning C; everything important is contained in the
47+
handy when you are learning C/C++; everything important is contained in the
4948
single file.
5049

51-
The first time you invoke a crun script, it is compiled using `cc` in
50+
The first time you invoke a crun script, it is compiled using
51+
`cc` (for C files with extension `.c`) or `g++` (for CPP files with
52+
extensions other than `.c`) in
5253
the directory holding the script, stored away in `/tmp/crun` and run
5354
immediately. Subsequent invocations will run the compiled executable,
5455
rather than re-compile, unless the source file has been modified
@@ -60,7 +61,7 @@ to cache executables across restarts. If no directory exists at
6061
`${CRUN_CACHE_DIR}` yet, it will be created using `mkdir -p`. Make sure
6162
`crun` has permissions to write to the directory.
6263

63-
If you have compilation flags that you need to be passed to `cc`, you
64+
If you have compilation flags that you need to be passed to `cc`/`g++`, you
6465
place them in the **2nd line** separately, inside a comment using `/*` and
6566
`*/`. For example,
6667

@@ -77,10 +78,11 @@ to some weird compilation errors!
7778
### extras:
7879
7980
By default, bash expressions in the string holding the flags are **not**
80-
are evaluated. This is a neat feature **but** I do understand it adds a new edge
81-
in the attack graph. You will need to **explicitly** enable this feature, using
82-
the environment variable `${CRUN_DO_EVAL}` or the command-line argument
83-
`--do-eval`. If enabled, a string such as `/* $(pkg-config --libs libuv) */`
81+
are evaluated. This is a neat feature **but** I do understand it adds a
82+
new edge in the attack graph. You will need to **explicitly** enable
83+
this feature, using the environment variable `${CRUN_DO_EVAL}` or
84+
the command-line argument `--do-eval`.
85+
If enabled, a string such as `/* $(pkg-config --libs libuv) */`
8486
for the compilation flags will be evaluated. So,
8587
8688
```bash
@@ -91,8 +93,9 @@ $ export CRUN_DO_EVAL=1 # you could place this in your ~/.bashrc (or equivalent
9193
$ crun --do-eval filename.c
9294
```
9395
94-
**Note**: Do **not** run scripts you do **not** trust, **even if** eval is disabled! Always
95-
remember, **no** system/application can ever be 100% secure!
96+
**Note**: Do **not** run scripts you do **not** trust, **even if**
97+
eval is disabled! Always remember, **no** system/application can
98+
ever be 100% secure!
9699
97100
To allow maximum efficiency, you can create a quick template of a script
98101
using:
@@ -117,18 +120,17 @@ skip running the compiled executable:
117120
$ crun --just-compile my_script
118121
```
119122

120-
Since `--just-compile` will make crun **not** run your executable, any arguments
121-
passed will be considered to be more compilation flags to use. It also
122-
echo's back the path to the compiled executable. So you could do something
123-
like:
123+
Since `--just-compile` will make crun **not** run your executable,
124+
any arguments passed will be considered to be more compilation flags to
125+
use. It also echo's back the path to the compiled executable.
126+
So you could do something like:
124127
125128
```bash
126129
$ gdb `crun --just-compile script.c -Wall -g`
127130
$ valgrind --leak-check=yes `crun --just-compile script.c -Wall -g` arg1 arg2
128131
```
129132
130133
131-
132134
## installation:
133135
134136
It's simple!
@@ -159,4 +161,3 @@ The **master** branch always remains stable. Development is done on the
159161
Copyright (c) 2015-2016 GochoMugo <mugo@forfuture.co.ke>
160162

161163
[dl]:https://raw.githubusercontent.com/GochoMugo/crun/master/crun.sh
162-

crun.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
set -e
55

66
# crun metadata
7-
CRUN_VERSION="0.6.0"
7+
CRUN_VERSION="0.7.0"
88
CRUN_URL="https://github.com/GochoMugo/crun"
99

1010
# showing help information
1111
function show_help() {
1212
echo " usage:"
13-
echo " as a shebang in your C file: #!/usr/bin/env crun"
13+
echo " as a shebang in your C/C++ file: #!/usr/bin/env crun"
1414
echo " direct invocation:"
1515
echo " crun --create|create-force <path>"
1616
echo " crun --help|version"
@@ -30,6 +30,18 @@ function show_help() {
3030
}
3131

3232

33+
# Return 0 if file does not have '.c' extension,
34+
# thus assuming it contains C++ code. Otherwise, 1
35+
# ${1} - file path
36+
function is_cpp_file() {
37+
if [[ "${1}" != *.c ]]
38+
then
39+
return 0
40+
fi
41+
return 1
42+
}
43+
44+
3345
# simple templating for a new C file
3446
# ${1} - file path
3547
# ${2} - whether to force creation i.e. clobber
@@ -140,7 +152,7 @@ ABS_PATH="${MAIN_DIR}/${FILENAME}"
140152
OUT_DIR="${CRUN_CACHE_DIR:-/tmp/crun}"
141153
OUT_NAME="$(echo "${ABS_PATH}" | sed s'/\//./g')"
142154
OUT_EXE="${OUT_DIR}/${OUT_NAME}"
143-
TMP_FILE="${OUT_EXE}.tmp.c"
155+
TMP_FILE="${OUT_DIR}/tmp${OUT_NAME}"
144156
CC_FLAGS="$(sed '2!d' "${ABS_PATH}" | grep -Eo '\/\*.*\*\/' | sed -e s'/^\/\*//' -e s'/\*\/$//')"
145157

146158
# runs the executable
@@ -154,6 +166,7 @@ function run_exe() {
154166
# ${2} - path to place executable
155167
function compile() {
156168
local args=
169+
local compiler=cc
157170

158171
# chdir to the directory holding the file
159172
pushd "${MAIN_DIR}" > /dev/null
@@ -172,8 +185,11 @@ function compile() {
172185
args="${args} ${INPUT_XARGS}"
173186
fi
174187

188+
# change compile if it is a CPP file
189+
is_cpp_file "${1}" && compiler=g++
190+
175191
# do compilation
176-
cc -o "${2}" "${1}" -I"${MAIN_DIR}" -L"${MAIN_DIR}" ${args}
192+
${compiler} -o "${2}" "${1}" -I"${MAIN_DIR}" -L"${MAIN_DIR}" ${args}
177193

178194
popd > /dev/null
179195
}

test/cpp.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env crun
2+
/* -Wall */
3+
#include <iostream>
4+
int main() {
5+
std::cout << "compiled using g++" << std::endl;
6+
return 0;
7+
}

0 commit comments

Comments
 (0)