diff --git a/README b/README index 2d76eae..37e9211 100644 --- a/README +++ b/README @@ -1,18 +1,38 @@ +Starter Kit Maker Created By: maxxtepper -This is not the only way to use this tool, it is simply an example. - Instructions: -1. Establish a user bin - $ mkdir $HOME/bin -2. Create symlink of file in bin - $ ln -s /full-path/git_begin $HOME/bin/. -3. Add the following line at the end of $HOME/.bashrc - export PATH="$HOME/bin:$PATH" +1. Install direnv + $ sudo apt install direnv + $ echo "eval \"\$(direnv hook bash)\"" >> $HOME/.bashrc +2. Install bazel + *go to bazel getting started and follow instructions + $ sudo apt install bazel + $ echo "export PATH=\"\$HOME/bin:\$PATH\"" >> $HOME/.bashrc +3. Git clone the repo + $ git clone https://github.com/maxxtepper/starter_kit_maker.git + $ cd starter_kit_maker +4. Establish a user bin up to the following: + $ mkdir -p $HOME/bin/starter_kit_maker/bin/bazel/cc-temp +5. Install the contents of the local repo cc-temp into the user bin cc-temp + $ cp -r ./bin/bazel/cc_temp/* $HOME/bin/starter_kit_maker/bin/bazel/cc-temp +6. Create symlink of scripts in bin + $ ln -s /full-path/git_begin $HOME/bin/. + $ ln -s /full-path/bin/object_maker $HOME/bin/. + $ ln -s /full-path/git_bzl_cc $HOME/bin/. + $ ln -s /full-path/bin/bazel/cc_bzl_obj $HOME/bin/. +7. Create $HOME/.bazelrc + $ Add the following: + build --cxxopt='-std=c++17' + test --cxxopt='-std=c++17' --test_output=all -Example Usage: +Example Usage (no bazel): $ git_begin project_name object0 object1 +Example Usage (with bazel): +$ git_bzl_cc project_name object0 object1 + After git_begin, the next string will be the name of the project, and every string after that will be objects named after the strings themselves -Symlink allows you to edit the git_begin file in the repo to keep the executable up-to-date +*Symlink allows you to edit/update the scripts in the repo while keeping the executable pointing to it +*Template files in local bin can be edited as needed diff --git a/bin/bazel/bzl_obj_chng b/bin/bazel/bzl_obj_chng new file mode 100644 index 0000000..0f3b23b --- /dev/null +++ b/bin/bazel/bzl_obj_chng @@ -0,0 +1,9 @@ +#!/bin/bash + +# Get variables +OBJECT=$1 +VARS=".vars" + +# Go into VARS, find the input +# And change all instances of +# the input, in all files, and in all directories. diff --git a/bin/bazel/cc-temp/WORKSPACE b/bin/bazel/cc-temp/WORKSPACE new file mode 100644 index 0000000..b54973d --- /dev/null +++ b/bin/bazel/cc-temp/WORKSPACE @@ -0,0 +1,7 @@ +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + +git_repository( + name = "googletest", + remote = "https://github.com/google/googletest", + tag = "release-1.10.0", +) diff --git a/bin/bazel/cc-temp/src/lib/BUILD b/bin/bazel/cc-temp/src/lib/BUILD new file mode 100644 index 0000000..4ceeac8 --- /dev/null +++ b/bin/bazel/cc-temp/src/lib/BUILD @@ -0,0 +1,7 @@ +# https://docs.bazel.build/versions/master/be/c-cpp.html#cc_library +cc_library( + name = "ThisLib", + srcs = glob(["**/*.cc"]), + hdrs = glob(["**/*.h"]), + visibility = ["//visibility:public"], +) diff --git a/bin/bazel/cc-temp/src/main/BUILD b/bin/bazel/cc-temp/src/main/BUILD new file mode 100644 index 0000000..5950289 --- /dev/null +++ b/bin/bazel/cc-temp/src/main/BUILD @@ -0,0 +1,6 @@ +# https://docs.bazel.build/versions/master/be/c-cpp.html#cc_binary +cc_binary( + name = "main", + srcs = ["main.cc"], + deps = ["//src/lib:ThisLib"], +) diff --git a/bin/bazel/cc-temp/src/main/main.cc b/bin/bazel/cc-temp/src/main/main.cc new file mode 100644 index 0000000..99e4c80 --- /dev/null +++ b/bin/bazel/cc-temp/src/main/main.cc @@ -0,0 +1,10 @@ +#include +#include "src/lib/Greeting.h" + +int main() +{ + Greeting *greet = new Greeting(); + std::cout << greet->getGreetingMessage() << std::endl; + + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/bin/bazel/cc-temp/tests/BUILD b/bin/bazel/cc-temp/tests/BUILD new file mode 100644 index 0000000..804ff70 --- /dev/null +++ b/bin/bazel/cc-temp/tests/BUILD @@ -0,0 +1,8 @@ +cc_test( + name = "tests", + srcs = glob(["**/*.cc"]), + deps = [ + "//src/lib:ThisLib", + "@googletest//:gtest_main", + ], +) diff --git a/bin/bazel/cc-temp/tests/Greeting_test.cc b/bin/bazel/cc-temp/tests/Greeting_test.cc new file mode 100644 index 0000000..92e7794 --- /dev/null +++ b/bin/bazel/cc-temp/tests/Greeting_test.cc @@ -0,0 +1,9 @@ +#include "gtest/gtest.h" +#include "src/lib/Greeting.h" + +TEST(GreetingShould, ReturnHelloWorld){ + Greeting *greet = new Greeting(); + std::string actual = greet->getGreetingMessage(); + std::string expected = "Hello World!"; + EXPECT_EQ(expected, actual); +} \ No newline at end of file diff --git a/bin/bazel/cc-temp/tests/README.md b/bin/bazel/cc-temp/tests/README.md new file mode 100644 index 0000000..802f947 --- /dev/null +++ b/bin/bazel/cc-temp/tests/README.md @@ -0,0 +1 @@ +This repo contains the example file structure discussed in https://www.ratanparai.com/c++/writing-unit-tests-with-bazel/ diff --git a/bin/bazel/cc-temp/tests/WORKSPACE b/bin/bazel/cc-temp/tests/WORKSPACE new file mode 100644 index 0000000..b54973d --- /dev/null +++ b/bin/bazel/cc-temp/tests/WORKSPACE @@ -0,0 +1,7 @@ +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + +git_repository( + name = "googletest", + remote = "https://github.com/google/googletest", + tag = "release-1.10.0", +) diff --git a/bin/bazel/cc_bzl_obj b/bin/bazel/cc_bzl_obj new file mode 100755 index 0000000..727c6ee --- /dev/null +++ b/bin/bazel/cc_bzl_obj @@ -0,0 +1,54 @@ +#!/bin/bash + +# Get variables +OBJECT=$1 +VARS=".vars" + +# Which directory? +# This one for now +# MUST be in the directory where the files are going + +# Create object files +# Header +touch $OBJECT.h +HEADER=${PROJECT^^}"_SRC_LIB_"${OBJECT^^}"_H_" +echo "#ifndef $HEADER +#define $HEADER + +class $OBJECT { + public: + $OBJECT(); + ~$OBJECT(); + + private: +}; + +#endif" >> $OBJECT.h + +# Source +touch $OBJECT.cc +echo "#include \"$OBJECT.h\" + +$OBJECT::$OBJECT() { +} + +$OBJECT::~$OBJECT() { +}" >> $OBJECT.cc + +# Test +touch ${PROJPWD}/tests/${OBJECT}_test.cc +echo "#include +#include \"gtest/gtest.h\" +#include \"src/lib/$OBJECT.h\" + +TEST(${OBJECT}Should, ReturnSomething){ +/* + std::unique_ptr<$OBJECT> ${OBJECT,,} = std::make_unique<$OBJECT>(); + std::string actual = ${OBJECT,,}->DoSomething(); + std::string expected = "Something"; + EXPECT_EQ(expected, actual); +*/ +}" >> ${PROJPWD}/tests/${OBJECT}_test.cc + +# Object vars +echo "$OBJECT" >> $VARS diff --git a/bin/object_maker b/bin/object_maker index ddd0d82..836044a 100755 --- a/bin/object_maker +++ b/bin/object_maker @@ -10,8 +10,8 @@ OBJECT=$1 # Create object files # Header touch $OBJECT.h -echo "#ifndef $OBJECT.H -#define $OBJECT.H +echo "#ifndef ${OBJECT}_H +#define ${OBJECT}_H class $OBJECT { public: @@ -26,6 +26,7 @@ class $OBJECT { # Source touch $OBJECT.cc echo "#include \"$OBJECT.h\" + $OBJECT::$OBJECT() { } diff --git a/git_begin b/git_begin index d19fc5f..8f2ef28 100755 --- a/git_begin +++ b/git_begin @@ -40,37 +40,9 @@ clean: # Create Objects PWD=`pwd` COUNT=0 -for object in "$OBJECT"; do +for object in "$@"; do if [ $COUNT -ne 0 ]; then - # Make Object: item - touch $@.h - echo "#ifndef $@.H - #define $@.H - - class $@ { - public: - $@(); - ~$@(); - - private: - }; - - #endif" >> $@.h - - # Source - touch $@.cc - echo "#include \"$@.h\" - $@::$@() { - } - - $@::~$@() { - }" >> $@.cc - - # Add object to makefile - sed -i "/^OBJFILES/ s/$/$@.o /" Makefile - $HOME/bin/object_maker $object - # Increase Count - let COUNT=COUNT+1 + object_maker $object else # Skip first item (project name) let COUNT=COUNT+1 @@ -89,6 +61,23 @@ sed -i "/^OBJFILES/ s/$/main.o /" Makefile # Make first commit git init +echo "Project initialized..." +vim README +echo "README updated..." git add . +<<<<<<< HEAD git commit -m "First commit of $PROJECT" #git remote add origin https://github.com/$USER/$PROJECT.git +======= +git commit -m "First commit of $PROJECT: Check README" +git branch -m master develop +echo "develop branch created (HEAD)..." +git branch release +echo "release branch created..." +echo "First commit is set. Ready to push the develop branch..." +echo "Go to https://github.com/new and make a new repo with the project name: $PROJECT" +read -p "Press enter once done" +git remote add origin https://github.com/$USER/$PROJECT.git +git push origin develop +echo "Develop branch successfuly pushed. Release branch is ready for merge when a releaseable version of develop is ready! Happy Building!!" +>>>>>>> 6218677e29466891c4a07853dc69808df7b0231a diff --git a/git_bzl_cc b/git_bzl_cc new file mode 100755 index 0000000..362c28f --- /dev/null +++ b/git_bzl_cc @@ -0,0 +1,131 @@ +#!/bin/bash +# $1 = Project Name + +# Get variables +USER=$(git config --global user.name) +PROJECT=$1 +TEMP_SOURCE="$HOME/bin/starter_kit_maker/bin/bazel/cc-temp" + +# Create and enter git directory +if [ -d "$PROJECT" ]; then + echo "${PROJECT} directory already exists in this directory. Go to a different directory." + exit N +fi +mkdir $PROJECT +cd $PROJECT + +# Direnv setup +echo "export PROJECT=${PROJECT}" >> .envrc +echo "export PROJPWD=${PWD}" >> .envrc +direnv allow . + +# README +touch README +echo "This is the README for $PROJECT" >> README + +# Create dir tree +mkdir src +mkdir src/lib +mkdir src/main +mkdir tests + +# Create WORKSPACE +touch WORKSPACE +echo "# $PROJECT" > WORKSPACE +cat "$TEMP_SOURCE/WORKSPACE" >> WORKSPACE + +# Create BUILDS +touch src/lib/BUILD +cat "$TEMP_SOURCE/src/lib/BUILD" > src/lib/BUILD +touch src/main/BUILD +cat "$TEMP_SOURCE/src/main/BUILD" > src/main/BUILD +touch tests/BUILD +cat "$TEMP_SOURCE/tests/BUILD" > tests/BUILD + +# Create object instance +COUNT=0 +for item in "$@"; do + if [ $COUNT -ne 0 ]; then + # Header + touch src/lib/$item.h + HEADER=${PROJECT^^}"_SRC_LIB_"${item^^}"_H_" + echo "#ifndef $HEADER +#define $HEADER + +class $item { + public: + $item(); + ~$item(); + + private: +}; + +#endif" >> src/lib/$item.h + + # Source + touch src/lib/$item.cc + echo "#include \"$item.h\" +$item::$item() { +} + +$item::~$item() { +}" >> src/lib/$item.cc + + # Test + touch tests/${item}_test.cc + echo "#include +#include \"gtest/gtest.h\" +#include \"src/lib/$item.h\" + +TEST(${item}Should, ReturnSomething){ +/* + std::unique_ptr<$item> ${item,,} = std::make_unique<$item>(); + std::string actual = ${item,,}->DoSomething(); + std::string expected = "Something"; + EXPECT_EQ(expected, actual); +*/ +}" >> tests/${item}_test.cc + + # Object vars + echo "$item" >> $VARS + + # Increase Count + let COUNT=COUNT+1 + else + # Skip first item (project name) + let COUNT=COUNT+1 + fi +done + +# main +touch src/main/main.cc +echo "#include + +int main(int argc, char** argv) { + return 0; +}" >> src/main/main.cc + +# Make first commit +git init +echo "Project initialized..." +# README +vim README +echo "README updated..." +# .gitignore +touch .gitignore +echo "bazel*" >> .gitignore +# Add and commit +git add . +git commit -m "First commit of $PROJECT: Check README" +# Branch setup +git branch -m master develop +echo "develop branch created (HEAD)..." +git branch release +echo "release branch created..." +# Remote and push +echo "First commit is set. Ready to push the develop branch..." +echo "Go to https://github.com/new and make a new repo with the project name: $PROJECT" +read -p "Press enter once done" +git remote add origin https://github.com/$USER/$PROJECT.git +git push origin develop +echo "Develop branch successfuly pushed. Release branch is ready for merge when a releaseable version of develop is ready! Happy Building!!"