Auto-update cmakelists on protocol sync, update to 1.59.0 (#93)
* CMake: Fix target options * update CMake package version after protocol sync * Update protocol to 1.59.0 * protocol_gen: change OneOf to `object` type The DAP spec introduces ambiguities with its particular uses of OneOf, which means that we can't deserialize the variants generated from it. Just set OneOf to an `object` type, like godap does.
This commit is contained in:
@@ -487,8 +487,8 @@ func (r *root) getType(def *definition) (builtType cppType, err error) {
|
||||
return ref.def.cppType, nil
|
||||
}
|
||||
|
||||
// The DAP spec introduces ambiguities with its particular uses of OneOf, just set to object
|
||||
if len(def.OneOf) != 0 {
|
||||
args := make([]string, len(def.OneOf))
|
||||
deps := make([]cppType, len(def.OneOf))
|
||||
for i, oneOf := range def.OneOf {
|
||||
if oneOf == nil {
|
||||
@@ -499,10 +499,9 @@ func (r *root) getType(def *definition) (builtType cppType, err error) {
|
||||
return nil, err
|
||||
}
|
||||
deps[i] = elTy
|
||||
args[i] = elTy.Name()
|
||||
}
|
||||
return &cppBasicType{
|
||||
name: "variant<" + strings.Join(args, ", ") + ">",
|
||||
name: "object",
|
||||
desc: def.Description,
|
||||
deps: deps,
|
||||
}, nil
|
||||
@@ -681,11 +680,15 @@ func run() error {
|
||||
return fmt.Errorf("Failed to load JSON file from '%v': %w", protocolURL, err)
|
||||
}
|
||||
|
||||
hPath, cppPaths := outputPaths()
|
||||
hPath, cppPaths, cMakeListsPath := outputPaths()
|
||||
if err := emitFiles(&protocol, hPath, cppPaths, pkg.Version); err != nil {
|
||||
return fmt.Errorf("Failed to emit files: %w", err)
|
||||
}
|
||||
|
||||
if err := updateCMakePackageVersion(cMakeListsPath, pkg.Version); err != nil {
|
||||
return fmt.Errorf("Failed to update CMakeLists.txt: %w", err)
|
||||
}
|
||||
|
||||
if clangfmt, err := exec.LookPath("clang-format"); err == nil {
|
||||
if out, err := exec.Command(clangfmt, "-i", hPath).CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("Failed to run clang-format on '%v':\n%v\n%w", hPath, string(out), err)
|
||||
@@ -702,6 +705,23 @@ func run() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Updates package version in CMakeLists.txt to current
|
||||
func updateCMakePackageVersion(cMakeListsPath string, version string) error {
|
||||
text, err := os.ReadFile(cMakeListsPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lines := strings.Split(string(text), "\n")
|
||||
for i, line := range lines {
|
||||
if strings.Contains(line, "project(cppdap") {
|
||||
lines[i] = "project(cppdap VERSION " + version + " LANGUAGES CXX C)"
|
||||
break
|
||||
}
|
||||
}
|
||||
output := strings.Join(lines, "\n")
|
||||
return os.WriteFile(cMakeListsPath, []byte(output), 0644)
|
||||
}
|
||||
|
||||
// emitFiles() opens each of the C++ files, generates the cppType definitions
|
||||
// from the schema root, then writes the types to the C++ files in dependency
|
||||
// order.
|
||||
@@ -790,8 +810,8 @@ func loadJSONFile(url string, obj interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// outputPaths() returns a path to the target C++ .h file and .cpp files
|
||||
func outputPaths() (string, cppTargetFilePaths) {
|
||||
// outputPaths() returns a path to the target C++ .h file and .cpp files, and the CMakeLists.txt
|
||||
func outputPaths() (string, cppTargetFilePaths, string) {
|
||||
_, thisFile, _, _ := runtime.Caller(1)
|
||||
thisDir := path.Dir(thisFile)
|
||||
h := path.Join(thisDir, "../../include/dap/protocol.h")
|
||||
@@ -801,5 +821,6 @@ func outputPaths() (string, cppTargetFilePaths) {
|
||||
event: path.Join(thisDir, "../../src/protocol_events.cpp"),
|
||||
types: path.Join(thisDir, "../../src/protocol_types.cpp"),
|
||||
}
|
||||
return h, cpp
|
||||
CMakeLists := path.Join(thisDir, "../../CMakeLists.txt")
|
||||
return h, cpp, CMakeLists
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user