Skip to content

Commit

Permalink
Update Contributor Guide with information and static code analysis (#291
Browse files Browse the repository at this point in the history
)

* Update Contributor Guide with information and static code analysis

- Specify what static code analysis is performe on repository and its packages
- Document structor of an OFRAK package Makefile
- Remove unneeded depenencies, clean Makefile targets

* Fix formatting of list
  • Loading branch information
whyitfor authored Apr 25, 2023
1 parent d79a7e7 commit 5caf047
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 35 deletions.
3 changes: 0 additions & 3 deletions disassemblers/ofrak_angr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,3 @@ inspect:
test: inspect
$(PYTHON) -m pytest -n auto --cov=ofrak_angr ofrak_angr_test
fun-coverage --cov-fail-under=100

.PHONY: dependencies
dependencies:
5 changes: 0 additions & 5 deletions disassemblers/ofrak_binary_ninja/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,3 @@ inspect:
test: inspect
$(PYTHON) -m pytest --cov=ofrak_binary_ninja --cov-report=term-missing ofrak_binary_ninja_test
fun-coverage --cov-fail-under=100

.PHONY: dependencies
dependencies:
test -f license.dat
chmod +x ./install_binary_ninja_headless_linux.sh
3 changes: 0 additions & 3 deletions disassemblers/ofrak_capstone/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,3 @@ inspect:
test: inspect
$(PYTHON) -m pytest ofrak_capstone_test --cov=ofrak_capstone --cov-report=term-missing
fun-coverage --cov-fail-under=100

.PHONY: dependencies
dependencies:
2 changes: 0 additions & 2 deletions disassemblers/ofrak_ghidra/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ develop:
test:
$(PYTHON) -m pytest --cov=ofrak_ghidra --cov-report=term-missing ofrak_ghidra_test
fun-coverage --cov-fail-under=100

dependencies:
48 changes: 47 additions & 1 deletion docs/contributor-guide/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,45 @@ ofrak_package_x
|--setup.py
|--ofrak_package_x_python_module
|...
|--ofrak_package_x_python_module_test
|...
```

`Makefile` must contain a rule `dependencies`. This rule should take care of any setup that needs to be done for that package before the Docker build.
### Makefile
At a minimum, an OFRAK package Makefile should contain the following targets:

- `install`: a phony target that installs the package
- `develop`: a phony target that installs the package in editable mode (for development)
- `inspect`: a phony target that runs static code analysis on the package
- `test`: a phony target that:
- has a dependency on `inspect`
- runs the packages tests, recording "term-missing" coverage information
- uses [fun-coverage](https://pypi.org/project/fun-coverage/) to assert that the package has 100% function coverage

An example of such a Makefile for `ofrak_package_x` is:
```make
PYTHON=python3
PIP=pip3

.PHONY: install
install:
$(PIP) install .

.PHONY: develop
develop:
$(PIP) install -e .[test]

.PHONY: inspect
inspect:
mypy

.PHONY: test
test: inspect
$(PYTHON) -m pytest -n auto --cov=ofrak_package_x_python_module --cov-report=term-missing --cov-fail-under=100 ofrak_package_x_python_module_test
fun-coverage --cov-fail-under=100
```

### Dockerstub & Dockerstage
`Dockerstub` should read as a normal Dockerfile, only without a base image specified at the top. This file should contain all of the steps necessary to install this package in a Docker image. During build, all packages' `Dockerstub`s will be concatenated, so specifying a base image is unnecessary. Also, any specified entrypoint may be overridden.

The build relies on the following assumptions:
Expand All @@ -149,6 +184,17 @@ The build relies on the following assumptions:
- All rules in `Makefile` should assume the working directory is `ofrak_package_x` (but at a different path as explained above)
- `Dockerstub` and `Dockerstage` should be written assuming the build context is the parent directory of `ofrak_package_x`. Do not assume anything is present in the build context besides the contents of `ofrak_package_x` and what `Makefile` adds to `ofrak_package_x` in the `dependencies` rule.

## Static Code Analysis
The repository has several automated static code anaysis workflows.

1. [Pre-commit](#pre-commit) is used, both as a pre-commit hook and as a CI/CD workflow, to ensure repository-wide:
1. [PEP8 compliance](#pep-8) (this is done using [black](#black)).
1. No Python modules contain unused imports.
1. Files are either empty or end with a newline.
1. Each package contains an `inspect` target responsible for static code analysis for that package.
1. As part of this, [MyPy](#type-annotations-and-mypy) is used to perform static type checking.


<div align="right">
<img src="../assets/square_05.png" width="125" height="125">
</div>
3 changes: 0 additions & 3 deletions ofrak_core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ test: inspect
$(PYTHON) -m pytest -n auto test_ofrak --cov=ofrak --cov-report=term-missing
fun-coverage --cov-fail-under=100

.PHONY: dependencies
dependencies:

ofrak/gui/public:
if [ -d /ofrak_gui ] ; then \
cp -r /ofrak_gui ofrak/gui/public ; \
Expand Down
6 changes: 0 additions & 6 deletions ofrak_io/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,3 @@ inspect:
test: inspect
$(PYTHON) -m pytest -n auto --cov=ofrak_io --cov-report=term-missing --cov-fail-under=100 ofrak_io_test
fun-coverage --cov-fail-under=100

.PHONY: dependencies
dependencies: ;

.PHONY: clean
clean: ;
6 changes: 0 additions & 6 deletions ofrak_patch_maker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,3 @@ inspect:
test: inspect
$(PYTHON) -m pytest -n auto --cov=ofrak_patch_maker --cov-report=term-missing ofrak_patch_maker_test
fun-coverage --cov-fail-under=100

.PHONY: dependencies
dependencies:

clean:
-rm -rf lib
6 changes: 0 additions & 6 deletions ofrak_type/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,3 @@ inspect:
test: inspect
$(PYTHON) -m pytest -n auto --cov=ofrak_type --cov-report=term-missing --cov-fail-under=100 ofrak_type_test
fun-coverage --cov-fail-under=100

.PHONY: dependencies
dependencies: ;

.PHONY: clean
clean: ;

0 comments on commit 5caf047

Please sign in to comment.