diff --git a/integration/codegen.sh b/integration/codegen.sh deleted file mode 100755 index d2ad44d3f..000000000 --- a/integration/codegen.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env bash - -# Runs the local code generator for the .bin test files (as created/kept -# up-to-date by ./update-bins.sh). Good for local iteration of WIP changes. -# -# Usage: -# -# ./codegen.sh -# -# Updates generated output for all integration tests. -# -# ./codegen.sh simple value -# -# Updates generated output only for the 'simple' and 'value' integration test. -# -# ./codegen.sh simple/simple.bin -# -# Updates generated output for the 'simple' integration test. Used by file watcher. -# -# Each integration test can optionally have a `parameters.txt` file that will -# be used as the ts-proto_opt... args for generating that test's code. - -INTEGRATION_DIR=$(realpath $(dirname "$BASH_SOURCE")) - -# Run the code generator in parallel. Note this is purposefully pinned to 5 because -# CI only has 2 cores, but we can go faster than that, and for me locally using all -# 16 cores is overly taxes the machine/kicks on fans/etc. 5 is a good balance. -N=5 - -echo "Generating typescript code for integration tests using ${N} cores..." - -cd $INTEGRATION_DIR - -if [[ $# -eq 0 ]]; then - FILTER_PATHS=. -else - FILTER_PATHS="${@}" -fi - -# Finds .bin files that match the given filter paths, which can be directories or paths to the .bin files themselves. -BIN_FILES=$(find $FILTER_PATHS -name "*.bin" -type f | grep -v dump-response.bin) - -for BIN_FILE in $BIN_FILES; do - echo "${BIN_FILE}" - # Strip the longest suffix starting at the 1st slash - TEST_DIR="${BIN_FILE##./}" - TEST_DIR="${TEST_DIR%%/*}" - PARAMS="" - - if [ -f "${TEST_DIR}/parameters.txt" ]; then - PARAMS=$(cat "${TEST_DIR}/parameters.txt") - fi - - ((i=i%N)); ((i++==0)) && wait - "../node_modules/.bin/tsx" "./codegen.ts" "${TEST_DIR}" "${BIN_FILE}" "${PARAMS}" & -done - -wait diff --git a/integration/codegen.ts b/integration/codegen.ts deleted file mode 100644 index 71312b593..000000000 --- a/integration/codegen.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { CodeGeneratorRequest } from "ts-proto-descriptors"; -import { mkdir, readFile, writeFile } from "fs"; -import { parse } from "path"; -import { promisify } from "util"; -import { generateFile, makeUtils } from "../src/main"; -import { createTypeMap } from "../src/types"; -import { generateIndexFiles, getVersions } from "../src/utils"; -import { getTsPoetOpts, optionsFromParameter } from "../src/options"; -import { BaseContext, createFileContext } from "../src/context"; -import { generateTypeRegistry } from "../src/generate-type-registry"; - -/** - * Generates output for our integration tests from their example proto files. - * - * We use snapshots of the protoc CodeGeneratorRequest's that are captured - * by running ./update_proto_bins.sh, just because various machines/CI/etc - * may not have the `protoc` compiler on their path. - */ -async function main() { - const dir = process.argv[2]; - const file = process.argv[3]; - const param = process.argv[4]; - await generate(file, dir, param); -} - -async function generate(binFile: string, baseDir: string, parameter: string) { - const stdin = await promisify(readFile)(binFile); - const request = CodeGeneratorRequest.decode(stdin); - request.parameter = parameter; - - const { protocVersion, tsProtoVersion } = await getVersions(request); - - const options = optionsFromParameter(parameter || ""); - - // we have to check for the parameter as a string here because the - // default value of the parameter is true. - if (parameter.includes("annotateFilesWithVersion=true")) { - options.annotateFilesWithVersion = true; - } else { - // we practically always want to not annotate files with version in tests - // as this will make snapshots fail on every version bump - options.annotateFilesWithVersion = false; - } - const typeMap = createTypeMap(request, options); - - for (let file of request.protoFile) { - // Make a different utils per file to track per-file usage - if (options.M[file.name]) { - continue; - } - const utils = makeUtils(options); - const ctx: BaseContext = { options, typeMap, utils }; - const [path, code] = generateFile({ ...ctx, currentFile: createFileContext(file) }, file); - const filePath = `${baseDir}/${path}`; - const dirPath = parse(filePath).dir; - await promisify(mkdir)(dirPath, { recursive: true }).catch(() => {}); - await promisify(writeFile)( - filePath, - code.toString({ ...getTsPoetOpts(options, tsProtoVersion, protocVersion, file.name), path }), - ); - } - - if (options.outputTypeRegistry) { - const utils = makeUtils(options); - const ctx: BaseContext = { options, typeMap, utils }; - - const path = "typeRegistry.ts"; - const code = generateTypeRegistry(ctx); - - const filePath = `${baseDir}/${path}`; - - await promisify(writeFile)( - filePath, - code.toString({ ...getTsPoetOpts(options, tsProtoVersion, protocVersion), path }), - ); - } - - if (options.outputIndex) { - for (const [path, code] of generateIndexFiles(request.protoFile, options)) { - const filePath = `${baseDir}/${path}`; - const dirPath = parse(filePath).dir; - await promisify(mkdir)(dirPath, { recursive: true }).catch(() => {}); - await promisify(writeFile)( - filePath, - code.toString({ ...getTsPoetOpts(options, tsProtoVersion, protocVersion), path }), - ); - } - } -} - -main().then(() => { - console.log(`${process.argv[3]}: Done`); -}); diff --git a/integration/protoc-gen-dump b/integration/protoc-gen-dump deleted file mode 100755 index b3e622d34..000000000 --- a/integration/protoc-gen-dump +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -# ---------------------------------------------------------------------------------------------------------------------- -# Testing utility to dump a serialised CodeGeneratorRequest object which can then be fed into plugin tests to drive -# generation. -# -# Example Usage: -# protoc \ -# --plugin=${PWD}/protoc-gen-dump \ -# --dump_out=target=server,type=undertow:../java \ -# ./helloworld.proto -# -# In the above example, we need to pass in arguments to the dump plugin - different types can be used to test different -# flows in the plugin generator resolution as well as asserting errors for incorrect/missing params. -# -# After generation, rename the file to something useful and then import in tests. -# ---------------------------------------------------------------------------------------------------------------------- -cat >| file.bin -# This echos back to protoc that we're a proto3 plugin -cat ./dump-response.bin diff --git a/integration/protoc-gen-dump.bat b/integration/protoc-gen-dump.bat deleted file mode 100644 index 272f9e037..000000000 --- a/integration/protoc-gen-dump.bat +++ /dev/null @@ -1 +0,0 @@ -@bash protoc-gen-dump diff --git a/integration/update-bins.sh b/integration/update-bins.sh deleted file mode 100755 index a5e3a0cee..000000000 --- a/integration/update-bins.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash - -# To avoid running the protoc pipeline all the time, we capture the incoming Plugin -# proto requests into .bin PROTO_FILES that then unit tests can pull in directly as needed. - -INTEGRATION_DIR=$(realpath $(dirname "$BASH_SOURCE")) -cd $INTEGRATION_DIR; - -if [[ "$OSTYPE" == "msys" ]]; then - PLUGIN_PATH="protoc-gen-dump.bat" -else - PLUGIN_PATH="protoc-gen-dump" -fi - -if [[ $# -eq 0 ]]; then - PROTO_FILES=$(find . -name "*.proto" -type f) -else - PROTO_FILES=$@ -fi - -for FILE in $PROTO_FILES; do - echo "${FILE}" - # Strip the longest suffix starting at the 1st slash - INPUT_DIR="${FILE##./}" - INPUT_DIR="${INPUT_DIR%%/*}" - OUTPUT_FILE="${FILE%proto}bin" - protoc --experimental_allow_proto3_optional "--plugin=$PLUGIN_PATH" --dump_out=. "${FILE}" "-I${INPUT_DIR}" - mv file.bin "${OUTPUT_FILE}" -done