Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
32d7706
works; working on object maker
maxxtepper Jun 3, 2019
ffd9892
added more capability: creates develop and release branches and promp…
maxxtepper Jun 3, 2019
1c00c56
bazel-test cc -- must have bin setupgit add git_bzl_cc
maxxtepper Mar 21, 2020
b19d860
now in local bin
maxxtepper Mar 22, 2020
6218677
added bin
maxxtepper Mar 22, 2020
7210010
cpp-temp now included
maxxtepper Mar 22, 2020
d4c62aa
hm
maxxtepper Mar 22, 2020
278a268
Merge branch 'bazel' of https://github.com/maxxtepper/starter_kit_mak…
maxxtepper Mar 22, 2020
f474a0b
fixed cpp-template to cpp-temp
maxxtepper Mar 22, 2020
b87725e
went back to needing /home/maxx/bin/bazel/
maxxtepper Mar 22, 2020
73a00f1
added object maker for bazel
maxxtepper Mar 22, 2020
9908827
made name fixes; restructured where everything is
maxxtepper Mar 22, 2020
be7716f
fixed lib name for tests
maxxtepper Mar 22, 2020
44792c4
google header style -- need to update obj_maker
maxxtepper Mar 24, 2020
c46cc87
integrated direnv into projects -- PROJECT is now an env var and used…
maxxtepper Mar 24, 2020
387afa5
Merge branch 'release' of https://github.com/maxxtepper/starter_kit_m…
maxxtepper Mar 25, 2020
e51466d
added test file maker for objects
maxxtepper Mar 27, 2020
0be4b47
added <memory> to tests
maxxtepper Mar 27, 2020
ab932be
.gitignore for bazel*
maxxtepper Mar 27, 2020
6b309e0
commented out test conditions
maxxtepper Mar 28, 2020
150c27c
trying obj chng
maxxtepper Apr 3, 2020
6afaac0
README updated
maxxtepper Apr 8, 2020
b56c723
README updated
maxxtepper Apr 8, 2020
db088d4
README updated
maxxtepper Apr 8, 2020
b43f137
added bin copy step to install -- block same name dir making
maxxtepper Apr 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions README
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions bin/bazel/bzl_obj_chng
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions bin/bazel/cc-temp/WORKSPACE
Original file line number Diff line number Diff line change
@@ -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",
)
7 changes: 7 additions & 0 deletions bin/bazel/cc-temp/src/lib/BUILD
Original file line number Diff line number Diff line change
@@ -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"],
)
6 changes: 6 additions & 0 deletions bin/bazel/cc-temp/src/main/BUILD
Original file line number Diff line number Diff line change
@@ -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"],
)
10 changes: 10 additions & 0 deletions bin/bazel/cc-temp/src/main/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <iostream>
#include "src/lib/Greeting.h"

int main()
{
Greeting *greet = new Greeting();
std::cout << greet->getGreetingMessage() << std::endl;

return EXIT_SUCCESS;
}
8 changes: 8 additions & 0 deletions bin/bazel/cc-temp/tests/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cc_test(
name = "tests",
srcs = glob(["**/*.cc"]),
deps = [
"//src/lib:ThisLib",
"@googletest//:gtest_main",
],
)
9 changes: 9 additions & 0 deletions bin/bazel/cc-temp/tests/Greeting_test.cc
Original file line number Diff line number Diff line change
@@ -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);
}
1 change: 1 addition & 0 deletions bin/bazel/cc-temp/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This repo contains the example file structure discussed in https://www.ratanparai.com/c++/writing-unit-tests-with-bazel/
7 changes: 7 additions & 0 deletions bin/bazel/cc-temp/tests/WORKSPACE
Original file line number Diff line number Diff line change
@@ -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",
)
54 changes: 54 additions & 0 deletions bin/bazel/cc_bzl_obj
Original file line number Diff line number Diff line change
@@ -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 <memory>
#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
5 changes: 3 additions & 2 deletions bin/object_maker
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -26,6 +26,7 @@ class $OBJECT {
# Source
touch $OBJECT.cc
echo "#include \"$OBJECT.h\"

$OBJECT::$OBJECT() {
}

Expand Down
49 changes: 19 additions & 30 deletions git_begin
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
131 changes: 131 additions & 0 deletions git_bzl_cc
Original file line number Diff line number Diff line change
@@ -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 <memory>
#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 <iostream>

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!!"