Generate error data at build time.

This avoids cluttering up the diff and making merge conflicts a pain.  It does,
however, mean we need to generate err_data.c ahead of time in Chromium and
likely other downstream builds. It also adds a build dependency on Go.

Change-Id: I6e0513ed9f50cfb030f7a523ea28519590977104
Reviewed-on: https://boringssl-review.googlesource.com/3790
Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
David Benjamin 2015-03-05 01:19:27 -05:00 committed by Adam Langley
parent f46cea8cd8
commit d27eda00a4
7 changed files with 58 additions and 2588 deletions

View File

@ -19,7 +19,8 @@ Build Prerequisites:
with Platform SDK 8.1 or later are supported. Recent versions of GCC and
Clang should work on non-Windows platforms, and maybe on Windows too.
* Go[5] is required for running tests, but not for building.
* Go[5] is required. If not found by CMake, the go executable may be
configured explicitly by setting GO_EXECUTABLE.
Using Ninja (note the 'N' is capitalized in the cmake invocation):

View File

@ -4,6 +4,11 @@ project (BoringSSL)
find_package(Perl REQUIRED)
find_program(GO_EXECUTABLE go)
if (NOT GO_EXECUTABLE)
message(FATAL_ERROR "Could not find Go")
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -ggdb -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -ggdb -std=c++0x -fvisibility=hidden")

View File

@ -1,11 +1,43 @@
include_directories(. .. ../../include)
add_custom_command(
OUTPUT err_data.c
COMMAND ${GO_EXECUTABLE} run err_data_generate.go > ${CMAKE_CURRENT_BINARY_DIR}/err_data.c
DEPENDS
err_data_generate.go
asn1.errordata
bio.errordata
bn.errordata
buf.errordata
cipher.errordata
conf.errordata
crypto.errordata
dh.errordata
digest.errordata
dsa.errordata
ecdh.errordata
ecdsa.errordata
ec.errordata
engine.errordata
evp.errordata
hkdf.errordata
obj.errordata
pem.errordata
pkcs8.errordata
rsa.errordata
ssl.errordata
x509.errordata
x509v3.errordata
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_library(
err
OBJECT
err.c
err_data.c
err_impl.c
)

View File

@ -126,6 +126,14 @@
#include <openssl/thread.h>
extern const uint32_t kOpenSSLFunctionValues[];
extern const size_t kOpenSSLFunctionValuesLen;
extern const char kOpenSSLFunctionStringData[];
extern const uint32_t kOpenSSLReasonValues[];
extern const size_t kOpenSSLReasonValuesLen;
extern const char kOpenSSLReasonStringData[];
/* err_fns contains a pointer to the current error implementation. */
static const struct ERR_FNS_st *err_fns = NULL;
extern const struct ERR_FNS_st openssl_err_default_impl;
@ -423,8 +431,6 @@ void ERR_error_string_n(uint32_t packed_error, char *buf, size_t len) {
}
}
#include "err_data.h"
// err_string_cmp is a compare function for searching error values with
// |bsearch| in |err_string_lookup|.
static int err_string_cmp(const void *a, const void *b) {
@ -545,9 +551,9 @@ const char *ERR_func_error_string(uint32_t packed_error) {
}
return err_string_lookup(ERR_GET_LIB(packed_error),
ERR_GET_FUNC(packed_error), kFunctionValues,
sizeof(kFunctionValues) / sizeof(kFunctionValues[0]),
kFunctionStringData);
ERR_GET_FUNC(packed_error), kOpenSSLFunctionValues,
kOpenSSLFunctionValuesLen,
kOpenSSLFunctionStringData);
}
const char *ERR_reason_error_string(uint32_t packed_error) {
@ -582,9 +588,8 @@ const char *ERR_reason_error_string(uint32_t packed_error) {
}
}
return err_string_lookup(lib, reason, kReasonValues,
sizeof(kReasonValues) / sizeof(kReasonValues[0]),
kReasonStringData);
return err_string_lookup(lib, reason, kOpenSSLReasonValues,
kOpenSSLReasonValuesLen, kOpenSSLReasonStringData);
}
void ERR_print_errors_cb(ERR_print_errors_callback_t callback, void *ctx) {

File diff suppressed because it is too large Load Diff

View File

@ -140,13 +140,16 @@ func (st *stringList) WriteTo(out stringWriter, name string) {
list := st.buildList()
fmt.Fprintf(os.Stderr, "%s: %d bytes of list and %d bytes of string data.\n", name, 4*len(list), len(st.stringData))
out.WriteString("static const uint32_t k" + name + "Values[] = {\n")
values := "kOpenSSL" + name + "Values"
out.WriteString("const uint32_t " + values + "[] = {\n")
for _, v := range list {
fmt.Fprintf(out, " 0x%x,\n", v)
}
out.WriteString("};\n\n")
out.WriteString("const size_t " + values + "Len = sizeof(" + values + ") / sizeof(" + values + "[0]);\n\n");
out.WriteString("static const char k" + name + "StringData[] =\n \"")
stringData := "kOpenSSL" + name + "StringData"
out.WriteString("const char " + stringData + "[] =\n \"")
for i, c := range st.stringData {
if c == 0 {
out.WriteString("\\0\"\n \"")
@ -267,6 +270,7 @@ func main() {
/* This file was generated by err_data_generate.go. */
#include <openssl/base.h>
#include <openssl/err.h>
#include <openssl/type_check.h>

View File

@ -21,7 +21,6 @@ import (
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"sort"
"strconv"
@ -132,25 +131,6 @@ func makeErrors(reset bool) error {
outputStrings(dataFile, lib, typeReasons, reasons)
dataFile.Close()
generateCmd := exec.Command("go", "run", "err_data_generate.go")
generateCmd.Dir = errDir
errDataH, err := os.OpenFile(filepath.Join(errDir, "err_data.h"), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
if err != nil {
return err
}
defer errDataH.Close()
generateCmd.Stdout = errDataH
generateCmd.Stderr = os.Stderr
if err := generateCmd.Start(); err != nil {
return err
}
if err := generateCmd.Wait(); err != nil {
return err
}
return nil
}