diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/all_tests.go | 92 | ||||
-rw-r--r-- | src/util/all_tests.json | 58 | ||||
-rw-r--r-- | src/util/doc.go | 76 | ||||
-rw-r--r-- | src/util/generate_build_files.py | 224 | ||||
-rw-r--r-- | src/util/make_errors.go | 98 |
5 files changed, 367 insertions, 181 deletions
diff --git a/src/util/all_tests.go b/src/util/all_tests.go index 49954df..566c3f7 100644 --- a/src/util/all_tests.go +++ b/src/util/all_tests.go @@ -41,63 +41,6 @@ var ( type test []string -var tests = []test{ - {"crypto/base64/base64_test"}, - {"crypto/bio/bio_test"}, - {"crypto/bn/bn_test"}, - {"crypto/bytestring/bytestring_test"}, - {"crypto/cipher/aead_test", "aes-128-gcm", "crypto/cipher/test/aes_128_gcm_tests.txt"}, - {"crypto/cipher/aead_test", "aes-128-key-wrap", "crypto/cipher/test/aes_128_key_wrap_tests.txt"}, - {"crypto/cipher/aead_test", "aes-256-gcm", "crypto/cipher/test/aes_256_gcm_tests.txt"}, - {"crypto/cipher/aead_test", "aes-256-key-wrap", "crypto/cipher/test/aes_256_key_wrap_tests.txt"}, - {"crypto/cipher/aead_test", "chacha20-poly1305", "crypto/cipher/test/chacha20_poly1305_tests.txt"}, - {"crypto/cipher/aead_test", "rc4-md5-tls", "crypto/cipher/test/rc4_md5_tls_tests.txt"}, - {"crypto/cipher/aead_test", "rc4-sha1-tls", "crypto/cipher/test/rc4_sha1_tls_tests.txt"}, - {"crypto/cipher/aead_test", "aes-128-cbc-sha1-tls", "crypto/cipher/test/aes_128_cbc_sha1_tls_tests.txt"}, - {"crypto/cipher/aead_test", "aes-128-cbc-sha1-tls-implicit-iv", "crypto/cipher/test/aes_128_cbc_sha1_tls_implicit_iv_tests.txt"}, - {"crypto/cipher/aead_test", "aes-128-cbc-sha256-tls", "crypto/cipher/test/aes_128_cbc_sha256_tls_tests.txt"}, - {"crypto/cipher/aead_test", "aes-256-cbc-sha1-tls", "crypto/cipher/test/aes_256_cbc_sha1_tls_tests.txt"}, - {"crypto/cipher/aead_test", "aes-256-cbc-sha1-tls-implicit-iv", "crypto/cipher/test/aes_256_cbc_sha1_tls_implicit_iv_tests.txt"}, - {"crypto/cipher/aead_test", "aes-256-cbc-sha256-tls", "crypto/cipher/test/aes_256_cbc_sha256_tls_tests.txt"}, - {"crypto/cipher/aead_test", "aes-256-cbc-sha384-tls", "crypto/cipher/test/aes_256_cbc_sha384_tls_tests.txt"}, - {"crypto/cipher/aead_test", "des-ede3-cbc-sha1-tls", "crypto/cipher/test/des_ede3_cbc_sha1_tls_tests.txt"}, - {"crypto/cipher/aead_test", "des-ede3-cbc-sha1-tls-implicit-iv", "crypto/cipher/test/des_ede3_cbc_sha1_tls_implicit_iv_tests.txt"}, - {"crypto/cipher/aead_test", "rc4-md5-ssl3", "crypto/cipher/test/rc4_md5_ssl3_tests.txt"}, - {"crypto/cipher/aead_test", "rc4-sha1-ssl3", "crypto/cipher/test/rc4_sha1_ssl3_tests.txt"}, - {"crypto/cipher/aead_test", "aes-128-cbc-sha1-ssl3", "crypto/cipher/test/aes_128_cbc_sha1_ssl3_tests.txt"}, - {"crypto/cipher/aead_test", "aes-256-cbc-sha1-ssl3", "crypto/cipher/test/aes_256_cbc_sha1_ssl3_tests.txt"}, - {"crypto/cipher/aead_test", "des-ede3-cbc-sha1-ssl3", "crypto/cipher/test/des_ede3_cbc_sha1_ssl3_tests.txt"}, - {"crypto/cipher/aead_test", "aes-128-ctr-hmac-sha256", "crypto/cipher/test/aes_128_ctr_hmac_sha256.txt"}, - {"crypto/cipher/aead_test", "aes-256-ctr-hmac-sha256", "crypto/cipher/test/aes_256_ctr_hmac_sha256.txt"}, - {"crypto/cipher/cipher_test", "crypto/cipher/test/cipher_test.txt"}, - {"crypto/cmac/cmac_test"}, - {"crypto/constant_time_test"}, - {"crypto/dh/dh_test"}, - {"crypto/digest/digest_test"}, - {"crypto/dsa/dsa_test"}, - {"crypto/ec/ec_test"}, - {"crypto/ec/example_mul"}, - {"crypto/ecdsa/ecdsa_test"}, - {"crypto/err/err_test"}, - {"crypto/evp/evp_extra_test"}, - {"crypto/evp/evp_test", "crypto/evp/evp_tests.txt"}, - {"crypto/evp/evp_test", "crypto/hmac/hmac_tests.txt"}, - {"crypto/evp/pbkdf_test"}, - {"crypto/hkdf/hkdf_test"}, - {"crypto/hmac/hmac_test", "crypto/hmac/hmac_tests.txt"}, - {"crypto/lhash/lhash_test"}, - {"crypto/modes/gcm_test"}, - {"crypto/pkcs8/pkcs12_test"}, - {"crypto/refcount_test"}, - {"crypto/rsa/rsa_test"}, - {"crypto/thread_test"}, - {"crypto/x509/pkcs7_test"}, - {"crypto/x509v3/tab_test"}, - {"crypto/x509v3/v3name_test"}, - {"ssl/pqueue/pqueue_test"}, - {"ssl/ssl_test"}, -} - // testOutput is a representation of Chromium's JSON test result format. See // https://www.chromium.org/developers/the-json-test-results-format type testOutput struct { @@ -254,8 +197,43 @@ func shortTestName(test test) string { return strings.Join(args, " ") } +// setWorkingDirectory walks up directories as needed until the current working +// directory is the top of a BoringSSL checkout. +func setWorkingDirectory() { + for i := 0; i < 64; i++ { + if _, err := os.Stat("BUILDING.md"); err == nil { + return + } + os.Chdir("..") + } + + panic("Couldn't find BUILDING.md in a parent directory!") +} + +func parseTestConfig(filename string) ([]test, error) { + in, err := os.Open(filename) + if err != nil { + return nil, err + } + defer in.Close() + + decoder := json.NewDecoder(in) + var result []test + if err := decoder.Decode(&result); err != nil { + return nil, err + } + return result, nil +} + func main() { flag.Parse() + setWorkingDirectory() + + tests, err := parseTestConfig("util/all_tests.json") + if err != nil { + fmt.Printf("Failed to parse input: %s\n", err) + os.Exit(1) + } testOutput := newTestOutput() var failed []test diff --git a/src/util/all_tests.json b/src/util/all_tests.json new file mode 100644 index 0000000..a6daa2f --- /dev/null +++ b/src/util/all_tests.json @@ -0,0 +1,58 @@ +[ + ["crypto/aes/aes_test"], + ["crypto/base64/base64_test"], + ["crypto/bio/bio_test"], + ["crypto/bn/bn_test"], + ["crypto/bytestring/bytestring_test"], + ["crypto/cipher/aead_test", "aes-128-gcm", "crypto/cipher/test/aes_128_gcm_tests.txt"], + ["crypto/cipher/aead_test", "aes-128-key-wrap", "crypto/cipher/test/aes_128_key_wrap_tests.txt"], + ["crypto/cipher/aead_test", "aes-256-gcm", "crypto/cipher/test/aes_256_gcm_tests.txt"], + ["crypto/cipher/aead_test", "aes-256-key-wrap", "crypto/cipher/test/aes_256_key_wrap_tests.txt"], + ["crypto/cipher/aead_test", "chacha20-poly1305", "crypto/cipher/test/chacha20_poly1305_tests.txt"], + ["crypto/cipher/aead_test", "rc4-md5-tls", "crypto/cipher/test/rc4_md5_tls_tests.txt"], + ["crypto/cipher/aead_test", "rc4-sha1-tls", "crypto/cipher/test/rc4_sha1_tls_tests.txt"], + ["crypto/cipher/aead_test", "aes-128-cbc-sha1-tls", "crypto/cipher/test/aes_128_cbc_sha1_tls_tests.txt"], + ["crypto/cipher/aead_test", "aes-128-cbc-sha1-tls-implicit-iv", "crypto/cipher/test/aes_128_cbc_sha1_tls_implicit_iv_tests.txt"], + ["crypto/cipher/aead_test", "aes-128-cbc-sha256-tls", "crypto/cipher/test/aes_128_cbc_sha256_tls_tests.txt"], + ["crypto/cipher/aead_test", "aes-256-cbc-sha1-tls", "crypto/cipher/test/aes_256_cbc_sha1_tls_tests.txt"], + ["crypto/cipher/aead_test", "aes-256-cbc-sha1-tls-implicit-iv", "crypto/cipher/test/aes_256_cbc_sha1_tls_implicit_iv_tests.txt"], + ["crypto/cipher/aead_test", "aes-256-cbc-sha256-tls", "crypto/cipher/test/aes_256_cbc_sha256_tls_tests.txt"], + ["crypto/cipher/aead_test", "aes-256-cbc-sha384-tls", "crypto/cipher/test/aes_256_cbc_sha384_tls_tests.txt"], + ["crypto/cipher/aead_test", "des-ede3-cbc-sha1-tls", "crypto/cipher/test/des_ede3_cbc_sha1_tls_tests.txt"], + ["crypto/cipher/aead_test", "des-ede3-cbc-sha1-tls-implicit-iv", "crypto/cipher/test/des_ede3_cbc_sha1_tls_implicit_iv_tests.txt"], + ["crypto/cipher/aead_test", "rc4-md5-ssl3", "crypto/cipher/test/rc4_md5_ssl3_tests.txt"], + ["crypto/cipher/aead_test", "rc4-sha1-ssl3", "crypto/cipher/test/rc4_sha1_ssl3_tests.txt"], + ["crypto/cipher/aead_test", "aes-128-cbc-sha1-ssl3", "crypto/cipher/test/aes_128_cbc_sha1_ssl3_tests.txt"], + ["crypto/cipher/aead_test", "aes-256-cbc-sha1-ssl3", "crypto/cipher/test/aes_256_cbc_sha1_ssl3_tests.txt"], + ["crypto/cipher/aead_test", "des-ede3-cbc-sha1-ssl3", "crypto/cipher/test/des_ede3_cbc_sha1_ssl3_tests.txt"], + ["crypto/cipher/aead_test", "aes-128-ctr-hmac-sha256", "crypto/cipher/test/aes_128_ctr_hmac_sha256.txt"], + ["crypto/cipher/aead_test", "aes-256-ctr-hmac-sha256", "crypto/cipher/test/aes_256_ctr_hmac_sha256.txt"], + ["crypto/cipher/cipher_test", "crypto/cipher/test/cipher_test.txt"], + ["crypto/cmac/cmac_test"], + ["crypto/constant_time_test"], + ["crypto/dh/dh_test"], + ["crypto/digest/digest_test"], + ["crypto/dsa/dsa_test"], + ["crypto/ec/ec_test"], + ["crypto/ec/example_mul"], + ["crypto/ecdsa/ecdsa_test"], + ["crypto/err/err_test"], + ["crypto/evp/evp_extra_test"], + ["crypto/evp/evp_test", "crypto/evp/evp_tests.txt"], + ["crypto/evp/pbkdf_test"], + ["crypto/hkdf/hkdf_test"], + ["crypto/hmac/hmac_test", "crypto/hmac/hmac_tests.txt"], + ["crypto/lhash/lhash_test"], + ["crypto/modes/gcm_test"], + ["crypto/pkcs8/pkcs8_test"], + ["crypto/pkcs8/pkcs12_test"], + ["crypto/poly1305/poly1305_test", "crypto/poly1305/poly1305_test.txt"], + ["crypto/refcount_test"], + ["crypto/rsa/rsa_test"], + ["crypto/thread_test"], + ["crypto/x509/pkcs7_test"], + ["crypto/x509v3/tab_test"], + ["crypto/x509v3/v3name_test"], + ["ssl/pqueue/pqueue_test"], + ["ssl/ssl_test"] +] diff --git a/src/util/doc.go b/src/util/doc.go index 540d6ca..23cd5f4 100644 --- a/src/util/doc.go +++ b/src/util/doc.go @@ -48,9 +48,8 @@ type HeaderSection struct { // Preamble contains a comment for a group of functions. Preamble []string Decls []HeaderDecl - // Num is just the index of the section. It's included in order to help - // text/template generate anchors. - Num int + // Anchor, if non-empty, is the URL fragment to use in anchor tags. + Anchor string // IsPrivate is true if the section contains private functions (as // indicated by its name). IsPrivate bool @@ -65,10 +64,8 @@ type HeaderDecl struct { Name string // Decl contains the preformatted C declaration itself. Decl string - // Num is an index for the declaration, but the value is unique for all - // declarations in a HeaderFile. It's included in order to help - // text/template generate anchors. - Num int + // Anchor, if non-empty, is the URL fragment to use in anchor tags. + Anchor string } const ( @@ -192,14 +189,6 @@ func extractDecl(lines []string, lineNo int) (decl string, rest []string, restLi return } -func skipPast(s, skip string) string { - i := strings.Index(s, skip) - if i > 0 { - return s[i:] - } - return s -} - func skipLine(s string) string { i := strings.Index(s, "\n") if i > 0 { @@ -227,8 +216,9 @@ func getNameFromDecl(decl string) (string, bool) { } return decl[:i], true } - decl = skipPast(decl, "STACK_OF(") - decl = skipPast(decl, "LHASH_OF(") + decl = strings.TrimPrefix(decl, "OPENSSL_EXPORT ") + decl = strings.TrimPrefix(decl, "STACK_OF(") + decl = strings.TrimPrefix(decl, "LHASH_OF(") i := strings.Index(decl, "(") if i < 0 { return "", false @@ -243,6 +233,10 @@ func getNameFromDecl(decl string) (string, bool) { return decl[j+1 : i], true } +func sanitizeAnchor(name string) string { + return strings.Replace(name, " ", "-", -1) +} + func (config *Config) parseHeader(path string) (*HeaderFile, error) { headerPath := filepath.Join(config.BaseDirectory, path) @@ -314,7 +308,7 @@ func (config *Config) parseHeader(path string) (*HeaderFile, error) { } } - var sectionNumber, declNumber int + allAnchors := make(map[string]struct{}) for { // Start of a section. @@ -330,10 +324,7 @@ func (config *Config) parseHeader(path string) (*HeaderFile, error) { return nil, fmt.Errorf("blank line at start of section on line %d", lineNo) } - section := HeaderSection{ - Num: sectionNumber, - } - sectionNumber++ + var section HeaderSection if strings.HasPrefix(line, commentStart) { comment, rest, restLineNo, err := extractComment(lines, lineNo) @@ -341,8 +332,17 @@ func (config *Config) parseHeader(path string) (*HeaderFile, error) { return nil, err } if len(rest) > 0 && len(rest[0]) == 0 { + anchor := sanitizeAnchor(firstSentence(comment)) + if len(anchor) > 0 { + if _, ok := allAnchors[anchor]; ok { + return nil, fmt.Errorf("duplicate anchor: %s", anchor) + } + allAnchors[anchor] = struct{}{} + } + section.Preamble = comment section.IsPrivate = len(comment) > 0 && strings.HasPrefix(comment[0], "Private functions") + section.Anchor = anchor lines = rest[1:] lineNo = restLineNo + 1 } @@ -381,13 +381,18 @@ func (config *Config) parseHeader(path string) (*HeaderFile, error) { if last := len(section.Decls) - 1; len(name) == 0 && len(comment) == 0 && last >= 0 { section.Decls[last].Decl += "\n" + decl } else { + anchor := sanitizeAnchor(name) + // TODO(davidben): Enforce uniqueness. This is + // skipped because #ifdefs currently result in + // duplicate table-of-contents entries. + allAnchors[anchor] = struct{}{} + section.Decls = append(section.Decls, HeaderDecl{ Comment: comment, Name: name, Decl: decl, - Num: declNumber, + Anchor: anchor, }) - declNumber++ } if len(lines) > 0 && len(lines[0]) == 0 { @@ -451,7 +456,7 @@ again: if end > 0 { end += start w := strings.ToLower(string(s[start:end])) - if w == "a" || w == "an" || w == "deprecated:" { + if w == "a" || w == "an" { start = end + 1 goto again } @@ -495,9 +500,9 @@ func generate(outPath string, config *Config) (map[string]string, error) { <ol> {{range .Sections}} {{if not .IsPrivate}} - {{if .Preamble}}<li class="header"><a href="#section-{{.Num}}">{{.Preamble | firstSentence | html | markupPipeWords}}</a></li>{{end}} + {{if .Anchor}}<li class="header"><a href="#{{.Anchor}}">{{.Preamble | firstSentence | html | markupPipeWords}}</a></li>{{end}} {{range .Decls}} - {{if .Name}}<li><a href="#decl-{{.Num}}"><tt>{{.Name}}</tt></a></li>{{end}} + {{if .Anchor}}<li><a href="#{{.Anchor}}"><tt>{{.Name}}</tt></a></li>{{end}} {{end}} {{end}} {{end}} @@ -508,7 +513,7 @@ func generate(outPath string, config *Config) (map[string]string, error) { <div class="section"> {{if .Preamble}} <div class="sectionpreamble"> - <a name="section-{{.Num}}"> + <a{{if .Anchor}} name="{{.Anchor}}"{{end}}> {{range .Preamble}}<p>{{. | html | markupPipeWords}}</p>{{end}} </a> </div> @@ -516,7 +521,7 @@ func generate(outPath string, config *Config) (map[string]string, error) { {{range .Decls}} <div class="decl"> - <a name="decl-{{.Num}}"> + <a{{if .Anchor}} name="{{.Anchor}}"{{end}}> {{range .Comment}} <p>{{. | html | markupPipeWords | newlinesToBR | markupFirstWord}}</p> {{end}} @@ -605,6 +610,14 @@ func generateIndex(outPath string, config *Config, headerDescriptions map[string return nil } +func copyFile(outPath string, inFilePath string) error { + bytes, err := ioutil.ReadFile(inFilePath) + if err != nil { + return err + } + return ioutil.WriteFile(filepath.Join(outPath, filepath.Base(inFilePath)), bytes, 0666) +} + func main() { var ( configFlag *string = flag.String("config", "doc.config", "Location of config file") @@ -645,4 +658,9 @@ func main() { fmt.Printf("Failed to generate index: %s\n", err) os.Exit(1) } + + if err := copyFile(*outputDir, "doc.css"); err != nil { + fmt.Printf("Failed to copy static file: %s\n", err) + os.Exit(1) + } } diff --git a/src/util/generate_build_files.py b/src/util/generate_build_files.py index e534a56..2eae98a 100644 --- a/src/util/generate_build_files.py +++ b/src/util/generate_build_files.py @@ -19,6 +19,7 @@ import os import subprocess import sys +import json # OS_ARCH_COMBOS maps from OS and platform to the OpenSSL assembly "style" for @@ -68,7 +69,9 @@ class Chromium(object): gypi.write(self.header + '{\n \'variables\': {\n') self.PrintVariableSection( - gypi, 'boringssl_lib_sources', files['crypto'] + files['ssl']) + gypi, 'boringssl_ssl_sources', files['ssl']) + self.PrintVariableSection( + gypi, 'boringssl_crypto_sources', files['crypto']) for ((osname, arch), asm_files) in asm_outputs: self.PrintVariableSection(gypi, 'boringssl_%s_%s_sources' % @@ -133,6 +136,9 @@ class Android(object): """ + def ExtraFiles(self): + return ['android_compat_hacks.c', 'android_compat_keywrap.c'] + def PrintVariableSection(self, out, name, files): out.write('%s := \\\n' % name) for f in sorted(files): @@ -143,8 +149,7 @@ class Android(object): with open('sources.mk', 'w+') as makefile: makefile.write(self.header) - files['crypto'].append('android_compat_hacks.c') - files['crypto'].append('android_compat_keywrap.c') + files['crypto'].extend(self.ExtraFiles()) self.PrintVariableSection(makefile, 'crypto_sources', files['crypto']) self.PrintVariableSection(makefile, 'ssl_sources', files['ssl']) self.PrintVariableSection(makefile, 'tool_sources', files['tool']) @@ -154,6 +159,127 @@ class Android(object): makefile, '%s_%s_sources' % (osname, arch), asm_files) +class AndroidStandalone(Android): + """AndroidStandalone is for Android builds outside of the Android-system, i.e. + + for applications that wish wish to ship BoringSSL. + """ + + def ExtraFiles(self): + return [] + + +class Bazel(object): + """Bazel outputs files suitable for including in Bazel files.""" + + def __init__(self): + self.firstSection = True + self.header = \ +"""# This file is created by generate_build_files.py. Do not edit manually. + +""" + + def PrintVariableSection(self, out, name, files): + if not self.firstSection: + out.write('\n') + self.firstSection = False + + out.write('%s = [\n' % name) + for f in sorted(files): + out.write(' "%s",\n' % f) + out.write(']\n') + + def WriteFiles(self, files, asm_outputs): + with open('BUILD.generated', 'w+') as out: + out.write(self.header) + + self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers']) + self.PrintVariableSection( + out, 'ssl_internal_headers', files['ssl_internal_headers']) + self.PrintVariableSection(out, 'ssl_sources', files['ssl']) + self.PrintVariableSection(out, 'crypto_headers', files['crypto_headers']) + self.PrintVariableSection( + out, 'crypto_internal_headers', files['crypto_internal_headers']) + self.PrintVariableSection(out, 'crypto_sources', files['crypto']) + self.PrintVariableSection(out, 'tool_sources', files['tool']) + + for ((osname, arch), asm_files) in asm_outputs: + if osname is not 'linux': + continue + self.PrintVariableSection( + out, 'crypto_sources_%s' % arch, asm_files) + + with open('BUILD.generated_tests', 'w+') as out: + out.write(self.header) + + out.write('test_support_sources = [\n') + for filename in files['test_support']: + if os.path.basename(filename) == 'malloc.cc': + continue + out.write(' "%s",\n' % filename) + out.write('] + glob(["src/crypto/test/*.h"])\n\n') + + name_counts = {} + for test in files['tests']: + name = os.path.basename(test[0]) + name_counts[name] = name_counts.get(name, 0) + 1 + + first = True + for test in files['tests']: + name = os.path.basename(test[0]) + if name_counts[name] > 1: + if '/' in test[1]: + name += '_' + os.path.splitext(os.path.basename(test[1]))[0] + else: + name += '_' + test[1].replace('-', '_') + + if not first: + out.write('\n') + first = False + + src_prefix = 'src/' + test[0] + for src in files['test']: + if src.startswith(src_prefix): + src = src + break + else: + raise ValueError("Can't find source for %s" % test[0]) + + out.write('cc_test(\n') + out.write(' name = "%s",\n' % name) + out.write(' size = "small",\n') + out.write(' srcs = ["%s"] + test_support_sources,\n' % src) + + data_files = [] + if len(test) > 1: + + out.write(' args = [\n') + for arg in test[1:]: + if '/' in arg: + out.write(' "$(location src/%s)",\n' % arg) + data_files.append('src/%s' % arg) + else: + out.write(' "%s",\n' % arg) + out.write(' ],\n') + + out.write(' copts = boringssl_copts,\n') + + if len(data_files) > 0: + out.write(' data = [\n') + for filename in data_files: + out.write(' "%s",\n' % filename) + out.write(' ],\n') + + if 'ssl/' in test[0]: + out.write(' deps = [\n') + out.write(' ":crypto",\n') + out.write(' ":ssl",\n') + out.write(' ],\n') + else: + out.write(' deps = [":crypto"],\n') + out.write(')\n') + + def FindCMakeFiles(directory): """Returns list of all CMakeLists.txt files recursively in directory.""" cmakefiles = [] @@ -188,6 +314,10 @@ def AllFiles(dent, is_dir): return True +def SSLHeaderFiles(dent, is_dir): + return dent in ['ssl.h', 'tls1.h', 'ssl23.h', 'ssl3.h', 'dtls1.h'] + + def FindCFiles(directory, filter_func): """Recurses through directory and returns a list of paths to all the C source files that pass filter_func.""" @@ -208,6 +338,21 @@ def FindCFiles(directory, filter_func): return cfiles +def FindHeaderFiles(directory, filter_func): + """Recurses through directory and returns a list of paths to all the header files that pass filter_func.""" + hfiles = [] + + for (path, dirnames, filenames) in os.walk(directory): + for filename in filenames: + if not filename.endswith('.h'): + continue + if not filter_func(filename, False): + continue + hfiles.append(os.path.join(path, filename)) + + return hfiles + + def ExtractPerlAsmFromCMakeFile(cmakefile): """Parses the contents of the CMakeLists.txt file passed as an argument and returns a list of all the perlasm() directives found in the file.""" @@ -289,6 +434,9 @@ def WriteAsmFiles(perlasms): if not output.startswith('src'): raise ValueError('output missing src: %s' % output) output = os.path.join(outDir, output[4:]) + if output.endswith('-armx.${ASM_EXT}'): + output = output.replace('-armx', + '-armx64' if arch == 'aarch64' else '-armx32') output = output.replace('${ASM_EXT}', asm_ext) if arch in ArchForAsmFilename(filename): @@ -302,7 +450,7 @@ def WriteAsmFiles(perlasms): return asmfiles -def main(platform): +def main(platforms): crypto_c_files = FindCFiles(os.path.join('src', 'crypto'), NoTests) ssl_c_files = FindCFiles(os.path.join('src', 'ssl'), NoTests) tool_cc_files = FindCFiles(os.path.join('src', 'tool'), NoTests) @@ -320,36 +468,80 @@ def main(platform): test_c_files = FindCFiles(os.path.join('src', 'crypto'), OnlyTests) test_c_files += FindCFiles(os.path.join('src', 'ssl'), OnlyTests) + ssl_h_files = ( + FindHeaderFiles( + os.path.join('src', 'include', 'openssl'), + SSLHeaderFiles)) + + def NotSSLHeaderFiles(filename, is_dir): + return not SSLHeaderFiles(filename, is_dir) + crypto_h_files = ( + FindHeaderFiles( + os.path.join('src', 'include', 'openssl'), + NotSSLHeaderFiles)) + + ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests) + crypto_internal_h_files = FindHeaderFiles( + os.path.join('src', 'crypto'), NoTests) + + with open('src/util/all_tests.json', 'r') as f: + tests = json.load(f) + test_binaries = set([test[0] for test in tests]) + test_sources = set([ + test.replace('.cc', '').replace('.c', '').replace( + 'src/', + '') + for test in test_c_files]) + if test_binaries != test_sources: + print 'Test sources and configured tests do not match' + a = test_binaries.difference(test_sources) + if len(a) > 0: + print 'These tests are configured without sources: ' + str(a) + b = test_sources.difference(test_binaries) + if len(b) > 0: + print 'These test sources are not configured: ' + str(b) + files = { 'crypto': crypto_c_files, + 'crypto_headers': crypto_h_files, + 'crypto_internal_headers': crypto_internal_h_files, 'ssl': ssl_c_files, + 'ssl_headers': ssl_h_files, + 'ssl_internal_headers': ssl_internal_h_files, 'tool': tool_cc_files, 'test': test_c_files, 'test_support': test_support_cc_files, + 'tests': tests, } asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).iteritems()) - platform.WriteFiles(files, asm_outputs) + for platform in platforms: + platform.WriteFiles(files, asm_outputs) return 0 def Usage(): - print 'Usage: python %s [chromium|android]' % sys.argv[0] + print 'Usage: python %s [chromium|android|android-standalone|bazel]' % sys.argv[0] sys.exit(1) if __name__ == '__main__': - if len(sys.argv) != 2: - Usage() - - platform = None - if sys.argv[1] == 'chromium': - platform = Chromium() - elif sys.argv[1] == 'android': - platform = Android() - else: + if len(sys.argv) < 2: Usage() - sys.exit(main(platform)) + platforms = [] + for s in sys.argv[1:]: + if s == 'chromium' or s == 'gyp': + platforms.append(Chromium()) + elif s == 'android': + platforms.append(Android()) + elif s == 'android-standalone': + platforms.append(AndroidStandalone()) + elif s == 'bazel': + platforms.append(Bazel()) + else: + Usage() + + sys.exit(main(platforms)) diff --git a/src/util/make_errors.go b/src/util/make_errors.go index dc8039a..cc35409 100644 --- a/src/util/make_errors.go +++ b/src/util/make_errors.go @@ -25,7 +25,6 @@ import ( "sort" "strconv" "strings" - "unicode" ) // ssl.h reserves values 1000 and above for error codes corresponding to @@ -61,12 +60,11 @@ func makeErrors(reset bool) error { } prefix := strings.ToUpper(lib) - functions, reasons, err := parseHeader(prefix, headerFile) + reasons, err := parseHeader(prefix, headerFile) headerFile.Close() if reset { err = nil - functions = make(map[string]int) // Retain any reason codes above reservedReasonCode. newReasons := make(map[string]int) for key, value := range reasons { @@ -97,12 +95,11 @@ func makeErrors(reset bool) error { continue } - if err := addFunctionsAndReasons(functions, reasons, name, prefix); err != nil { + if err := addReasons(reasons, name, prefix); err != nil { return err } } - assignNewValues(functions, -1) assignNewValues(reasons, reservedReasonCode) headerFile, err = os.Open(headerPath) @@ -117,7 +114,7 @@ func makeErrors(reset bool) error { } defer newHeaderFile.Close() - if err := writeHeaderFile(newHeaderFile, headerFile, prefix, functions, reasons); err != nil { + if err := writeHeaderFile(newHeaderFile, headerFile, prefix, reasons); err != nil { return err } os.Rename(headerPath+".tmp", headerPath) @@ -127,8 +124,7 @@ func makeErrors(reset bool) error { return err } - outputStrings(dataFile, lib, typeFunctions, functions) - outputStrings(dataFile, lib, typeReasons, reasons) + outputStrings(dataFile, lib, reasons) dataFile.Close() return nil @@ -136,16 +132,16 @@ func makeErrors(reset bool) error { func findToplevel() (path string, err error) { path = ".." - buildingPath := filepath.Join(path, "BUILDING") + buildingPath := filepath.Join(path, "BUILDING.md") _, err = os.Stat(buildingPath) if err != nil && os.IsNotExist(err) { path = filepath.Join("..", path) - buildingPath = filepath.Join(path, "BUILDING") + buildingPath = filepath.Join(path, "BUILDING.md") _, err = os.Stat(buildingPath) } if err != nil { - return "", errors.New("Cannot find BUILDING file at the top-level") + return "", errors.New("Cannot find BUILDING.md file at the top-level") } return path, nil } @@ -183,7 +179,7 @@ func outputAssignments(w io.Writer, assignments map[string]int) { } } -func parseDefineLine(line, lib string) (typ int, key string, value int, ok bool) { +func parseDefineLine(line, lib string) (key string, value int, ok bool) { if !strings.HasPrefix(line, "#define ") { return } @@ -193,16 +189,8 @@ func parseDefineLine(line, lib string) (typ int, key string, value int, ok bool) return } - funcPrefix := lib + "_F_" - reasonPrefix := lib + "_R_" - key = fields[1] - switch { - case strings.HasPrefix(key, funcPrefix): - typ = typeFunctions - case strings.HasPrefix(key, reasonPrefix): - typ = typeReasons - default: + if !strings.HasPrefix(key, lib+"_R_") { return } @@ -215,7 +203,7 @@ func parseDefineLine(line, lib string) (typ int, key string, value int, ok bool) return } -func writeHeaderFile(w io.Writer, headerFile io.Reader, lib string, functions, reasons map[string]int) error { +func writeHeaderFile(w io.Writer, headerFile io.Reader, lib string, reasons map[string]int) error { var last []byte var haveLast, sawDefine bool newLine := []byte("\n") @@ -223,7 +211,7 @@ func writeHeaderFile(w io.Writer, headerFile io.Reader, lib string, functions, r scanner := bufio.NewScanner(headerFile) for scanner.Scan() { line := scanner.Text() - _, _, _, ok := parseDefineLine(line, lib) + _, _, ok := parseDefineLine(line, lib) if ok { sawDefine = true continue @@ -247,7 +235,6 @@ func writeHeaderFile(w io.Writer, headerFile io.Reader, lib string, functions, r return err } - outputAssignments(w, functions) outputAssignments(w, reasons) w.Write(newLine) @@ -259,14 +246,9 @@ func writeHeaderFile(w io.Writer, headerFile io.Reader, lib string, functions, r return nil } -const ( - typeFunctions = iota - typeReasons -) - -func outputStrings(w io.Writer, lib string, ty int, assignments map[string]int) { +func outputStrings(w io.Writer, lib string, assignments map[string]int) { lib = strings.ToUpper(lib) - prefixLen := len(lib + "_F_") + prefixLen := len(lib + "_R_") keys := make([]string, 0, len(assignments)) for key := range assignments { @@ -275,11 +257,7 @@ func outputStrings(w io.Writer, lib string, ty int, assignments map[string]int) sort.Strings(keys) for _, key := range keys { - typeString := "function" - if ty == typeReasons { - typeString = "reason" - } - fmt.Fprintf(w, "%s,%s,%d,%s\n", lib, typeString, assignments[key], key[prefixLen:]) + fmt.Fprintf(w, "%s,%d,%s\n", lib, assignments[key], key[prefixLen:]) } } @@ -339,7 +317,7 @@ func handleDeclareMacro(line, join, macroName string, m map[string]int) { } } -func addFunctionsAndReasons(functions, reasons map[string]int, filename, prefix string) error { +func addReasons(reasons map[string]int, filename, prefix string) error { file, err := os.Open(filename) if err != nil { return err @@ -347,45 +325,15 @@ func addFunctionsAndReasons(functions, reasons map[string]int, filename, prefix defer file.Close() reasonPrefix := prefix + "_R_" - var currentFunction string scanner := bufio.NewScanner(file) for scanner.Scan() { line := scanner.Text() - if len(line) > 0 && unicode.IsLetter(rune(line[0])) { - /* Function start */ - fields := strings.Fields(line) - for _, field := range fields { - if i := strings.Index(field, "("); i != -1 { - f := field[:i] - // The return type of some functions is - // a macro that contains a "(". - if f == "STACK_OF" { - continue - } - currentFunction = f - for len(currentFunction) > 0 && currentFunction[0] == '*' { - currentFunction = currentFunction[1:] - } - break - } - } - } - - // 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 - } - } - handleDeclareMacro(line, "_R_", "OPENSSL_DECLARE_ERROR_REASON(", reasons) - 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 } @@ -413,25 +361,17 @@ func addFunctionsAndReasons(functions, reasons map[string]int, filename, prefix return scanner.Err() } -func parseHeader(lib string, file io.Reader) (functions, reasons map[string]int, err error) { - functions = make(map[string]int) +func parseHeader(lib string, file io.Reader) (reasons map[string]int, err error) { reasons = make(map[string]int) scanner := bufio.NewScanner(file) for scanner.Scan() { - typ, key, value, ok := parseDefineLine(scanner.Text(), lib) + key, value, ok := parseDefineLine(scanner.Text(), lib) if !ok { continue } - switch typ { - case typeFunctions: - functions[key] = value - case typeReasons: - reasons[key] = value - default: - panic("internal error") - } + reasons[key] = value } err = scanner.Err() |