makefile

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comment

type Comment struct {
	Target  string
	Value   string
	Default bool
	// contains filtered or unexported fields
}

Comment node.

func (Comment) Lines

func (n Comment) Lines() []int

type Include

type Include struct {
	Value string
	// contains filtered or unexported fields
}

Include node.

func (Include) Lines

func (n Include) Lines() []int

type Node

type Node interface {
	Lines() []int
}

Node interface.

func Parse

func Parse(r io.Reader) ([]Node, error)

Parse the given input.

func ParseRecursive

func ParseRecursive(r io.Reader, dir string) ([]Node, error)

ParseRecursive parses the given input recursively relative to the given dir such as /usr/local/include.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser is a quick-n-dirty Makefile "parser", not really, just comments and a few directives, but you'll forgive me.

func (*Parser) Parse

func (p *Parser) Parse(r io.Reader) ([]Node, error)

Parse the given input reader. TODO(bwplotka): Streaming version would be nice.

Example (WithComments)
contents := `
include github.com/tj/foo
# Stuff here:
#
#    :)
#
# Start the dev server.
start:
	@gopherjs -m -v serve --http :3000 github.com/tj/docs/client
.PHONY: start
# Start the API server.
api:
	@go run server/cmd/api/api.go
.PHONY: api
# Display dependency graph.
deps:
	@godepgraph github.com/tj/docs/client | dot -Tsvg | browser
.PHONY: deps
# Display size of dependencies.
#
# - foo
# - bar
# - baz
#
size:
	@gopherjs build client/*.go -m -o /tmp/out.js
	@du -h /tmp/out.js
	@gopher-count /tmp/out.js | sort -nr
.PHONY: size
.PHONY: dummy
# Just a comment.
# Just another comment.
dummy:
	@ls
`

nodes, err := Parse(strings.NewReader(contents))
if err != nil {
	panic(err)
}

for _, node := range nodes {
	fmt.Printf("%#v\n", node)
}
Output:

makefile.Include{node:makefile.node{lines:[]int{1}}, Value:"github.com/tj/foo"}
makefile.Comment{node:makefile.node{lines:[]int{7}}, Target:"start", Value:"Stuff here:\n\n   :)\n\nStart the dev server.", Default:false}
makefile.Comment{node:makefile.node{lines:[]int{8, 11}}, Target:"api", Value:"Start the API server.", Default:false}
makefile.Comment{node:makefile.node{lines:[]int{15}}, Target:"deps", Value:"Display dependency graph.", Default:false}
makefile.Comment{node:makefile.node{lines:[]int{24}}, Target:"size", Value:"Display size of dependencies.\n\n- foo\n- bar\n- baz", Default:false}
makefile.Comment{node:makefile.node{lines:[]int{32}}, Target:"dummy", Value:"Just a comment.\nJust another comment.", Default:false}
Example (WithoutComments)
contents := `
include github.com/tj/foo
include github.com/tj/bar
include github.com/tj/something/here
start:
	@gopherjs -m -v serve --http :3000 github.com/tj/docs/client
.PHONY: start
api:
	@go run server/cmd/api/api.go
.PHONY: api
deps:
	@godepgraph github.com/tj/docs/client | dot -Tsvg | browser
.PHONY: deps
`

nodes, err := Parse(strings.NewReader(contents))
if err != nil {
	panic(err)
}

for _, node := range nodes {
	fmt.Printf("%#v\n", node)
}
Output:

makefile.Include{node:makefile.node{lines:[]int{1}}, Value:"github.com/tj/foo"}
makefile.Include{node:makefile.node{lines:[]int{2}}, Value:"github.com/tj/bar"}
makefile.Include{node:makefile.node{lines:[]int{3}}, Value:"github.com/tj/something/here"}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL