Skip to content
Katie Dektar edited this page Dec 14, 2020 · 7 revisions

C++ Utils

Libraries for student C++ code.

C/C++ CI

Images

graphics/image.h can be used to create, view, load and save images.

You can try using this library with this CS50 lab.

Read more at https://github.com/ILXL/cpputils/wiki/Images

Karel the Robot

cpputils/karel/karel.h can be used to create functional Karel the Robot problems.

You can try using this library with this CS50 lab.

Read more at https://github.com/ILXL/cpputils/wiki/Karel-the-Robot

cpputils usage (for lab and project creators):

As a subtree:

If you don't expect your lab or project to need to back-port changes into cpputils, it may be easier to check out cpputils as a subtree.

From the root directory of your lab, you can run:

git subtree add --prefix problem/cpputils https://github.com/ILXL/cpputils master --squash

This creates a copy of the cpputils repository's master branch as a single commit in your git history. If you want to update it, run:

git subtree pull --prefix problem/cpputils https://github.com/ILXL/cpputils master --squash

As a submodule:

To use this as a submodule in another lab or project, run:

git submodule add -b v2 https://github.com/ILXL/cpputils

This will create a .gitmodules file which you can add and commit, pointed at a particular branch (in this case v2).

Then make sure everyone who checks out the repo gets the submodule, for example adding this command to your project Makefile to check if image.h is available:

cpputils/graphics/image.h:
	@git submodule update --init --recursive

This checks out cpputils at a particular commit, and everyone cloning your git repository will get that exact commit. This is useful for versioning: it ensures everyone using that git repository will have the same version of cpputils until it is explicitly updated.

So, if you want to update the commit which cpputils is pointed at in an existing repo, you can pull from within the cpputils directory and then cd back out to add and commit the change. For example, this snippet pulls the latest from the master branch:

cd cpputils
git checkout master && git pull
cd ..
git add cpputils/ && git commit -m "Updating cpputils"

Release process (for cpputils library contributors):

Branches

Users of cpputils will check out a particular branch as a submodule within their repository. We have created branches for each version to make it easy for submodules to get a known stable cpputils.

  • Development of cpputils should be merged to the master branch.
  • Significant changes, once ready for usage, should be forked to new version branches (v1, v2, etc).
  • Changes should not be merged back to earlier version branches, except bugfixes.

Testing

Utility classes in cpputils should be tested to ensure changes do not cause any surprising breakages. You can set up github continuous integration testing using Github Actions.

You can add new tests by editing .github/workflows/c-cpp.yml. For example, the graphics class is tested with graphcis/image_unittest.cc. c-cpp.yml has a workflow to make image_unittest which ensures all dependencies are installed (like gtest) and then builds and runs image_unittest.cc.

You can see the result of each test pass in the actions tab on GitHub.

Note: Github Actions is free for public repositories, but there are a limited number of minutes for private repos! cpputils is public so it has unlimited actions minutes.