Skip to content

Latest commit

 

History

History
117 lines (79 loc) · 4.22 KB

File metadata and controls

117 lines (79 loc) · 4.22 KB

Metaprogramming

MIT 6.NULL - Metaprogramming

Build systems

概念:dependencies, targets, rules

makeMakefile

  • 根据modify time确定什么文件需要regenerate
target: prerequisite1 prerequisite2 ...
	command1
	command2 (需要tab)
paper.pdf: paper.tex plot-data.png
	pdflatex paper.tex

plot-%.png: %.dat plot.py
	./plot.py -i $*.dat -o $@
# specify all source files here
SRCS = hw.c helper.c

# specify target here (name of executable)
TARG = hw

# specify compiler, compile flags, and needed libs
CC   = gcc
OPTS = -Wall -O
LIBS = -lm

# this translates .c files in src list to .o’s
OBJS = $(SRCS:.c=.o)

# all is not really needed, but is used to generate the target, default directive
all: $(TARG)

# this generates the target executable
$(TARG): $(OBJS)
	$(CC) -o $(TARG) $(OBJS) $(LIBS)
	
# this is a generic rule for .o files
%.o: %.c
  $(CC) $(OPTS) -c $< -o $@

# and finally, a clean line
.PHONY: clean
clean:
	rm -f $(OBJS) $(TARG)
  • 第一个directive是default goal
  • indent后面的命令是建立依赖的语句
  • .PHONY避免clean和名为clean的文件冲突
SUBDIRS = foo bar baz

.PHONY: subdirs $(SUBDIRS)

subdirs: $(SUBDIRS)

$(SUBDIRS):
        $(MAKE) -C $@

foo: baz

Dependency management

概念:repository, versioning, version number, semantic versioning

  • If a new release does not change the API, increase the patch version.
  • If you add to your API in a backwards-compatible way, increase the minor version.
  • If you change the API in a non-backwards-compatible way, increase the major version.
  • Rust's build system,可帮助理解版本号以及dependency管理

lock file: a file that lists the exact version you are currently depending on of each dependency

  • vendoring: copy all the code of your dependencies into your own project

makedepend工具能帮助寻找依赖

Continuous integration(CI) systems

“stuff that runs whenever your code changes”

  • e.g. Travis CI, Azure Pipelines, and GitHub Actions
  • Pages is a CI action that runs the Jekyll blog software on every push to master and makes the built site available on a particular GitHub domain

testing

  • Test suite: a collective term for all the tests
  • Unit test: a “micro-test” that tests a specific feature in isolation
  • Integration test: a “macro-test” that runs a larger part of the system to check that different feature or components work together.
  • Regression test: a test that implements a particular pattern that previously caused a bug to ensure that the bug does not resurface.
  • Mocking: the replace a function, module, or type with a fake implementation to avoid testing unrelated functionality. For example, you might “mock the network” or “mock the disk”.

Github Pages

  1. Set up a simple auto-published page using GitHub Pages. Add a GitHub Action to the repository to run shellcheck on any shell files in that repository (here is one way to do it). Check that it works!
  2. Build your own GitHub action to run proselint or write-good on all the .md files in the repository. Enable it in your repository, and check that it works by filing a pull request with a typo in it.

Inbox

个人blog的建立:

调研之后决定用动态blog,halo是傻瓜式操作,在阿里云上部署