Update DAP protocol to 1.41.0
Update the script to include the DAP version in the file headers. Remove http file caching. Was never used.
This commit is contained in:
@@ -33,29 +33,29 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
cache = flag.String("cache", "", "File cache of the .json schema")
|
||||
)
|
||||
|
||||
const (
|
||||
jsonURL = "https://raw.githubusercontent.com/microsoft/vscode-debugadapter-node/master/debugProtocol.json"
|
||||
protocolURL = "https://raw.githubusercontent.com/microsoft/vscode-debugadapter-node/master/debugProtocol.json"
|
||||
packageURL = "https://raw.githubusercontent.com/microsoft/vscode-debugadapter-node/master/protocol/package.json"
|
||||
|
||||
versionTag = "${version}"
|
||||
commonPrologue = `// Copyright 2019 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Generated with protocol_gen.go -- do not edit this file.
|
||||
// go run scripts/protocol_gen/protocol_gen.go
|
||||
// Generated with protocol_gen.go -- do not edit this file.
|
||||
// go run scripts/protocol_gen/protocol_gen.go
|
||||
//
|
||||
// DAP version ${version}
|
||||
`
|
||||
|
||||
headerPrologue = commonPrologue + `
|
||||
@@ -527,18 +527,20 @@ type cppFilePaths map[structType]string
|
||||
type cppFiles map[structType]*os.File
|
||||
|
||||
func run() error {
|
||||
data, err := loadJSONFile()
|
||||
if err != nil {
|
||||
pkg := struct {
|
||||
Version string `json:"version"`
|
||||
}{}
|
||||
if err := loadJSONFile(packageURL, &pkg); err != nil {
|
||||
return err
|
||||
}
|
||||
r := root{}
|
||||
d := json.NewDecoder(bytes.NewReader(data))
|
||||
if err := d.Decode(&r); err != nil {
|
||||
|
||||
protocol := root{}
|
||||
if err := loadJSONFile(protocolURL, &protocol); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
hPath, cppPaths := outputPaths()
|
||||
if err := emitFiles(&r, hPath, cppPaths); err != nil {
|
||||
if err := emitFiles(&protocol, hPath, cppPaths, pkg.Version); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -551,12 +553,14 @@ func run() error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("clang-format not found on PATH. Please format before committing.")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func emitFiles(r *root, hPath string, cppPaths map[structType]string) error {
|
||||
func emitFiles(r *root, hPath string, cppPaths map[structType]string, version string) error {
|
||||
h, err := os.Create(hPath)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -572,9 +576,9 @@ func emitFiles(r *root, hPath string, cppPaths map[structType]string) error {
|
||||
defer f.Close()
|
||||
}
|
||||
|
||||
h.WriteString(headerPrologue)
|
||||
h.WriteString(strings.ReplaceAll(headerPrologue, versionTag, version))
|
||||
for _, f := range cppFiles {
|
||||
f.WriteString(cppPrologue)
|
||||
f.WriteString(strings.ReplaceAll(cppPrologue, versionTag, version))
|
||||
}
|
||||
|
||||
structs, err := buildStructs(r)
|
||||
@@ -618,25 +622,19 @@ func emitFiles(r *root, hPath string, cppPaths map[structType]string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadJSONFile() ([]byte, error) {
|
||||
if *cache != "" {
|
||||
data, err := ioutil.ReadFile(*cache)
|
||||
if err == nil {
|
||||
return data, nil
|
||||
}
|
||||
}
|
||||
resp, err := http.Get(jsonURL)
|
||||
func loadJSONFile(url string, obj interface{}) error {
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
if *cache != "" {
|
||||
ioutil.WriteFile(*cache, data, 0777)
|
||||
if err := json.NewDecoder(bytes.NewReader(data)).Decode(obj); err != nil {
|
||||
return err
|
||||
}
|
||||
return data, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func outputPaths() (string, cppFilePaths) {
|
||||
|
||||
Reference in New Issue
Block a user