Skip to content

Commit 623fce4

Browse files
polytypicCI script
authored andcommitted
Enhanced init commands
1 parent d910a17 commit 623fce4

File tree

7 files changed

+69
-48
lines changed

7 files changed

+69
-48
lines changed

.cppsm/testing/add_subdirectory_test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ add_subdirectory(subdir)
77
EOF
88

99
mkdir subdir && cd "$_"
10-
git init
1110
cppsm init-hello
1211

1312
mkdir ../.build && cd "$_"

.cppsm/testing/hello_and_then_some_test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash -e
22

33
git init
4-
cppsm init-hello
4+
VERSION=v1 cppsm init-hello
55

66
git commit -m Initial
77

.cppsm/testing/init_library_test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash -e
22

3-
git init
43
cppsm init-library
54
CXX='' CC='' cppsm test

.cppsm/travis-ci

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ done
4040

4141
mkdir travis_ci_test && cd "$_"
4242

43-
git init
44-
cppsm init-hello
43+
NAME=hello cppsm init-hello
4544
git commit -m Initial
4645

4746
../travis-ci

commands/init

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,26 @@
33
# shellcheck source=.settings
44
. "${BASH_SOURCE%/*}/.settings"
55

6+
to-cpp() {
7+
echo "$1" | sed -e 's#[^a-zA-Z0-9_]#_#g' -e 's#__*#_#g' -e 's#^_##' -e 's#_$##'
8+
}
9+
610
if [ -z "$NAME" ]; then
7-
export NAME="${PWD##*/}"
11+
NAME="${PWD##*/}"
12+
fi
13+
NAME="$(to-cpp "$NAME")"
14+
15+
if [ -z "$VERSION" ]; then
16+
if git symbolic-ref --short HEAD > /dev/null 2>&1; then
17+
VERSION="$(git symbolic-ref --short HEAD)"
18+
fi
19+
fi
20+
if [ -z "$VERSION" ]; then
21+
VERSION="v1"
822
fi
9-
export VERSION="${VERSION:-v1}"
23+
VERSION="$(to-cpp "$VERSION")"
1024

11-
if [ "$#" -ne 0 ] || [ ! -d .git ] || \
12-
[ "$NAME" != "$(echo "$NAME" | grep -o '^[a-zA-Z0-9_]\+')" ] ; then
25+
if [ "$#" -ne 0 ]; then
1326
CMD="${0##*/}"
1427
cat << EOF
1528
Usage: $CMD
@@ -19,13 +32,20 @@ Options:
1932
NAME=$NAME|...
2033
VERSION=$VERSION|...
2134
22-
Initializes a new C++ project with cppsm configuration files or updates an
23-
existing project to use the latest configuration files. Run $CMD in the
24-
top-level directory of a fresh git project.
35+
Initializes a new project with cppsm configuration files when run in an empty
36+
directory or updates an existing project to use the latest configuration files.
2537
EOF
2638
exit 1
2739
fi
2840

41+
if [ ! -e .git ] || [ -z "$NAME" ] || [ -z "$VERSION" ]; then
42+
git init
43+
fi
44+
45+
if [ "$(git symbolic-ref --short HEAD)" != "$VERSION" ]; then
46+
git checkout -b "$VERSION"
47+
fi
48+
2949
if [ -n "$TRAVIS_BRANCH" ]; then
3050
CLI_BRANCH="$TRAVIS_BRANCH"
3151
else
@@ -43,15 +63,31 @@ if [ ! -d .cppsm ]; then
4363
git submodule "${GIT_QUIET[@]}" add --branch "$BOILERPLATE_BRANCH" "$BOILERPLATE_URL" .cppsm
4464
fi
4565

46-
ln -fs .cppsm/.clang-format .clang-format
47-
ln -fs .cppsm/.gitignore .gitignore
48-
ln -fs .cppsm/.prettierrc .prettierrc
66+
create-parent-dir() {
67+
local FILE="$1"
68+
if [[ "$FILE" =~ / ]]; then mkdir -p "${FILE%/*}"; fi
69+
}
70+
71+
add-link() {
72+
local FILE="$1"
73+
local LINK="$2"
74+
if [ ! -e "$LINK" ]; then
75+
create-parent-dir "$LINK"
76+
ln -fs "$FILE" "$LINK"
77+
git add "$LINK"
78+
fi
79+
}
80+
81+
add-link .cppsm/.clang-format .clang-format
82+
add-link .cppsm/.gitignore .gitignore
83+
add-link .cppsm/.prettierrc .prettierrc
4984

