12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
- DOCKER ?= docker
16
- GOLANG_VERSION ?= 1.15
17
- C_FOR_GO_TAG ?= 8eeee8c3b71f9c3c90c4a73db54ed08b0bba971d
18
- BUILDIMAGE ?= nvidia/go-nvml-devel:$(GOLANG_VERSION ) -$(C_FOR_GO_TAG )
19
-
20
15
PWD := $(shell pwd)
21
16
GEN_DIR := $(PWD ) /gen
22
17
PKG_DIR := $(PWD ) /pkg
23
18
GEN_BINDINGS_DIR := $(GEN_DIR ) /nvml
24
19
PKG_BINDINGS_DIR := $(PKG_DIR ) /nvml
25
20
26
- SOURCES = $(shell find $(GEN_BINDINGS_DIR ) -type f)
27
-
28
- EXAMPLES := $(patsubst ./examples/% /,% ,$(sort $(dir $(wildcard ./examples/* /) ) ) )
29
- EXAMPLE_TARGETS := $(patsubst % ,example-% , $(EXAMPLES ) )
30
-
31
21
ifeq ($(shell uname) ,Darwin)
32
22
SED := $(DOCKER) run -it --rm -v "$(PWD):$(PWD)" -w "$(PWD)" alpine:latest sed
33
23
else
34
24
SED := sed
35
25
endif
36
26
37
- TARGETS := all test clean bindings test-bindings clean-bindings patch-nvml-h examples $(EXAMPLE_TARGETS )
38
- DOCKER_TARGETS := $(patsubst % , docker-% , $(TARGETS ) )
39
- .PHONY : $(TARGETS ) $(DOCKER_TARGETS )
27
+ MODULE := github.com/NVIDIA/go-nvml/pkg
40
28
41
- .DEFAULT_GOAL = all
29
+ DOCKER ?= docker
42
30
43
- all : bindings
44
- test : test-bindings
45
- clean : clean-bindings
31
+ GOLANG_VERSION ?= 1.18.10
32
+ C_FOR_GO_TAG ?= 8eeee8c3b71f9c3c90c4a73db54ed08b0bba971d
33
+
34
+ ifeq ($(IMAGE ) ,)
35
+ REGISTRY ?= nvidia
36
+ IMAGE =$(REGISTRY ) /go-nvml
37
+ endif
38
+ IMAGE_TAG ?= $(GOLANG_VERSION ) -$(C_FOR_GO_TAG )
39
+ BUILDIMAGE ?= $(IMAGE ) :$(IMAGE_TAG ) -devel
40
+
41
+ EXAMPLES := $(patsubst ./examples/% /,% ,$(sort $(dir $(wildcard ./examples/* /) ) ) )
42
+ EXAMPLE_TARGETS := $(patsubst % ,example-% , $(EXAMPLES ) )
43
+
44
+ CMDS := $(patsubst ./cmd/% /,% ,$(sort $(dir $(wildcard ./cmd/* /) ) ) )
45
+ CMD_TARGETS := $(patsubst % ,cmd-% , $(CMDS ) )
46
+
47
+ CHECK_TARGETS := assert-fmt vet lint
48
+
49
+ MAKE_TARGETS := binary build all fmt generate test coverage check examples
50
+
51
+ GENERATE_TARGETS := clean bindings test-bindings clean-bindings patch-nvml-h
52
+
53
+ TARGETS := $(MAKE_TARGETS ) $(EXAMPLE_TARGETS ) $(CMD_TARGETS ) $(GENERATE_TARGETS ) $(CHECK_TARGETS )
54
+
55
+ DOCKER_TARGETS := $(patsubst % ,docker-% , $(TARGETS ) )
56
+ .PHONY : $(TARGETS ) $(DOCKER_TARGETS )
46
57
47
58
GOOS := linux
48
59
60
+ build :
61
+ GOOS=$(GOOS ) go build $(MODULE ) /...
62
+
49
63
examples : $(EXAMPLE_TARGETS )
50
- $(EXAMPLE_TARGETS ) : example-% : bindings
64
+ $(EXAMPLE_TARGETS ) : example-% :
51
65
GOOS=$(GOOS ) go build ./examples/$(* )
52
66
67
+ check : $(CHECK_TARGETS )
68
+
69
+ # Apply go fmt to the codebase
70
+ fmt :
71
+ go list -f ' {{.Dir}}' $(MODULE ) /... \
72
+ | xargs gofmt -s -l -w
73
+
74
+ assert-fmt :
75
+ go list -f ' {{.Dir}}' $(MODULE ) /... \
76
+ | xargs gofmt -s -l > fmt.out
77
+ @if [ -s fmt.out ]; then \
78
+ echo " \nERROR: The following files are not formatted:\n" ; \
79
+ cat fmt.out; \
80
+ rm fmt.out; \
81
+ exit 1; \
82
+ else \
83
+ rm fmt.out; \
84
+ fi
85
+
86
+ generate :
87
+ go generate $(MODULE ) /...
88
+
89
+ lint :
90
+ # We use `go list -f '{{.Dir}}' $(MODULE)/...` to skip the `vendor` folder.
91
+ # One we have fixed the linting issues, we whould add -set_exit_status
92
+ go list -f ' {{.Dir}}' $(MODULE ) /... | grep -v pkg/nvml | xargs golint
93
+
94
+ vet :
95
+ go vet $(MODULE ) /...
96
+
97
+ COVERAGE_FILE := coverage.out
98
+ test : build
99
+ # go test -v -coverprofile=$(COVERAGE_FILE) $(MODULE)/...
100
+ @echo " TODO: Skipping tests for now"
101
+
102
+ coverage : test
103
+ # cat $(COVERAGE_FILE) | grep -v "_mock.go" > $(COVERAGE_FILE).no-mocks
104
+ # go tool cover -func=$(COVERAGE_FILE).no-mocks
105
+ @echo " TODO: Skipping coverage for now"
106
+
107
+ # Generate an image for containerized builds
108
+ # Note: This image is local only
109
+ .PHONY : .build-image .pull-build-image .push-build-image
110
+ .build-image : docker/Dockerfile.devel
111
+ if [ " $( SKIP_IMAGE_BUILD) " = " " ]; then \
112
+ $(DOCKER ) build \
113
+ --progress=plain \
114
+ --build-arg GOLANG_VERSION=" $( GOLANG_VERSION) " \
115
+ --build-arg C_FOR_GO_TAG=" $( C_FOR_GO_TAG) " \
116
+ --tag $(BUILDIMAGE ) \
117
+ -f $(^ ) \
118
+ docker; \
119
+ fi
120
+
121
+ .pull-build-image :
122
+ $(DOCKER ) pull $(BUILDIMAGE )
123
+
124
+ .push-build-image :
125
+ $(DOCKER ) push $(BUILDIMAGE )
126
+
127
+ # A target for executing make targets in a docker container
128
+ $(DOCKER_TARGETS ) : docker-% : .build-image
129
+ @echo " Running 'make $( * ) ' in docker container $( BUILDIMAGE) "
130
+ $(DOCKER ) run \
131
+ --rm \
132
+ -e GOCACHE=/tmp/.cache \
133
+ -v $(PWD ) :$(PWD ) \
134
+ -w $(PWD ) \
135
+ --user $$(id -u ) :$$(id -g ) \
136
+ $(BUILDIMAGE ) \
137
+ make $(* )
138
+
139
+ # Start an interactive shell using the development image.
140
+ PHONY : .shell
141
+ .shell :
142
+ $(DOCKER ) run \
143
+ --rm \
144
+ -ti \
145
+ -e GOCACHE=/tmp/.cache \
146
+ -v $(PWD ) :$(PWD ) \
147
+ -w $(PWD ) \
148
+ --user $$(id -u ) :$$(id -g ) \
149
+ $(BUILDIMAGE )
150
+
151
+
152
+ SOURCES = $(shell find $(GEN_BINDINGS_DIR ) -type f)
153
+
154
+ .DEFAULT_GOAL = bindings
155
+
156
+ # In order to build the packages we need to patch the nvml.h file
157
+ build : bindings
158
+
159
+ test : test-bindings
160
+ clean : clean-bindings
161
+
53
162
$(PKG_BINDINGS_DIR ) :
54
163
mkdir -p $(@ )
55
164
@@ -60,7 +169,6 @@ $(PKG_BINDINGS_DIR)/nvml.h: $(GEN_BINDINGS_DIR)/nvml.h | $(PKG_BINDINGS_DIR)
60
169
spatch --in-place --very-quiet --sp-file $(GEN_BINDINGS_DIR ) /anonymous_structs.cocci $(@ ) > /dev/null
61
170
62
171
bindings : .create-bindings .strip-autogen-comment .strip-nvml-h-linenumber
63
-
64
172
.create-bindings : $(PKG_BINDINGS_DIR ) /nvml.h $(SOURCES ) | $(PKG_BINDINGS_DIR )
65
173
cp $(GEN_BINDINGS_DIR ) /nvml.yml $(PKG_BINDINGS_DIR )
66
174
c-for-go -out $(PKG_DIR ) $(PKG_BINDINGS_DIR ) /nvml.yml
@@ -84,10 +192,6 @@ bindings: .create-bindings .strip-autogen-comment .strip-nvml-h-linenumber
84
192
| xargs $(SED ) -i -E ' s#$(SED_SEARCH_STRING)$$#$(SED_REPLACE_STRING)#g'
85
193
86
194
test-bindings : bindings
87
- cd $(PKG_BINDINGS_DIR ) ; \
88
- go test -v . ; \
89
- cd -> /dev/null
90
-
91
195
clean-bindings :
92
196
rm -rf $(PKG_BINDINGS_DIR )
93
197
git checkout $(PKG_BINDINGS_DIR )
@@ -140,58 +244,9 @@ update-nvml-h:
140
244
done ; \
141
245
echo
142
246
143
- # Generate an image for containerized builds
144
- # Note: This image is local only
145
- .build-image : Dockerfile
146
- $(DOCKER ) buildx build \
147
- --progress=plain \
148
- --build-arg GOLANG_VERSION=" $( GOLANG_VERSION) " \
149
- --build-arg C_FOR_GO_TAG=" $( C_FOR_GO_TAG) " \
150
- --tag $(BUILDIMAGE ) \
151
- .
152
-
153
- # A target for executing make targets in a docker container
154
- $(DOCKER_TARGETS ) : docker-% : .build-image
155
- @echo " Running 'make $( * ) ' in docker container $( BUILDIMAGE) "
156
- $(DOCKER ) run \
157
- --rm \
158
- -e JQ=jq \
159
- -e GOCACHE=/tmp/.cache \
160
- -v $(PWD ) :$(PWD ) \
161
- -w $(PWD ) \
162
- --user $$(id -u ) :$$(id -g ) \
163
- $(BUILDIMAGE ) \
164
- make $(* )
165
-
166
- # A make target to set up an interactive docker environment as the current user.
167
- # This is useful for debugging issues in the make process in the container.
168
- .docker-shell : .build-image
169
- $(DOCKER ) run \
170
- -ti \
171
- --rm \
172
- -e JQ=jq \
173
- -e GOCACHE=/tmp/.cache \
174
- -v $(PWD ) :$(PWD ) \
175
- -w $(PWD ) \
176
- --user $$(id -u ) :$$(id -g ) \
177
- $(BUILDIMAGE ) \
178
- bash
179
-
180
- # A make target to set up an interactive docker environment as root.
181
- # This is useful for debugging issues in dependencies or the container build process
182
- .docker-root-shell : .build-image
183
- $(DOCKER ) run \
184
- -ti \
185
- --rm \
186
- -e JQ=jq \
187
- -e GOCACHE=/tmp/.cache \
188
- -v $(PWD ) :$(PWD ) \
189
- -w $(PWD ) \
190
- $(BUILDIMAGE ) \
191
- bash
192
-
193
247
# Run markdownlint (https://github.com/markdownlint/markdownlint) for README.md
194
248
# Note: Tabs are preferred for Golang code blocks
195
249
markdownlint : MDL := $(DOCKER ) run --rm -v "$(PWD ) :$(PWD ) " -w "$(PWD ) " markdownlint/markdownlint:latest
196
250
markdownlint :
197
251
@$(MDL ) --rules=~ no-hard-tabs,~line-length README.md
252
+
0 commit comments