Compare commits
22 Commits
Author | SHA1 | Date |
---|---|---|
tastytea | e4531464b5 | |
tastytea | c9e38fa636 | |
tastytea | 5430c2de39 | |
tastytea | 6fb459467a | |
tastytea | fde11f722c | |
tastytea | 72a4e41679 | |
tastytea | 3a42baa24a | |
tastytea | 95e9b19c83 | |
tastytea | 6efea73391 | |
tastytea | 19a9388137 | |
tastytea | e8685e9f55 | |
tastytea | 83abaf81b6 | |
tastytea | 4c26c25c91 | |
tastytea | 052c82ba41 | |
tastytea | 238947729a | |
tastytea | 0abb33cdbc | |
tastytea | d714ff6930 | |
tastytea | 95b4ca21ed | |
tastytea | 125e45ca88 | |
tastytea | d1b2f5e54a | |
tastytea | c265c129ea | |
tastytea | b4011aae38 |
305
.drone.yml
305
.drone.yml
|
@ -1,176 +1,147 @@
|
||||||
pipeline:
|
kind: pipeline
|
||||||
gcc5:
|
name: x86_64 build
|
||||||
image: debian:stretch-slim
|
|
||||||
pull: true
|
|
||||||
when:
|
|
||||||
event: [push, pull_request]
|
|
||||||
environment:
|
|
||||||
- LANG=C.utf8
|
|
||||||
- CXX=g++-5
|
|
||||||
- CXXFLAGS=-pipe -O2
|
|
||||||
commands:
|
|
||||||
- rm /etc/apt/apt.conf.d/docker-clean
|
|
||||||
- apt-get update -q
|
|
||||||
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
|
|
||||||
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
|
|
||||||
- apt-get install -qy gnupg
|
|
||||||
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0x60c317803a41ba51845e371a1e9377a2ba9ef27f
|
|
||||||
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
|
|
||||||
- apt-get update -q
|
|
||||||
- apt-get install -qy -t xenial g++-5
|
|
||||||
- apt-get install -qy cmake pkg-config
|
|
||||||
- apt-get install -qy libconfig++-dev libxdg-basedir-dev asciidoc
|
|
||||||
- rm -rf build && mkdir -p build && cd build
|
|
||||||
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
|
|
||||||
- make VERBOSE=1
|
|
||||||
volumes:
|
|
||||||
- /var/cache/debian-package-cache:/var/cache/apt/archives
|
|
||||||
|
|
||||||
gcc6:
|
volumes:
|
||||||
image: debian:stretch-slim
|
- name: debian-package-cache
|
||||||
pull: true
|
host:
|
||||||
environment:
|
path: /var/cache/debian-package-cache
|
||||||
- LANG=C.utf8
|
|
||||||
- CXX=g++-6
|
|
||||||
- CXXFLAGS=-pipe -O2
|
|
||||||
commands:
|
|
||||||
- rm /etc/apt/apt.conf.d/docker-clean
|
|
||||||
- apt-get update -q
|
|
||||||
- apt-get install -qy g++-6 cmake pkg-config
|
|
||||||
- apt-get install -qy libconfig++-dev libxdg-basedir-dev asciidoc
|
|
||||||
- apt-get install -qy dpkg-dev d-shlibs rpm file wget
|
|
||||||
- rm -rf build && mkdir -p build && cd build
|
|
||||||
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
|
|
||||||
- make VERBOSE=1
|
|
||||||
- make install DESTDIR=install
|
|
||||||
volumes:
|
|
||||||
- /var/cache/debian-package-cache:/var/cache/apt/archives
|
|
||||||
|
|
||||||
gcc7:
|
trigger:
|
||||||
image: debian:stretch-slim
|
event:
|
||||||
pull: true
|
exclude:
|
||||||
when:
|
- tag
|
||||||
event: [push, pull_request]
|
|
||||||
environment:
|
|
||||||
- LANG=C.utf8
|
|
||||||
- CXX=g++-7
|
|
||||||
- CXXFLAGS=-pipe -O2
|
|
||||||
commands:
|
|
||||||
- rm /etc/apt/apt.conf.d/docker-clean
|
|
||||||
- apt-get update -q
|
|
||||||
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
|
|
||||||
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
|
|
||||||
- apt-get install -qy gnupg
|
|
||||||
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0x60c317803a41ba51845e371a1e9377a2ba9ef27f
|
|
||||||
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
|
|
||||||
- apt-get update -q
|
|
||||||
- apt-get install -qy -t xenial g++-7
|
|
||||||
- apt-get install -qy cmake pkg-config
|
|
||||||
- apt-get install -qy libconfig++-dev libxdg-basedir-dev asciidoc
|
|
||||||
- rm -rf build && mkdir -p build && cd build
|
|
||||||
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
|
|
||||||
- make VERBOSE=1
|
|
||||||
volumes:
|
|
||||||
- /var/cache/debian-package-cache:/var/cache/apt/archives
|
|
||||||
|
|
||||||
gcc8:
|
steps:
|
||||||
image: debian:stretch-slim
|
- name: submodules
|
||||||
pull: true
|
image: docker:git
|
||||||
when:
|
commands:
|
||||||
event: [push, pull_request]
|
- git submodule init
|
||||||
environment:
|
- git submodule update --recursive
|
||||||
- LANG=C.utf8
|
|
||||||
- CXX=g++-8
|
|
||||||
- CXXFLAGS=-pipe -O2
|
|
||||||
commands:
|
|
||||||
- rm /etc/apt/apt.conf.d/docker-clean
|
|
||||||
- apt-get update -q
|
|
||||||
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
|
|
||||||
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
|
|
||||||
- apt-get install -qy gnupg
|
|
||||||
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0x60c317803a41ba51845e371a1e9377a2ba9ef27f
|
|
||||||
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
|
|
||||||
- apt-get update -q
|
|
||||||
- apt-get install -qy -t xenial g++-8
|
|
||||||
- apt-get install -qy cmake pkg-config
|
|
||||||
- apt-get install -qy libconfig++-dev libxdg-basedir-dev asciidoc
|
|
||||||
- rm -rf build && mkdir -p build && cd build
|
|
||||||
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
|
|
||||||
- make VERBOSE=1
|
|
||||||
volumes:
|
|
||||||
- /var/cache/debian-package-cache:/var/cache/apt/archives
|
|
||||||
|
|
||||||
clang3:
|
- name: gcc6
|
||||||
image: debian:stretch-slim
|
image: debian:stretch-slim
|
||||||
pull: true
|
pull: always
|
||||||
when:
|
environment:
|
||||||
event: [push, pull_request]
|
LANG: C.utf8
|
||||||
environment:
|
CXX: g++-6
|
||||||
- LANG=C.utf8
|
CXXFLAGS: -pipe -O2
|
||||||
- CXX=clang++
|
commands:
|
||||||
- CXXFLAGS=-pipe -O2
|
- rm /etc/apt/apt.conf.d/docker-clean
|
||||||
commands:
|
- apt-get update -q
|
||||||
- rm /etc/apt/apt.conf.d/docker-clean
|
- apt-get install -qy g++-6 cmake pkg-config
|
||||||
- apt-get update -q
|
- apt-get install -qy libconfig++-dev libxdg-basedir-dev asciidoc
|
||||||
- apt-get install -qy clang cmake pkg-config
|
- apt-get install -qy dpkg-dev d-shlibs rpm file wget
|
||||||
- apt-get install -qy libconfig++-dev libxdg-basedir-dev asciidoc
|
- rm -rf build && mkdir -p build && cd build
|
||||||
- rm -rf build && mkdir -p build && cd build
|
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
|
||||||
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
|
- make VERBOSE=1
|
||||||
- make VERBOSE=1
|
- make install DESTDIR=install
|
||||||
volumes:
|
volumes:
|
||||||
- /var/cache/debian-package-cache:/var/cache/apt/archives
|
- name: debian-package-cache
|
||||||
|
path: /var/cache/apt/archives
|
||||||
|
|
||||||
clang5:
|
|
||||||
image: debian:stretch-slim
|
|
||||||
pull: true
|
|
||||||
when:
|
|
||||||
event: [push, pull_request]
|
|
||||||
environment:
|
|
||||||
- LANG=C.utf8
|
|
||||||
- CXX=clang++-5.0
|
|
||||||
- CXXFLAGS=-pipe -O2
|
|
||||||
commands:
|
|
||||||
- rm /etc/apt/apt.conf.d/docker-clean
|
|
||||||
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
|
|
||||||
- echo "deb http://deb.debian.org/debian stretch-backports main" >> /etc/apt/sources.list.d/stretch.list
|
|
||||||
- apt-get update -q
|
|
||||||
- apt-get install -qy -t stretch-backports clang-5.0
|
|
||||||
- apt-get install -qy cmake pkg-config
|
|
||||||
- apt-get install -qy libconfig++-dev libxdg-basedir-dev asciidoc
|
|
||||||
- rm -rf build && mkdir -p build && cd build
|
|
||||||
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
|
|
||||||
- make VERBOSE=1
|
|
||||||
volumes:
|
|
||||||
- /var/cache/debian-package-cache:/var/cache/apt/archives
|
|
||||||
|
|
||||||
clang6:
|
- name: gcc5
|
||||||
image: debian:stretch-slim
|
image: debian:stretch-slim
|
||||||
pull: true
|
pull: always
|
||||||
when:
|
environment:
|
||||||
event: [push, pull_request]
|
LANG: C.utf8
|
||||||
environment:
|
CXX: g++-5
|
||||||
- LANG=C.utf8
|
CXXFLAGS: -pipe -O2
|
||||||
- CXX=clang++-6.0
|
commands:
|
||||||
- CXXFLAGS=-pipe -O2
|
- rm /etc/apt/apt.conf.d/docker-clean
|
||||||
commands:
|
- apt-get update -q
|
||||||
- rm /etc/apt/apt.conf.d/docker-clean
|
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
|
||||||
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
|
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
|
||||||
- echo "deb http://deb.debian.org/debian stretch-backports main" >> /etc/apt/sources.list.d/stretch.list
|
- apt-get install -qy gnupg
|
||||||
- apt-get update -q
|
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0x60c317803a41ba51845e371a1e9377a2ba9ef27f
|
||||||
- apt-get install -qy -t stretch-backports clang-6.0
|
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
|
||||||
- apt-get install -qy cmake pkg-config
|
- apt-get update -q
|
||||||
- apt-get install -qy libconfig++-dev libxdg-basedir-dev asciidoc
|
- apt-get install -qy -t xenial g++-5
|
||||||
- rm -rf build && mkdir -p build && cd build
|
- apt-get install -qy cmake pkg-config
|
||||||
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
|
- apt-get install -qy libconfig++-dev libxdg-basedir-dev asciidoc
|
||||||
- make VERBOSE=1
|
- rm -rf build && mkdir -p build && cd build
|
||||||
volumes:
|
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
|
||||||
- /var/cache/debian-package-cache:/var/cache/apt/archives
|
- make VERBOSE=1
|
||||||
|
volumes:
|
||||||
|
- name: debian-package-cache
|
||||||
|
path: /var/cache/apt/archives
|
||||||
|
|
||||||
notify:
|
- name: gcc9
|
||||||
image: drillster/drone-email
|
image: debian:stretch-slim
|
||||||
pull: true
|
pull: always
|
||||||
|
environment:
|
||||||
|
LANG: C.utf8
|
||||||
|
CXX: g++-9
|
||||||
|
CXXFLAGS: -pipe -O2
|
||||||
|
commands:
|
||||||
|
- rm /etc/apt/apt.conf.d/docker-clean
|
||||||
|
- apt-get update -q
|
||||||
|
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
|
||||||
|
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
|
||||||
|
- apt-get install -qy gnupg
|
||||||
|
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0x60c317803a41ba51845e371a1e9377a2ba9ef27f
|
||||||
|
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
|
||||||
|
- apt-get update -q
|
||||||
|
- apt-get install -qy -t xenial g++-9
|
||||||
|
- apt-get install -qy cmake pkg-config
|
||||||
|
- apt-get install -qy libconfig++-dev libxdg-basedir-dev asciidoc
|
||||||
|
- rm -rf build && mkdir -p build && cd build
|
||||||
|
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
|
||||||
|
- make VERBOSE=1
|
||||||
|
volumes:
|
||||||
|
- name: debian-package-cache
|
||||||
|
path: /var/cache/apt/archives
|
||||||
|
|
||||||
|
- name: clang3
|
||||||
|
image: debian:stretch-slim
|
||||||
|
pull: always
|
||||||
|
environment:
|
||||||
|
LANG: C.utf8
|
||||||
|
CXX: clang++
|
||||||
|
CXXFLAGS: -pipe -O2
|
||||||
|
commands:
|
||||||
|
- rm /etc/apt/apt.conf.d/docker-clean
|
||||||
|
- apt-get update -q
|
||||||
|
- apt-get install -qy clang cmake pkg-config
|
||||||
|
- apt-get install -qy libconfig++-dev libxdg-basedir-dev asciidoc
|
||||||
|
- rm -rf build && mkdir -p build && cd build
|
||||||
|
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
|
||||||
|
- make VERBOSE=1
|
||||||
|
volumes:
|
||||||
|
- name: debian-package-cache
|
||||||
|
path: /var/cache/apt/archives
|
||||||
|
|
||||||
|
- name: clang6
|
||||||
|
image: debian:stretch-slim
|
||||||
|
pull: always
|
||||||
|
environment:
|
||||||
|
LANG: C.utf8
|
||||||
|
CXX: clang++-6.0
|
||||||
|
CXXFLAGS: -pipe -O2
|
||||||
|
commands:
|
||||||
|
- rm /etc/apt/apt.conf.d/docker-clean
|
||||||
|
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
|
||||||
|
- echo "deb http://deb.debian.org/debian stretch-backports main" >> /etc/apt/sources.list.d/stretch.list
|
||||||
|
- apt-get update -q
|
||||||
|
- apt-get install -qy -t stretch-backports clang-6.0
|
||||||
|
- apt-get install -qy cmake pkg-config
|
||||||
|
- apt-get install -qy libconfig++-dev libxdg-basedir-dev asciidoc
|
||||||
|
- rm -rf build && mkdir -p build && cd build
|
||||||
|
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
|
||||||
|
- make VERBOSE=1
|
||||||
|
volumes:
|
||||||
|
- name: debian-package-cache
|
||||||
|
path: /var/cache/apt/archives
|
||||||
|
|
||||||
|
- name: notify
|
||||||
|
image: drillster/drone-email
|
||||||
|
pull: always
|
||||||
|
settings:
|
||||||
host: cryptoparty-celle.de
|
host: cryptoparty-celle.de
|
||||||
secrets: [ email_username, email_password ]
|
|
||||||
from: drone@tzend.de
|
from: drone@tzend.de
|
||||||
when:
|
username:
|
||||||
status: [ changed, failure ]
|
from_secret: email_username
|
||||||
|
password:
|
||||||
|
from_secret: email_password
|
||||||
|
when:
|
||||||
|
status: [ changed, failure ]
|
||||||
|
|
|
@ -1,50 +1,47 @@
|
||||||
cmake_minimum_required (VERSION 3.2)
|
# Support version 3.6 and above, but use policy settings up to 3.14.
|
||||||
project(compilescript
|
# 3.6 is needed because of IMPORTED_TARGET in pkg_check_modules().
|
||||||
VERSION 0.4.0
|
cmake_minimum_required(VERSION 3.6...3.14)
|
||||||
LANGUAGES CXX
|
# Ranges are supported from 3.12, set policy to current for < 3.12.
|
||||||
)
|
if(${CMAKE_VERSION} VERSION_LESS 3.12)
|
||||||
|
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
||||||
|
endif()
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
project(compilescript
|
||||||
find_package(PkgConfig REQUIRED)
|
VERSION 0.4.1
|
||||||
pkg_check_modules(LIBXDG_BASEDIR REQUIRED libxdg-basedir)
|
LANGUAGES CXX)
|
||||||
pkg_check_modules(LIBCONFIG REQUIRED libconfig++)
|
# DESCRIPTION was introduced in version 3.9.
|
||||||
|
if(NOT (${CMAKE_VERSION} VERSION_LESS 3.9))
|
||||||
|
set(PROJECT_DESCRIPTION
|
||||||
|
"Execute source files from compiled languages as scripts.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
option(WITH_MAN "Compile and install manpage." YES)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 14)
|
set(CMAKE_CXX_STANDARD 14)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG
|
set(DEBUG_CXXFLAGS
|
||||||
"${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -Wpedantic -ftrapv -fsanitize=undefined -g -Og -fno-omit-frame-pointer")
|
"-Wall"
|
||||||
|
"-Wextra"
|
||||||
include_directories(${PROJECT_BINARY_DIR})
|
"-Wpedantic"
|
||||||
include_directories(${LIBXDG_BASEDIR_INCLUDE_DIRS})
|
"-ftrapv"
|
||||||
include_directories(${LIBCONFIG_INCLUDE_DIRS})
|
"-fsanitize=undefined"
|
||||||
|
"-g"
|
||||||
link_directories(${LIBXDG_BASEDIR_LIBRARY_DIRS})
|
"-Og"
|
||||||
link_directories(${LIBCONFIG_LIBRARY_DIRS})
|
"-fno-omit-frame-pointer")
|
||||||
|
set(DEBUG_LDFLAGS
|
||||||
# Write version in header
|
"-fsanitize=undefined")
|
||||||
configure_file(
|
add_compile_options("$<$<CONFIG:Debug>:${DEBUG_CXXFLAGS}>")
|
||||||
"${PROJECT_SOURCE_DIR}/src/version.hpp.in"
|
# add_link_options was introduced in version 3.13.
|
||||||
"${PROJECT_BINARY_DIR}/version.hpp"
|
if(${CMAKE_VERSION} VERSION_LESS 3.13)
|
||||||
)
|
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${DEBUG_LDFLAGS}")
|
||||||
|
else()
|
||||||
file(GLOB sources src/*.cpp)
|
add_link_options("$<$<CONFIG:Debug>:${DEBUG_LDFLAGS}>")
|
||||||
add_executable(${CMAKE_PROJECT_NAME} "${sources}")
|
endif()
|
||||||
target_link_libraries(${CMAKE_PROJECT_NAME}
|
|
||||||
"${LIBXDG_BASEDIR_LDFLAGS} ${LIBCONFIG_LDFLAGS}"
|
add_subdirectory(src)
|
||||||
"-lstdc++fs")
|
|
||||||
install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
|
if (WITH_MAN)
|
||||||
|
add_subdirectory(man)
|
||||||
set(WITH_MAN "YES" CACHE STRING "WITH_MAN defaults to \"YES\"")
|
|
||||||
if (WITH_MAN)
|
|
||||||
add_custom_command(OUTPUT "${PROJECT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.1"
|
|
||||||
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
|
|
||||||
DEPENDS "${CMAKE_SOURCE_DIR}/${CMAKE_PROJECT_NAME}.1.adoc"
|
|
||||||
COMMAND ${CMAKE_SOURCE_DIR}/build_manpage.sh
|
|
||||||
ARGS ${PROJECT_VERSION})
|
|
||||||
add_custom_target(run ALL
|
|
||||||
DEPENDS "${PROJECT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.1")
|
|
||||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.1
|
|
||||||
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
10
README.adoc
10
README.adoc
|
@ -1,7 +1,7 @@
|
||||||
= compilescript
|
= compilescript
|
||||||
|
|
||||||
**compilescript** allows you to execute files from compiled languages as
|
*compilescript* allows you to execute files from compiled languages like scripts.
|
||||||
scripts. By default it uses `g++`.
|
By default it uses `g++`.
|
||||||
|
|
||||||
It compiles the source file, stores the binary in
|
It compiles the source file, stores the binary in
|
||||||
`${XDG_CACHE_HOME}/compilescript/` and executes it. If the binary in cache is
|
`${XDG_CACHE_HOME}/compilescript/` and executes it. If the binary in cache is
|
||||||
|
@ -9,7 +9,7 @@ newer than the source file, the compilation is skipped.
|
||||||
|
|
||||||
== Usage
|
== Usage
|
||||||
|
|
||||||
Have a look at the https://schlomp.space/tastytea/compilescript/src/branch/master/compilescript.1.adoc[manpage].
|
Have a look at the https://schlomp.space/tastytea/compilescript/src/branch/main/man/compilescript.1.adoc[manpage].
|
||||||
|
|
||||||
== Install
|
== Install
|
||||||
|
|
||||||
|
@ -22,8 +22,8 @@ https://schlomp.space/tastytea/overlay[repository].
|
||||||
|
|
||||||
==== Dependencies
|
==== Dependencies
|
||||||
|
|
||||||
* C++ compiler (tested: https://gcc.gnu.org/[gcc] 5/6/7/8,
|
* C++ compiler (tested: https://gcc.gnu.org/[gcc] 5/6/8/9,
|
||||||
https://llvm.org/[clang] 3/5/6)
|
https://llvm.org/[clang] 3/6)
|
||||||
* https://cmake.org/[cmake] (at least 3.2)
|
* https://cmake.org/[cmake] (at least 3.2)
|
||||||
* http://repo.or.cz/w/libxdg-basedir.git[libxdg-basedir] (tested: 1.2)
|
* http://repo.or.cz/w/libxdg-basedir.git[libxdg-basedir] (tested: 1.2)
|
||||||
* https://github.com/hyperrealm/libconfig[libconfig++] (tested: 1.5)
|
* https://github.com/hyperrealm/libconfig[libconfig++] (tested: 1.5)
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.1"
|
||||||
|
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
|
||||||
|
DEPENDS "${PROJECT_NAME}.1.adoc"
|
||||||
|
COMMAND "${PROJECT_SOURCE_DIR}/man/build_manpage.sh"
|
||||||
|
ARGS "${PROJECT_VERSION}")
|
||||||
|
|
||||||
|
add_custom_target(man ALL
|
||||||
|
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.1")
|
||||||
|
|
||||||
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.1
|
||||||
|
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
|
|
@ -3,9 +3,10 @@
|
||||||
name="compilescript"
|
name="compilescript"
|
||||||
|
|
||||||
if [ -n "${1}" ]; then
|
if [ -n "${1}" ]; then
|
||||||
dir="$(dirname ${0})"
|
dir=$(dirname "${0}")
|
||||||
|
version=${1}
|
||||||
cp -vf "${dir}/${name}.1.adoc" .
|
cp -vf "${dir}/${name}.1.adoc" .
|
||||||
sed -Ei "s/(Revision: +)[0-9]+\.[0-9]\.[0-9]/\1${1}/" "${name}.1.adoc"
|
sed -Ei "s/(Revision: +)[0-9]+\.[0-9]\.[0-9]/\1${version}/" "${name}.1.adoc"
|
||||||
a2x --doctype manpage --format manpage --no-xmllint "${name}.1.adoc"
|
a2x --doctype manpage --format manpage --no-xmllint "${name}.1.adoc"
|
||||||
else
|
else
|
||||||
echo "usage: ${0} VERSION" >&2
|
echo "usage: ${0} VERSION" >&2
|
|
@ -1,7 +1,8 @@
|
||||||
= compilescript(1)
|
= compilescript(1)
|
||||||
|
:doctype: manpage
|
||||||
:Author: tastytea
|
:Author: tastytea
|
||||||
:Email: tastytea@tastytea.de
|
:Email: tastytea@tastytea.de
|
||||||
:Date: 2019-01-25
|
:Date: 2019-10-10
|
||||||
:Revision: 0.0.0
|
:Revision: 0.0.0
|
||||||
:man source: compilescript
|
:man source: compilescript
|
||||||
:man version: {revision}
|
:man version: {revision}
|
||||||
|
@ -9,7 +10,7 @@
|
||||||
|
|
||||||
== NAME
|
== NAME
|
||||||
|
|
||||||
compilescript - allows you to execute files from compiled languages as scripts.
|
compilescript - Execute source files from compiled languages as scripts.
|
||||||
|
|
||||||
== SYNOPSIS
|
== SYNOPSIS
|
||||||
|
|
||||||
|
@ -35,11 +36,15 @@ The compiler invocation looks like this: <configured compiler> <source file>
|
||||||
|
|
||||||
== OPTIONS
|
== OPTIONS
|
||||||
|
|
||||||
[frame="none",grid="none"]
|
*--cleanup*::
|
||||||
|===
|
Delete old cache files. You can configure the timespan after which a file is
|
||||||
|*--cleanup* | Delete old cache files (older than +clean_after_hours+).
|
considered old with the config option _clean_after_hours_.
|
||||||
|*--version* | Print version, copyright and license.
|
|
||||||
|===
|
*--compiler* _command_::
|
||||||
|
Override compiler command. Note that *--compiler*=_command_ does NOT work.
|
||||||
|
|
||||||
|
*--version*::
|
||||||
|
Print version, copyright and license.
|
||||||
|
|
||||||
== EXAMPLES
|
== EXAMPLES
|
||||||
|
|
||||||
|
@ -72,11 +77,8 @@ cache_dir = "/home/user/.cache/compilescript";
|
||||||
|
|
||||||
== FILES
|
== FILES
|
||||||
|
|
||||||
[format="csv",frame="none",grid="none",cols=">,<"]
|
- *Configuration file*: `${XDG_CONFIG_HOME}/compilescript.cfg`
|
||||||
|======
|
- *Cache*: `${XDG_CACHE_HOME}/compilescript/`
|
||||||
Configuration file:,`${XDG_CONFIG_HOME}/compilescript.cfg`
|
|
||||||
Cache:,`${XDG_CACHE_HOME}/compilescript/`
|
|
||||||
|======
|
|
||||||
|
|
||||||
`${XDG_CONFIG_HOME}` is usually `~/.config` and `${XDG_CACHE_HOME}` is usually
|
`${XDG_CONFIG_HOME}` is usually `~/.config` and `${XDG_CACHE_HOME}` is usually
|
||||||
`~/.cache`.
|
`~/.cache`.
|
|
@ -0,0 +1,22 @@
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_check_modules(libxdg-basedir REQUIRED IMPORTED_TARGET libxdg-basedir)
|
||||||
|
pkg_check_modules(libconfig++ REQUIRED IMPORTED_TARGET libconfig++)
|
||||||
|
|
||||||
|
# Write version in header
|
||||||
|
configure_file("version.hpp.in" "${CMAKE_CURRENT_BINARY_DIR}/version.hpp")
|
||||||
|
|
||||||
|
set(sources "main.cpp" "../xdgcfg/src/xdgcfg.cpp")
|
||||||
|
|
||||||
|
add_executable(${CMAKE_PROJECT_NAME} "${sources}")
|
||||||
|
|
||||||
|
target_include_directories(${PROJECT_NAME}
|
||||||
|
PRIVATE
|
||||||
|
"${PROJECT_SOURCE_DIR}/xdgcfg/include"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}")
|
||||||
|
|
||||||
|
target_link_libraries(${CMAKE_PROJECT_NAME}
|
||||||
|
PRIVATE PkgConfig::libxdg-basedir PkgConfig::libconfig++ stdc++fs)
|
||||||
|
|
||||||
|
install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
253
src/main.cpp
253
src/main.cpp
|
@ -14,40 +14,63 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if __cplusplus >= 201703L
|
#include "version.hpp"
|
||||||
#include <filesystem>
|
#include "xdgcfg.hpp"
|
||||||
#else
|
|
||||||
#include <experimental/filesystem>
|
|
||||||
#endif
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include <fstream>
|
|
||||||
#include <chrono>
|
|
||||||
#include <system_error>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <libconfig.h++>
|
#include <libconfig.h++>
|
||||||
#include <basedir.h>
|
#include <basedir.h>
|
||||||
#include "xdgcfg.hpp"
|
#include <unistd.h>
|
||||||
#include "version.hpp"
|
#include <chrono>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <exception>
|
||||||
|
#include <experimental/filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
#include <system_error>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#if __cplusplus >= 201703L
|
namespace fs = std::experimental::filesystem;
|
||||||
namespace fs = std::filesystem;
|
|
||||||
#else
|
|
||||||
namespace fs = std::experimental::filesystem;
|
|
||||||
#endif
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using std::chrono::system_clock;
|
using std::chrono::system_clock;
|
||||||
using std::chrono::hours;
|
using std::chrono::hours;
|
||||||
using std::chrono::duration_cast;
|
using std::chrono::duration_cast;
|
||||||
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
|
|
||||||
string compiler = "g++ -x c++";
|
class Compilescript
|
||||||
fs::path cache_dir;
|
{
|
||||||
int clean_after_hours = 30 * 24;
|
private:
|
||||||
|
string _compiler;
|
||||||
|
fs::path _cache_dir;
|
||||||
|
int _clean_after_hours;
|
||||||
|
|
||||||
bool read_settings()
|
public:
|
||||||
|
Compilescript();
|
||||||
|
|
||||||
|
//! Read settings and set member variables.
|
||||||
|
void read_settings();
|
||||||
|
//! Remove files older than `_clean_after_hours` from the cache.
|
||||||
|
void cleanup();
|
||||||
|
//! Compile `filename` if necessary and return filename of binary.
|
||||||
|
string compile(const string &filename);
|
||||||
|
//! Run binary. Pass original `argv`, the 1st entry is ignored.
|
||||||
|
void run(const string &filename, char *argv[]);
|
||||||
|
//! Print version, copyright and license.
|
||||||
|
void print_version();
|
||||||
|
//! Set compiler command.
|
||||||
|
void set_compiler(const string &command);
|
||||||
|
};
|
||||||
|
|
||||||
|
Compilescript::Compilescript()
|
||||||
|
: _compiler("g++ -x c++")
|
||||||
|
, _clean_after_hours(30 * 24)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
void Compilescript::read_settings()
|
||||||
{
|
{
|
||||||
bool need_save = false;
|
bool need_save = false;
|
||||||
xdgcfg config("compilescript.cfg");
|
xdgcfg config("compilescript.cfg");
|
||||||
|
@ -56,105 +79,79 @@ bool read_settings()
|
||||||
|
|
||||||
if (cfg.exists("compiler"))
|
if (cfg.exists("compiler"))
|
||||||
{
|
{
|
||||||
compiler = cfg["compiler"].c_str();
|
_compiler = cfg["compiler"].c_str();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cfg.add("compiler", libconfig::Setting::TypeString) = compiler;
|
cfg.add("compiler", libconfig::Setting::TypeString) = _compiler;
|
||||||
need_save = true;
|
need_save = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg.exists("clean_after_hours"))
|
if (cfg.exists("clean_after_hours"))
|
||||||
{
|
{
|
||||||
cfg.lookupValue("clean_after_hours", clean_after_hours);
|
cfg.lookupValue("clean_after_hours", _clean_after_hours);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cfg.add("clean_after_hours",
|
cfg.add("clean_after_hours",
|
||||||
libconfig::Setting::TypeInt) = clean_after_hours;
|
libconfig::Setting::TypeInt) = _clean_after_hours;
|
||||||
need_save = true;
|
need_save = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg.exists("cache_dir"))
|
if (cfg.exists("cache_dir"))
|
||||||
{
|
{
|
||||||
cache_dir = cfg["cache_dir"].c_str();
|
_cache_dir = cfg["cache_dir"].c_str();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xdgHandle xdg;
|
xdgHandle xdg;
|
||||||
xdgInitHandle(&xdg);
|
xdgInitHandle(&xdg);
|
||||||
cache_dir = xdgCacheHome(&xdg);
|
_cache_dir = xdgCacheHome(&xdg);
|
||||||
cache_dir /= "compilescript";
|
_cache_dir /= "compilescript";
|
||||||
xdgWipeHandle(&xdg);
|
xdgWipeHandle(&xdg);
|
||||||
}
|
}
|
||||||
if (!fs::is_directory(cache_dir))
|
if (!fs::is_directory(_cache_dir))
|
||||||
{
|
{
|
||||||
fs::create_directories(cache_dir);
|
fs::create_directories(_cache_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (need_save)
|
if (need_save)
|
||||||
{
|
{
|
||||||
config.write();
|
config.write();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanup()
|
void Compilescript::cleanup()
|
||||||
{
|
{
|
||||||
for (const fs::directory_entry &entry
|
for (const auto &entry : fs::recursive_directory_iterator(_cache_dir))
|
||||||
: fs::recursive_directory_iterator(cache_dir))
|
|
||||||
{
|
{
|
||||||
if (fs::is_regular_file(entry))
|
if (!fs::is_regular_file(entry))
|
||||||
{
|
{
|
||||||
auto diff = system_clock::now() - fs::last_write_time(entry);
|
continue;
|
||||||
if (duration_cast<hours>(diff).count() > clean_after_hours)
|
}
|
||||||
{
|
|
||||||
fs::path current_path = entry.path();
|
|
||||||
std::error_code e;
|
|
||||||
|
|
||||||
while (fs::remove(current_path, e))
|
const auto diff = system_clock::now() - fs::last_write_time(entry);
|
||||||
|
if (duration_cast<hours>(diff).count() > _clean_after_hours)
|
||||||
|
{
|
||||||
|
fs::path current_path = entry.path();
|
||||||
|
std::error_code e;
|
||||||
|
|
||||||
|
while (fs::remove(current_path, e))
|
||||||
|
{
|
||||||
|
current_path = current_path.parent_path();
|
||||||
|
if (current_path == _cache_dir)
|
||||||
{
|
{
|
||||||
current_path = current_path.parent_path();
|
break;
|
||||||
if (current_path == cache_dir)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
string Compilescript::compile(const string &filename)
|
||||||
{
|
{
|
||||||
if (!read_settings())
|
const fs::path original = fs::canonical(filename);
|
||||||
{
|
const fs::path source = _cache_dir / original;
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argc <= 1)
|
|
||||||
{
|
|
||||||
cerr << "usage: " << argv[0] << " [file|--cleanup|--version] [arguments]\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (string(argv[1]) == "--cleanup")
|
|
||||||
{
|
|
||||||
cleanup();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (string(argv[1]) == "--version")
|
|
||||||
{
|
|
||||||
cout << "compilescript " << global::version << endl <<
|
|
||||||
"Copyright (C) 2018, 2019 tastytea <tastytea@tastytea.de>\n"
|
|
||||||
"License GPLv3: GNU GPL version 3 <https://www.gnu.org/licenses/gpl-3.0.html>.\n"
|
|
||||||
"This is free software: you are free to change and redistribute it.\n"
|
|
||||||
"There is NO WARRANTY, to the extent permitted by law.\n";
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fs::path original = fs::canonical(argv[1]);
|
|
||||||
const fs::path source = cache_dir / original;
|
|
||||||
const fs::path binary = (source.string() + ".bin");
|
const fs::path binary = (source.string() + ".bin");
|
||||||
string compiler_arguments;
|
string compiler_arguments;
|
||||||
fs::create_directories(binary.parent_path());
|
fs::create_directories(binary.parent_path());
|
||||||
|
@ -177,14 +174,11 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
std::getline(in, buf);
|
std::getline(in, buf);
|
||||||
if (buf.substr(0, 16) == "//compilescript:")
|
const std::regex re("^(//|#|;) ?compilescript:");
|
||||||
|
std::smatch match;
|
||||||
|
if (std::regex_search(buf, match, re))
|
||||||
{
|
{
|
||||||
compiler_arguments = buf.substr(16);
|
compiler_arguments = match.suffix();
|
||||||
}
|
|
||||||
else if ((buf.substr(0, 15) == "#compilescript:") ||
|
|
||||||
(buf.substr(0, 15) == ";compilescript:"))
|
|
||||||
{
|
|
||||||
compiler_arguments = buf.substr(15);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -202,26 +196,99 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cerr << "ERROR: Could not open file: " << source << endl;
|
throw std::runtime_error("Could not open file: "
|
||||||
return 1;
|
+ source.string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cerr << "ERROR: Could not open file: " << original << endl;
|
throw std::runtime_error("Could not open file: "
|
||||||
return 1;
|
+ original.string());
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = std::system((compiler + " " + source.string() + " "
|
const string command = _compiler + " " + source.string() + " "
|
||||||
+ compiler_arguments + " -o " + binary.string()).c_str());
|
+ compiler_arguments + " -o " + binary.string();
|
||||||
|
int ret = std::system(command.c_str()); // NOLINT(cert-env33-c)
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
cerr << "ERROR: Compilation failed.\n";
|
throw std::runtime_error("Compilation failed.");
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
execv(binary.c_str(), &argv[1]);
|
return binary.string();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Compilescript::run(const string &filename, char *argv[])
|
||||||
|
{
|
||||||
|
execvp(filename.c_str(), argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Compilescript::print_version()
|
||||||
|
{
|
||||||
|
cout << "compilescript " << global::version << '\n' <<
|
||||||
|
"Copyright (C) 2018, 2019 tastytea <tastytea@tastytea.de>\n"
|
||||||
|
"License GPLv3: GNU GPL version 3 "
|
||||||
|
"<https://www.gnu.org/licenses/gpl-3.0.html>.\n"
|
||||||
|
"This program comes with ABSOLUTELY NO WARRANTY. This is free software,"
|
||||||
|
"\nand you are welcome to redistribute it under certain conditions.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void Compilescript::set_compiler(const string &command)
|
||||||
|
{
|
||||||
|
_compiler = command;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
const vector<string> args(argv, argv + argc);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Compilescript App;
|
||||||
|
App.read_settings();
|
||||||
|
|
||||||
|
if (args.size() <= 1)
|
||||||
|
{
|
||||||
|
cerr << "usage: " << args[0]
|
||||||
|
<< " [file|--cleanup|--version|--compiler command] "
|
||||||
|
<< "[arguments]\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (args[1] == "--cleanup")
|
||||||
|
{
|
||||||
|
App.cleanup();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (args[1] == "--version")
|
||||||
|
{
|
||||||
|
App.print_version();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (args[1] == "--compiler")
|
||||||
|
{
|
||||||
|
if (args.size() <= 3)
|
||||||
|
{
|
||||||
|
cerr << "Error: You need to specify a command.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
App.set_compiler(args[2]);
|
||||||
|
const string binary = App.compile(args[3]);
|
||||||
|
// We know that argv[3] exists.
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||||
|
App.run(binary, &argv[3]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const string binary = App.compile(args[1]);
|
||||||
|
// We know that argv[1] exists.
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||||
|
App.run(binary, &argv[1]);
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
cerr << "Error: " << e.what() << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
namespace global
|
namespace global
|
||||||
{
|
{
|
||||||
static constexpr char version[] = "@PROJECT_VERSION@";
|
static constexpr char version[] = "@PROJECT_VERSION@";
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // VERSION_HPP
|
#endif // VERSION_HPP
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
../xdgcfg/src/xdgcfg.cpp
|
|
|
@ -1 +0,0 @@
|
||||||
../xdgcfg/src/xdgcfg.hpp
|
|
2
xdgcfg
2
xdgcfg
|
@ -1 +1 @@
|
||||||
Subproject commit e22f82fc6f1c40cda3d3ce5e671299f26f622528
|
Subproject commit 9337964266ae55415beaa7f517cc4240a259289a
|
Reference in New Issue