Skip to content

Commit e847864

Browse files
committed
To make it easier for users to set up configuration files without having to remember various fields, the configuration file is written with all empty fields by default except for the Impl field.
1 parent fb56e76 commit e847864

File tree

2 files changed

+38
-22
lines changed

2 files changed

+38
-22
lines changed

cmd/llcppcfg/gen/cfg_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,10 @@ func Test_sortIncludes(t *testing.T) {
473473
}
474474

475475
func TestNewLLCppConfig(t *testing.T) {
476+
want := llcppg.NewDefault()
477+
want.Name = "libcjson"
478+
want.CFlags = "$(pkg-config --cflags libcjson)"
479+
want.Libs = "$(pkg-config --libs libcjson)"
476480
type args struct {
477481
name string
478482
flag FlagMode
@@ -488,13 +492,7 @@ func TestNewLLCppConfig(t *testing.T) {
488492
"libcjson",
489493
WithTab,
490494
},
491-
&llcppg.Config{
492-
Name: "libcjson",
493-
CFlags: "$(pkg-config --cflags libcjson)",
494-
Libs: "$(pkg-config --libs libcjson)",
495-
Cplusplus: false,
496-
KeepUnderScore: false,
497-
},
495+
want,
498496
},
499497
}
500498
for _, tt := range tests {

config/config.go

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,54 @@ import (
77
)
88

99
type Condition struct {
10-
OS []string `json:"os"`
11-
Arch []string `json:"arch"`
10+
OS []string `json:"os,omitempty"`
11+
Arch []string `json:"arch,omitempty"`
1212
}
1313

1414
type ImplFiles struct {
15-
Files []string `json:"files"`
16-
Cond Condition `json:"cond"`
15+
Files []string `json:"files,omitempty"`
16+
Cond Condition `json:"cond,omitempty"`
1717
}
1818

1919
// Config represents a configuration for the llcppg tool.
2020
type Config struct {
2121
Name string `json:"name"`
2222
CFlags string `json:"cflags"`
2323
// NOTE(MeterosLiu): libs can be empty when we're in headerOnly mode
24-
Libs string `json:"libs,omitempty"`
24+
Libs string `json:"libs"`
2525
Include []string `json:"include"`
26-
TrimPrefixes []string `json:"trimPrefixes,omitempty"`
27-
Cplusplus bool `json:"cplusplus,omitempty"`
28-
Deps []string `json:"deps,omitempty"`
29-
KeepUnderScore bool `json:"keepUnderScore,omitempty"`
26+
TrimPrefixes []string `json:"trimPrefixes"`
27+
Cplusplus bool `json:"cplusplus"`
28+
Deps []string `json:"deps"`
29+
KeepUnderScore bool `json:"keepUnderScore"`
3030
Impl []ImplFiles `json:"impl,omitempty"`
31-
Mix bool `json:"mix,omitempty"`
32-
SymMap map[string]string `json:"symMap,omitempty"`
33-
TypeMap map[string]string `json:"typeMap,omitempty"`
34-
StaticLib bool `json:"staticLib,omitempty"`
35-
HeaderOnly bool `json:"headerOnly,omitempty"`
31+
Mix bool `json:"mix"`
32+
SymMap map[string]string `json:"symMap"`
33+
TypeMap map[string]string `json:"typeMap"`
34+
StaticLib bool `json:"staticLib"`
35+
HeaderOnly bool `json:"headerOnly"`
3636
}
3737

38+
// To make it easier for users to set up configuration files without
39+
// having to remember various fields, the configuration file is written
40+
// with all empty fields by default except for the Impl field.
3841
func NewDefault() *Config {
39-
return &Config{}
42+
return &Config{
43+
Name: "",
44+
CFlags: "",
45+
Libs: "",
46+
Include: []string{},
47+
TrimPrefixes: []string{},
48+
Cplusplus: false,
49+
Deps: []string{},
50+
KeepUnderScore: false,
51+
Impl: []ImplFiles{},
52+
Mix: false,
53+
SymMap: map[string]string{},
54+
TypeMap: map[string]string{},
55+
StaticLib: false,
56+
HeaderOnly: false,
57+
}
4058
}
4159

4260
type SymbolInfo struct {

0 commit comments

Comments
 (0)