summaryrefslogtreecommitdiffstats
path: root/src/util/make_errors.go
diff options
context:
space:
mode:
authorAdam Langley <agl@google.com>2015-05-11 17:20:37 -0700
committerKenny Root <kroot@google.com>2015-05-12 23:06:14 +0000
commite9ada863a7b3e81f5d2b1e3bdd2305da902a87f5 (patch)
tree6e43e34595ecf887c26c32b86d8ab097fe8cac64 /src/util/make_errors.go
parentb3106a0cc1493bbe0505c0ec0ce3da4ca90a29ae (diff)
downloadexternal_boringssl-e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5.zip
external_boringssl-e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5.tar.gz
external_boringssl-e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5.tar.bz2
external/boringssl: bump revision.
This change bumps the BoringSSL revision to the current tip-of-tree. Change-Id: I91d5bf467e16e8d86cb19a4de873985f524e5faa
Diffstat (limited to 'src/util/make_errors.go')
-rw-r--r--src/util/make_errors.go106
1 files changed, 46 insertions, 60 deletions
diff --git a/src/util/make_errors.go b/src/util/make_errors.go
index 5fd75e2..dc8039a 100644
--- a/src/util/make_errors.go
+++ b/src/util/make_errors.go
@@ -36,17 +36,20 @@ const reservedReasonCode = 1000
var resetFlag *bool = flag.Bool("reset", false, "If true, ignore current assignments and reassign from scratch")
func makeErrors(reset bool) error {
- dirName, err := os.Getwd()
+ topLevelPath, err := findToplevel()
if err != nil {
return err
}
- lib := filepath.Base(dirName)
- headerPath, err := findHeader(lib + ".h")
+ dirName, err := os.Getwd()
if err != nil {
return err
}
- sourcePath := lib + "_error.c"
+
+ lib := filepath.Base(dirName)
+ headerPath := filepath.Join(topLevelPath, "include", "openssl", lib+".h")
+ errDir := filepath.Join(topLevelPath, "crypto", "err")
+ dataPath := filepath.Join(errDir, lib+".errordata")
headerFile, err := os.Open(headerPath)
if err != nil {
@@ -90,7 +93,7 @@ func makeErrors(reset bool) error {
}
for _, name := range filenames {
- if !strings.HasSuffix(name, ".c") || name == sourcePath {
+ if !strings.HasSuffix(name, ".c") {
continue
}
@@ -119,55 +122,32 @@ func makeErrors(reset bool) error {
}
os.Rename(headerPath+".tmp", headerPath)
- sourceFile, err := os.OpenFile(sourcePath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
+ dataFile, err := os.OpenFile(dataPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
return err
}
- defer sourceFile.Close()
- fmt.Fprintf(sourceFile, `/* Copyright (c) 2014, Google Inc.
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
-
-#include <openssl/err.h>
-
-#include <openssl/%s.h>
-
-const ERR_STRING_DATA %s_error_string_data[] = {
-`, lib, prefix)
- outputStrings(sourceFile, lib, typeFunctions, functions)
- outputStrings(sourceFile, lib, typeReasons, reasons)
-
- sourceFile.WriteString(" {0, NULL},\n};\n")
+ outputStrings(dataFile, lib, typeFunctions, functions)
+ outputStrings(dataFile, lib, typeReasons, reasons)
+ dataFile.Close()
return nil
}
-func findHeader(basename string) (path string, err error) {
- includeDir := filepath.Join("..", "include")
+func findToplevel() (path string, err error) {
+ path = ".."
+ buildingPath := filepath.Join(path, "BUILDING")
- fi, err := os.Stat(includeDir)
+ _, err = os.Stat(buildingPath)
if err != nil && os.IsNotExist(err) {
- includeDir = filepath.Join("..", includeDir)
- fi, err = os.Stat(includeDir)
+ path = filepath.Join("..", path)
+ buildingPath = filepath.Join(path, "BUILDING")
+ _, err = os.Stat(buildingPath)
}
if err != nil {
- return "", errors.New("cannot find path to include directory")
- }
- if !fi.IsDir() {
- return "", errors.New("include node is not a directory")
+ return "", errors.New("Cannot find BUILDING file at the top-level")
}
- return filepath.Join(includeDir, "openssl", basename), nil
+ return path, nil
}
type assignment struct {
@@ -295,18 +275,17 @@ func outputStrings(w io.Writer, lib string, ty int, assignments map[string]int)
sort.Strings(keys)
for _, key := range keys {
- var pack string
- if ty == typeFunctions {
- pack = key + ", 0"
- } else {
- pack = "0, " + key
+ typeString := "function"
+ if ty == typeReasons {
+ typeString = "reason"
}
-
- fmt.Fprintf(w, " {ERR_PACK(ERR_LIB_%s, %s), \"%s\"},\n", lib, pack, key[prefixLen:])
+ fmt.Fprintf(w, "%s,%s,%d,%s\n", lib, typeString, assignments[key], key[prefixLen:])
}
}
func assignNewValues(assignments map[string]int, reserved int) {
+ // Needs to be in sync with the reason limit in
+ // |ERR_reason_error_string|.
max := 99
for _, value := range assignments {
@@ -320,16 +299,23 @@ func assignNewValues(assignments map[string]int, reserved int) {
max++
+ // Sort the keys, so this script is reproducible.
+ keys := make([]string, 0, len(assignments))
for key, value := range assignments {
if value == -1 {
- if reserved >= 0 && max >= reserved {
- // If this happens, try passing
- // -reset. Otherwise bump up reservedReasonCode.
- panic("Automatically-assigned values exceeded limit!")
- }
- assignments[key] = max
- max++
+ keys = append(keys, key)
+ }
+ }
+ sort.Strings(keys)
+
+ for _, key := range keys {
+ if reserved >= 0 && max >= reserved {
+ // If this happens, try passing -reset. Otherwise bump
+ // up reservedReasonCode.
+ panic("Automatically-assigned values exceeded limit!")
}
+ assignments[key] = max
+ max++
}
}
@@ -360,8 +346,7 @@ func addFunctionsAndReasons(functions, reasons map[string]int, filename, prefix
}
defer file.Close()
- prefix += "_"
- reasonPrefix := prefix + "R_"
+ reasonPrefix := prefix + "_R_"
var currentFunction string
scanner := bufio.NewScanner(file)
@@ -388,8 +373,9 @@ func addFunctionsAndReasons(functions, reasons map[string]int, filename, prefix
}
}
- if strings.Contains(line, "OPENSSL_PUT_ERROR(") {
- functionToken := prefix + "F_" + currentFunction
+ // Do not include cross-module error lines.
+ if strings.Contains(line, "OPENSSL_PUT_ERROR(" + prefix + ",") {
+ functionToken := prefix + "_F_" + currentFunction
if _, ok := functions[functionToken]; !ok {
functions[functionToken] = -1
}
@@ -399,7 +385,7 @@ func addFunctionsAndReasons(functions, reasons map[string]int, filename, prefix
handleDeclareMacro(line, "_F_", "OPENSSL_DECLARE_ERROR_FUNCTION(", functions)
for len(line) > 0 {
- i := strings.Index(line, prefix)
+ i := strings.Index(line, prefix + "_")
if i == -1 {
break
}