github.com/m3db/m3@v1.5.0/src/x/generated-source-files.mk (about)

     1  gopath_prefix            := $(GOPATH)/src
     2  m3x_package              := github.com/m3db/m3/src/x
     3  m3x_package_path         := $(gopath_prefix)/$(m3x_package)
     4  temp_suffix              := _temp
     5  
     6  # Tests that all currently generated types match their contents if they were regenerated
     7  .PHONY: test-genny-all
     8  test-genny-all: genny-all
     9  	@test "$(shell git --no-pager diff --shortstat 2>/dev/null)" = "" || (git --no-pager diff --no-color && echo "Check git status, there are dirty files" && exit 1)
    10  	@test "$(shell git --no-pager status --porcelain 2>/dev/null | grep "^??")" = "" || (git status --porcelain && echo "Check git status, there are untracked files" && exit 1)
    11  
    12  .PHONY: genny-all
    13  genny-all: genny-map-all genny-list-all genny-arraypool-all
    14  
    15  .PHONY: genny-map-all
    16  genny-map-all: idhashmap-update byteshashmap-update
    17  
    18  .PHONY: idhashmap-update
    19  idhashmap-update:
    20  	cd $(m3x_package_path)/generics/hashmap && cat ./map.go | grep -v nolint | genny -pkg idkey -ast gen "KeyType=ident.ID ValueType=MapValue" > ./idkey/map_gen.go
    21  
    22  .PHONY: byteshashmap-update
    23  byteshashmap-update:
    24  	cd $(m3x_package_path)/generics/hashmap && cat ./map.go | grep -v nolint | genny -pkg byteskey -ast gen "KeyType=[]byte ValueType=MapValue" > ./byteskey/map_gen.go
    25  
    26  # NB(prateek): `target_package` should not have a trailing slash
    27  # Generic targets meant to be re-used by other users
    28  .PHONY: hashmap-gen
    29  hashmap-gen:
    30  	$(eval out_dir=$(gopath_prefix)/$(target_package))
    31  	cd $(m3x_package_path)/generics/hashmap && cat ./map.go | grep -v nolint | genny -pkg $(pkg) -ast gen "KeyType=$(key_type) ValueType=$(value_type)" > "$(out_dir)/map_gen.go"
    32  ifneq ($(rename_type_prefix),)
    33  	make hashmap-gen-rename
    34  endif
    35  
    36  .PHONY: idhashmap-gen
    37  idhashmap-gen:
    38  	$(eval out_dir=$(gopath_prefix)/$(target_package))
    39  	cd $(m3x_package_path)/generics/hashmap/idkey && cat ./map_gen.go | grep -v nolint | genny -pkg $(pkg) -ast gen "MapValue=$(value_type)" > "$(out_dir:\=)/map_gen.go"
    40  	cd $(m3x_package_path)/generics/hashmap/idkey && cat ./new_map.go | grep -v nolint | genny -pkg $(pkg) -ast gen "MapValue=$(value_type)" > "$(out_dir:\=)/new_map_gen.go"
    41  ifneq ($(rename_type_prefix),)
    42  	make hashmap-gen-rename rename_nogen_key="true"
    43  endif
    44  
    45  .PHONY: byteshashmap-gen
    46  byteshashmap-gen:
    47  	$(eval out_dir=$(gopath_prefix)/$(target_package))
    48  	cd $(m3x_package_path)/generics/hashmap/byteskey && cat ./map_gen.go | grep -v nolint | genny -pkg $(pkg) -ast gen "MapValue=$(value_type)" > "$(out_dir:\=)/map_gen.go"
    49  	cd $(m3x_package_path)/generics/hashmap/byteskey && cat ./new_map.go | grep -v nolint | genny -pkg $(pkg) -ast gen "MapValue=$(value_type)" > "$(out_dir:\=)/new_map_gen.go"
    50  ifneq ($(rename_type_prefix),)
    51  	make hashmap-gen-rename rename_nogen_key="true"
    52  endif
    53  
    54  key_type_alias   ?= $(key_type)
    55  value_type_alias ?= $(value_type)
    56  .PHONY: hashmap-gen-rename
    57  hashmap-gen-rename:
    58  	$(eval out_dir=$(gopath_prefix)/$(target_package))
    59  	$(eval temp_outdir=$(out_dir)$(temp_suffix))
    60  	echo $(temp_outdir)
    61  	@if test -d $(temp_outdir); then echo "temp directory $(temp_outdir) exists, failing" ; exit 1 ; fi
    62  	mkdir -p $(temp_outdir)
    63  	! test -f $(out_dir)/new_map_gen.go || mv $(out_dir)/new_map_gen.go $(temp_outdir)/new_map_gen.go
    64  ifeq ($(rename_nogen_key),)
    65  	# allow users to short circuit the generation of key.go if they don't need it.
    66  	echo 'package $(pkg)' > $(temp_outdir)/key.go
    67  	echo '' >> $(temp_outdir)/key.go
    68  	test "$(key_type_alias)" == ""  || echo "type $(key_type_alias) interface{}" >> $(temp_outdir)/key.go
    69  endif
    70  ifeq ($(rename_nogen_value),)
    71  	# Allow users to short circuit the generation of value.go if they don't need it.
    72  	echo 'package $(pkg)' > $(temp_outdir)/value.go
    73  	echo '' >> $(temp_outdir)/value.go
    74  	test "$(value_type_alias)" = "struct*" || echo 'type $(value_type_alias) interface{}' >> $(temp_outdir)/value.go
    75  endif
    76  	mv $(out_dir)/map_gen.go $(temp_outdir)/map_gen.go
    77  
    78  	gofmt -w -r 'Map -> $(rename_type_prefix)Map' $(temp_outdir)/*_gen.go
    79  	sed -i'tmp' 's#^// Map# // $(rename_type_prefix)Map#g' $(temp_outdir)/*_gen.go
    80  
    81  	gofmt -w -r 'MapHash -> $(rename_type_prefix)MapHash' $(temp_outdir)/*_gen.go
    82  	sed -i'tmp' 's#^// MapHash# // $(rename_type_prefix)MapHash#g' $(temp_outdir)/*_gen.go
    83  
    84  	gofmt -w -r 'HashFn -> $(rename_type_prefix)MapHashFn' $(temp_outdir)/*_gen.go
    85  	sed -i'tmp' 's#^// HashFn# // $(rename_type_prefix)MapHashFn#g' $(temp_outdir)/*_gen.go
    86  
    87  	gofmt -w -r 'EqualsFn -> $(rename_type_prefix)MapEqualsFn' $(temp_outdir)/*_gen.go
    88  	sed -i'tmp' 's#^// EqualsFn# // $(rename_type_prefix)MapEqualsFn#g' $(temp_outdir)/*_gen.go
    89  
    90  	gofmt -w -r 'CopyFn -> $(rename_type_prefix)MapCopyFn' $(temp_outdir)/*_gen.go
    91  	sed -i'tmp' 's#^// CopyFn# // $(rename_type_prefix)MapCopyFn#g' $(temp_outdir)/*_gen.go
    92  
    93  	gofmt -w -r 'FinalizeFn -> $(rename_type_prefix)MapFinalizeFn' $(temp_outdir)/*_gen.go
    94  	sed -i'tmp' 's#^// FinalizeFn# // $(rename_type_prefix)MapFinalizeFn#g' $(temp_outdir)/*_gen.go
    95  
    96  	gofmt -w -r 'MapEntry -> $(rename_type_prefix)MapEntry' $(temp_outdir)/*_gen.go
    97  	sed -i'tmp' 's#^// MapEntry# // $(rename_type_prefix)MapEntry#g' $(temp_outdir)/*_gen.go
    98  
    99  	gofmt -w -r 'SetUnsafeOptions -> $(rename_type_prefix)MapSetUnsafeOptions' $(temp_outdir)/*_gen.go
   100  	sed -i'tmp' 's#^// SetUnsafeOptions# // $(rename_type_prefix)MapSetUnsafeOptions#g' $(temp_outdir)/*_gen.go
   101  
   102  	gofmt -w -r 'mapAlloc -> _$(rename_type_prefix)MapAlloc' $(temp_outdir)/*_gen.go
   103  	sed -i'tmp' 's#^// mapAlloc#// _$(rename_type_prefix)MapAlloc#g' $(temp_outdir)/*_gen.go
   104  
   105  	gofmt -w -r 'mapOptions -> _$(rename_type_prefix)MapOptions' $(temp_outdir)/*_gen.go
   106  	sed -i'tmp' 's#^// mapOptions#// _$(rename_type_prefix)MapOptions#g' $(temp_outdir)/*_gen.go
   107  
   108  	gofmt -w -r 'mapKey -> _$(rename_type_prefix)MapKey' $(temp_outdir)/*_gen.go
   109  	sed -i'tmp' 's#^// mapKey#// _$(rename_type_prefix)MapKey#g' $(temp_outdir)/*_gen.go
   110  
   111  	gofmt -w -r 'mapKeyOptions -> _$(rename_type_prefix)MapKeyOptions' $(temp_outdir)/*_gen.go
   112  	sed -i'tmp' 's#^// mapKeyOptions#// _$(rename_type_prefix)MapKeyOptions#g' $(temp_outdir)/*_gen.go
   113  
   114  	[ "$(rename_constructor)" = "" ] || \
   115  	gofmt -w -r 'NewMap -> $(rename_constructor)' $(temp_outdir)/*_gen.go && \
   116  	sed -i'tmp' 's#^// NewMap#// $(rename_constructor)#g' $(temp_outdir)/*_gen.go
   117  	[ "$(rename_constructor_options)" = "" ] || \
   118  	gofmt -w -r 'MapOptions -> $(rename_constructor_options)' $(temp_outdir)/*_gen.go && \
   119  	sed -i'tmp' 's#^// MapOptions#// $(rename_constructor_options)#g' $(temp_outdir)/*_gen.go
   120  
   121  	mv $(temp_outdir)/map_gen.go $(out_dir)/map_gen.go
   122  	! test -f $(temp_outdir)/new_map_gen.go || mv $(temp_outdir)/new_map_gen.go $(out_dir)/new_map_gen.go
   123  	rm -f $(temp_outdir)/key.go
   124  	rm -f $(temp_outdir)/value.go
   125  	rm -f $(temp_outdir)/*.gotmp
   126  	rmdir $(temp_outdir)
   127  
   128  # Generation rule for all generated lists
   129  .PHONY: genny-list-all
   130  genny-list-all:                              \
   131  	genny-list-context-finalizeables
   132  
   133  # List generation rule for context/finalizeablesList
   134  .PHONY: genny-list-context-finalizeables
   135  genny-list-context-finalizeables:
   136  	cd $(m3x_package_path) && make genny-pooled-elem-list-gen \
   137  		pkg=context                                           \
   138  		elem_type=finalizeable                                \
   139  		value_type=finalizeable                               \
   140  		rename_type_prefix=finalizeable                       \
   141  		rename_type_middle=Finalizeable                       \
   142  		rename_gen_types=true                                 \
   143  		target_package=github.com/m3db/m3/src/x/context
   144  	# Rename generated list file
   145  	mv -f $(m3x_package_path)/context/list_gen.go $(m3x_package_path)/context/finalizeable_list_gen.go
   146  
   147  .PHONY: genny-arraypool-all
   148  genny-arraypool-all: genny-arraypool-ident-tags
   149  
   150  # arraypool generation rule for ident/tagsArrayPool
   151  .PHONY: genny-arraypool-ident-tags
   152  genny-arraypool-ident-tags:
   153  	cd $(m3x_package_path) && make genny-arraypool   \
   154  		pkg=ident                                      \
   155  		elem_type=Tag                                  \
   156  		target_package=$(m3x_package)/ident            \
   157  		out_file=tag_arraypool_gen.go                  \
   158  		rename_type_prefix=tag                         \
   159  		rename_type_middle=Tag                         \
   160  		rename_constructor=newTagArrayPool             \
   161  		rename_gen_types=true
   162  
   163  # NB(prateek): `target_package` should not have a trailing slash
   164  # Generic arraypool generation rule
   165  .PHONY: genny-arraypool
   166  genny-arraypool:
   167  	$(eval out_dir=$(gopath_prefix)/$(target_package))
   168  	cat $(m3x_package_path)/generics/arraypool/pool.go | grep -v nolint | genny -pkg $(pkg) -ast gen "elemType=$(elem_type)" > "$(out_dir)/$(out_file)"
   169  ifneq ($(rename_type_prefix),)
   170  	$(eval temp_outdir=$(out_dir)$(temp_suffix))
   171  	@if [ -d $(temp_outdir) ] ; then echo "temp directory $(temp_outdir) exists, failing" ; exit 1 ; fi
   172  	mkdir -p $(temp_outdir)
   173  	mv $(out_dir)/$(out_file) $(temp_outdir)/$(out_file)
   174  	make arraypool-gen-rename out_dir=$(out_dir)
   175  	mv $(temp_outdir)/$(out_file) $(out_dir)/$(out_file)
   176  	rm -f $(temp_outdir)/*.gotmp
   177  	rmdir $(temp_outdir)
   178  endif
   179  
   180  elem_type_alias ?= $(elem_type)
   181  .PHONY: arraypool-gen-rename
   182  arraypool-gen-rename:
   183  	$(eval temp_outdir=$(out_dir)$(temp_suffix))
   184  ifneq ($(rename_gen_types),)
   185  	# Allow users to short circuit the generation of types.go if they don't need it.
   186  	echo 'package $(pkg)' > $(temp_outdir)/types.go
   187  	echo '' >> $(temp_outdir)/types.go
   188  	echo "type $(elem_type_alias) interface{}" >> $(temp_outdir)/types.go
   189  endif
   190  	gofmt -w -r 'elemArrayPool -> $(rename_type_prefix)ArrayPool' $(temp_outdir)/*.go
   191  	gofmt -w -r 'elemArr -> $(rename_type_prefix)Arr' $(temp_outdir)/*.go
   192  	gofmt -w -r 'elemArrPool -> $(rename_type_prefix)ArrPool' $(temp_outdir)/*.go
   193  	gofmt -w -r 'elemArrayPoolOpts -> $(rename_type_prefix)ArrayPoolOpts' $(temp_outdir)/*.go
   194  	gofmt -w -r 'elemFinalizeFn -> $(rename_type_prefix)FinalizeFn' $(temp_outdir)/*.go
   195  	gofmt -w -r 'newElemArrayPool -> $(rename_constructor)' $(temp_outdir)/*.go
   196  	gofmt -w -r 'defaultElemFinalizerFn -> default$(rename_type_middle)FinalizerFn' $(temp_outdir)/*.go
   197  
   198  	# best effort comment rename
   199  	sed -i'tmp' 's#^// elemArr#// $(rename_type_prefix)Arr#g' $(temp_outdir)/*.go
   200  	sed -i'tmp' 's#^// elemFinalizeFn#// $(rename_type_prefix)FinalizeFn#g' $(temp_outdir)/*.go
   201  	sed -i'tmp' 's#^// newElemArrayPool#// $(rename_constructor)#g' $(temp_outdir)/*.go
   202  	sed -i'tmp' 's#^// defaultElemFinalizerFn#// default$(rename_type_middle)FinalizerFn#g' $(temp_outdir)/*.go
   203  ifneq ($(rename_gen_types),)
   204  	rm $(temp_outdir)/types.go
   205  endif
   206  
   207  # NB(prateek): `target_package` should not have a trailing slash
   208  # generic leakcheckpool generation rule
   209  .PHONY: genny-leakcheckpool
   210  genny-leakcheckpool:
   211  	$(eval out_dir=$(gopath_prefix)/$(target_package))
   212  	cat $(m3x_package_path)/generics/leakcheckpool/pool.go | grep -v nolint | genny -pkg $(pkg) -ast gen "elemType=$(elem_type) elemTypePool=$(elem_type_pool)" > "$(out_dir)/$(out_file)"
   213  
   214  .PHONY: genny-pooled-elem-list-gen
   215  genny-pooled-elem-list-gen:
   216  	$(eval out_dir=$(gopath_prefix)/$(target_package))
   217  	cd $(m3x_package_path)/generics/list && cat ./list.go | grep -v nolint | genny -pkg $(pkg) -ast gen "ValueType=$(value_type)" > "$(out_dir)/list_gen.go"
   218  ifneq ($(rename_type_prefix),)
   219  	$(eval temp_outdir=$(out_dir)$(temp_suffix))
   220  	@if [ -d $(temp_outdir) ] ; then echo "temp directory $(temp_outdir) exists, failing" ; exit 1 ; fi
   221  	mkdir -p $(temp_outdir)
   222  	mv $(out_dir)/list_gen.go $(temp_outdir)/list_gen.go
   223  	make list-gen-rename out_dir=$(out_dir)
   224  	mv $(temp_outdir)/list_gen.go $(out_dir)/list_gen.go
   225  	rm -f $(temp_outdir)/*.gotmp
   226  	rmdir $(temp_outdir)
   227  endif
   228  
   229  elem_type_alias ?= $(elem_type)
   230  .PHONY: list-gen-rename
   231  list-gen-rename:
   232  	$(eval temp_outdir=$(out_dir)$(temp_suffix))
   233  ifneq ($(rename_gen_types),)
   234  	# Allow users to short circuit the generation of types.go if they don't need it.
   235  	echo 'package $(pkg)' > $(temp_outdir)/types.go
   236  	echo '' >> $(temp_outdir)/types.go
   237  	echo "type $(elem_type_alias) interface{}" >> $(temp_outdir)/types.go
   238  endif
   239  	gofmt -w -r 'Element -> $(rename_type_prefix)Element' $(temp_outdir)/*.go
   240  	gofmt -w -r 'List -> $(rename_type_prefix)List' $(temp_outdir)/*.go
   241  	gofmt -w -r 'ElementPool -> $(rename_type_prefix)ElementPool' $(temp_outdir)/*.go
   242  	gofmt -w -r 'newElementPool -> new$(rename_type_middle)ElementPool' $(temp_outdir)/*.go
   243  	gofmt -w -r 'newList -> new$(rename_type_middle)List' $(temp_outdir)/*.go
   244  	# best-effort comment fixup
   245  	sed -i'tmp' 's#^// Element#// $(rename_type_prefix)Element#g' $(temp_outdir)/*.go
   246  	sed -i'tmp' 's#^// List#// $(rename_type_prefix)List#g' $(temp_outdir)/*.go
   247  	sed -i'tmp' 's#^// ElementPool#// $(rename_type_prefix)ElementPool#g' $(temp_outdir)/*.go
   248  	sed -i'tmp' 's#^// newElementPool#// new$(rename_type_middle)ElementPool#g' $(temp_outdir)/*.go
   249  	sed -i'tmp' 's#^// newList#// new$(rename_type_middle)List#g' $(temp_outdir)/*.go
   250  ifneq ($(rename_gen_types),)
   251  	rm $(temp_outdir)/types.go
   252  endif