Skip to content

Commit

Permalink
v0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
GochoMugo committed Dec 21, 2016
2 parents 5db90d8 + 6cb9603 commit 85fa519
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 21 deletions.
10 changes: 10 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## Unreleased




## [0.7.0][0.7.0] - 20/12/2016

Added:

* add support for C++ files


## [0.6.0][0.6.0] - 29/03/2016

Changed:
Expand Down Expand Up @@ -80,3 +89,4 @@ This is the very first version of `crun`.
[0.4.0]:https://github.com/GochoMugo/crun/releases/tag/v0.4.0
[0.5.0]:https://github.com/GochoMugo/crun/releases/tag/v0.5.0
[0.6.0]:https://github.com/GochoMugo/crun/releases/tag/v0.6.0
[0.7.0]:https://github.com/GochoMugo/crun/releases/tag/v0.7.0
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ test: clean
bats ./test/*.sh
@echo " !! testing using CRUN_CACHE_DIR"
CRUN_CACHE_DIR=/tmp/crun-cache ./test/cache.c
@echo " !! testing compiling CPP code"
./test/cpp.cc

deps: bats clib
clib install
Expand Down
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

# crun

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

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

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

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

Since `--just-compile` will make crun **not** run your executable, any arguments
passed will be considered to be more compilation flags to use. It also
echo's back the path to the compiled executable. So you could do something
like:
Since `--just-compile` will make crun **not** run your executable,
any arguments passed will be considered to be more compilation flags to
use. It also echo's back the path to the compiled executable.
So you could do something like:
```bash
$ gdb `crun --just-compile script.c -Wall -g`
$ valgrind --leak-check=yes `crun --just-compile script.c -Wall -g` arg1 arg2
```
## installation:
It's simple!
Expand Down Expand Up @@ -159,4 +161,3 @@ The **master** branch always remains stable. Development is done on the
Copyright (c) 2015-2016 GochoMugo <[email protected]>

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

24 changes: 20 additions & 4 deletions crun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
set -e

# crun metadata
CRUN_VERSION="0.6.0"
CRUN_VERSION="0.7.0"
CRUN_URL="https://github.com/GochoMugo/crun"

# showing help information
function show_help() {
echo " usage:"
echo " as a shebang in your C file: #!/usr/bin/env crun"
echo " as a shebang in your C/C++ file: #!/usr/bin/env crun"
echo " direct invocation:"
echo " crun --create|create-force <path>"
echo " crun --help|version"
Expand All @@ -30,6 +30,18 @@ function show_help() {
}


# Return 0 if file does not have '.c' extension,
# thus assuming it contains C++ code. Otherwise, 1
# ${1} - file path
function is_cpp_file() {
if [[ "${1}" != *.c ]]
then
return 0
fi
return 1
}


# simple templating for a new C file
# ${1} - file path
# ${2} - whether to force creation i.e. clobber
Expand Down Expand Up @@ -140,7 +152,7 @@ ABS_PATH="${MAIN_DIR}/${FILENAME}"
OUT_DIR="${CRUN_CACHE_DIR:-/tmp/crun}"
OUT_NAME="$(echo "${ABS_PATH}" | sed s'/\//./g')"
OUT_EXE="${OUT_DIR}/${OUT_NAME}"
TMP_FILE="${OUT_EXE}.tmp.c"
TMP_FILE="${OUT_DIR}/tmp${OUT_NAME}"
CC_FLAGS="$(sed '2!d' "${ABS_PATH}" | grep -Eo '\/\*.*\*\/' | sed -e s'/^\/\*//' -e s'/\*\/$//')"

# runs the executable
Expand All @@ -154,6 +166,7 @@ function run_exe() {
# ${2} - path to place executable
function compile() {
local args=
local compiler=cc

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

# change compile if it is a CPP file
is_cpp_file "${1}" && compiler=g++

# do compilation
cc -o "${2}" "${1}" -I"${MAIN_DIR}" -L"${MAIN_DIR}" ${args}
${compiler} -o "${2}" "${1}" -I"${MAIN_DIR}" -L"${MAIN_DIR}" ${args}

popd > /dev/null
}
Expand Down
7 changes: 7 additions & 0 deletions test/cpp.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env crun
/* -Wall */
#include <iostream>
int main() {
std::cout << "compiled using g++" << std::endl;
return 0;
}

0 comments on commit 85fa519

Please sign in to comment.