Skip to content

fix(scripts): store clients generated in a batch in temp directory #3323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scripts/generate-clients/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.aws-models/
.aws-models/
.sdk-codegen/
2 changes: 2 additions & 0 deletions scripts/generate-clients/code-gen-dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const getCodeGenOutputDir = (dir) =>
const CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR = getCodeGenOutputDir("protocol-test-codegen");
const CODE_GEN_GENERIC_CLIENT_OUTPUT_DIR = getCodeGenOutputDir("generic-client-test-codegen");
const CODE_GEN_SDK_OUTPUT_DIR = getCodeGenOutputDir("sdk-codegen");
const TEMP_CODE_GEN_SDK_OUTPUT_DIR = normalize(join(__dirname, ".sdk-codegen"));

module.exports = {
CODE_GEN_ROOT,
Expand All @@ -25,4 +26,5 @@ module.exports = {
CODE_GEN_GENERIC_CLIENT_OUTPUT_DIR,
DEFAULT_CODE_GEN_INPUT_DIR,
TEMP_CODE_GEN_INPUT_DIR,
TEMP_CODE_GEN_SDK_OUTPUT_DIR,
};
16 changes: 14 additions & 2 deletions scripts/generate-clients/code-gen.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// @ts-check
const { basename, join, relative } = require("path");
const { emptyDirSync } = require("fs-extra");
const { copySync, emptyDirSync } = require("fs-extra");
const { copyFileSync } = require("fs");
const { spawnProcess } = require("../utils/spawn-process");
const { CODE_GEN_ROOT, CODE_GEN_SDK_ROOT, TEMP_CODE_GEN_INPUT_DIR } = require("./code-gen-dir");
const {
CODE_GEN_ROOT,
CODE_GEN_SDK_ROOT,
CODE_GEN_SDK_OUTPUT_DIR,
TEMP_CODE_GEN_INPUT_DIR,
TEMP_CODE_GEN_SDK_OUTPUT_DIR,
} = require("./code-gen-dir");
const { getModelFilepaths } = require("./get-model-filepaths");

const generateClients = async (models, batchSize) => {
Expand All @@ -22,7 +28,13 @@ const generateClients = async (models, batchSize) => {
copyFileSync(filepath, join(TEMP_CODE_GEN_INPUT_DIR, filename));
}
await spawnProcess("./gradlew", options, { cwd: CODE_GEN_ROOT });
// We're copying generated code to temporary directory as it's cleans
// codegen directory in every run.
// Refs: https://github.com/aws/aws-sdk-js-v3/issues/3321
copySync(CODE_GEN_SDK_OUTPUT_DIR, TEMP_CODE_GEN_SDK_OUTPUT_DIR);
}
copySync(TEMP_CODE_GEN_SDK_OUTPUT_DIR, CODE_GEN_SDK_OUTPUT_DIR);
emptyDirSync(TEMP_CODE_GEN_SDK_OUTPUT_DIR);
};

const generateProtocolTests = async () => {
Expand Down