GithubHelp home page GithubHelp logo

generate's Introduction

codegen

This is a simple script suitable for facilitating code generation.

Unlike make, which relies on timestamps, it precisely tracks the input and output hashes of files so that code generation only runs when it is needed.

Unlike some fancier real build systems, this is simple enough to understand easily.

To use, create a git-style config file (I like to call mine codegen) and place it in your source tree. It might look something like this:

[gen "bar"]
	in = foo_test.go
	in = foo.go
	out = bar_test.go
	out = bar.go
	run = ./gen.sh

[gen "date"]
	out = date.go
	run = (\
		echo \"package example\" \n \
		echo \"\" \n \
		echo \"const date = \\\"$(date)\\\"\") > date.go

Each gen section defines a rule that constructs the files listed in out from the files listed in in by running run.

After running generate for the first time, you'll see that your file now includes:

[file "codegen.conf"]
	foo = 9d30df65a4e476a04e8255f22d89f627a1b9edba
	date = 56938b98d7fe51450d64d66c5656111a2b4f56aa
[file "foo_test.go"]
	foo = 25c275c5a5d2ae07fae59a72cbc4b9241d76ad30
[file "foo.go"]
	foo = 890d2531d03cd352e90ef4a5449b64bdf9d2098e
[file "bar_test.go"]
	foo = 5c2cc9784f3fe35e10aa47ae61296d69eb0eef1e
[file "bar.go"]
	foo = 6dbb71b8a40a734a06aad9e41e44d73db213542a
[file "date.go"]
	date = 1a77530613ba42092b0293eb455204efdc12a2a4
[file "Generatefile"]
	foo = 0ed4578ff85eef070e8196821bd7eec5d6d91931
	date = 56938b98d7fe51450d64d66c5656111a2b4f56aa

Pro-tip: You can make your config file executable and use a shebang line at the start to make your generate file directly runable.

#!/usr/bin/env ../generate 

[gen "bar"]
	in = foo.go
	out = bar.go
	run = ./gen.sh

generate's People

Contributors

crewjam avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.