5085
add-file() {
51-
if [[ "$1" =~ / ]]; then mkdir -p "${1%/*}"; fi
52-
if [ ! -e "$1" ]; then
53-
cat > "$1"
54-
git add "$1"
86+
local FILE="$1"
87+
if [ ! -e "$FILE" ]; then
88+
create-parent-dir "$FILE"
89+
cat > "$FILE"
90+
git add "$FILE"
5591
fi
5692
}
5793

@@ -61,10 +97,4 @@ project($NAME)
6197
include(.cppsm/c++17.cmake)
6298
EOF
6399

64-
cp "$CPPSM/.travis.yml" .travis.yml
65-
66-
git add \
67-
.clang-format \
68-
.gitignore \
69-
.prettierrc \
70-
.travis.yml
100+
add-file .travis.yml < "$CPPSM/.travis.yml"

commands/init-hello

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,55 @@
33
# shellcheck source=init
44
. "${BASH_SOURCE%/*}/init"
55

6-
add-file provides/include/message_v1/hello.hpp << EOF
6+
add-file "provides/include/message_${VERSION}/hello.hpp" << EOF
77
#include <string>
88
9-
namespace message_v1 {
9+
namespace message_${VERSION} {
1010
1111
std::string hello(const std::string &to);
1212
1313
}
1414
EOF
1515

1616
add-file provides/library/hello.cpp << EOF
17-
#include "message_v1/hello.hpp"
17+
#include "message_${VERSION}/hello.hpp"
1818
19-
std::string message_v1::hello(const std::string &to) {
19+
std::string message_${VERSION}::hello(const std::string &to) {
2020
return "Hello, " + to + "!";
2121
}
2222
EOF
2323

2424
add-file provides/CMakeLists.txt << EOF
25-
add_conventional_library(message_v1)
25+
add_conventional_library(message_${VERSION})
2626
EOF
2727

2828
"$CPPSM/commands/add" equipment https://github.com/per-framework/testing.cpp.git v1
2929

3030
add-file internals/testing/message_test.cpp << EOF
31-
#include "message_v1/hello.hpp"
31+
#include "message_${VERSION}/hello.hpp"
3232
3333
#include "testing_v1/test.hpp"
3434
3535
using namespace testing_v1;
3636
3737
auto hello_test =
38-
test([]() { verify("Hello, there!" == message_v1::hello("there")); });
38+
test([]() { verify("Hello, there!" == message_${VERSION}::hello("there")); });
3939
EOF
4040

4141
add-file internals/program/hello.cpp << EOF
42-
#include "message_v1/hello.hpp"
42+
#include "message_${VERSION}/hello.hpp"
4343
4444
#include <iostream>
4545
4646
int main() {
47-
std::cout << message_v1::hello("world") << std::endl;
47+
std::cout << message_${VERSION}::hello("world") << std::endl;
4848
return 0;
4949
}
5050
EOF
5151

5252
add-file internals/CMakeLists.txt << EOF
53-
add_conventional_executable_tests(PRIVATE message_v1 testing_v1)
53+
add_conventional_executable_tests(PRIVATE message_${VERSION} testing_v1)
5454
5555
add_conventional_executable(hello)
56-
target_link_libraries(hello PRIVATE message_v1)
56+
target_link_libraries(hello PRIVATE message_${VERSION})
5757
EOF

commands/init-library

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,16 @@
33
# shellcheck source=init
44
. "${BASH_SOURCE%/*}/init"
55

6-
if [ -z "$VERSION" ]; then
7-
FULL_NAME="${NAME}"
8-
else
9-
FULL_NAME="${NAME}_${VERSION}"
10-
fi
11-
126
# Library boilerplate
137

148
add-file provides/CMakeLists.txt << EOF
15-
add_conventional_library($FULL_NAME)
9+
add_conventional_library(${NAME}_${VERSION})
1610
EOF
1711

18-
add-file "provides/include/$FULL_NAME/synopsis.hpp" << EOF
12+
add-file "provides/include/${NAME}_${VERSION}/synopsis.hpp" << EOF
1913
#pragma once
2014
21-
namespace $FULL_NAME {
15+
namespace ${NAME}_${VERSION} {
2216
2317
// TODO
2418
@@ -28,11 +22,11 @@ EOF
2822
# Testing boilerplate
2923

3024
add-file internals/CMakeLists.txt << EOF
31-
add_conventional_executable_tests(PRIVATE $FULL_NAME)
25+
add_conventional_executable_tests(PRIVATE ${NAME}_${VERSION})
3226
EOF
3327

3428
add-file internals/testing/compile_synopsis_test.cpp << EOF
35-
#include "$FULL_NAME/synopsis.hpp"
29+
#include "${NAME}_${VERSION}/synopsis.hpp"
3630
3731
int main() { return 0; }
3832
EOF

0 commit comments

Comments
 (0)