Skip to content

Commit 4b16f7c

Browse files
authored
feat: update protocol_tests when generate-clients is run (#1141)
1 parent fee3b6f commit 4b16f7c

File tree

7 files changed

+100
-51
lines changed

7 files changed

+100
-51
lines changed

codegen/protocol-test-codegen/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ plugins {
2020
}
2121

2222
dependencies {
23-
implementation("software.amazon.smithy:smithy-aws-protocol-tests:0.9.8")
23+
implementation("software.amazon.smithy:smithy-aws-protocol-tests:0.9.9")
2424
compile(project(":smithy-aws-typescript-codegen"))
2525
}
2626

codegen/protocol-test-codegen/smithy-build.json

+25-10
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
"projections": {
44
"aws-ec2": {
55
"transforms": [
6-
{"name": "includeServices", "args": ["aws.protocols.tests.ec2#AwsEc2"]}
6+
{
7+
"name": "includeServices",
8+
"args": ["aws.protocols.tests.ec2#AwsEc2"]
9+
}
710
],
811
"plugins": {
912
"typescript-codegen": {
10-
"package": "@aws-sdk/protocol-tests-aws-ec2",
13+
"package": "@aws-sdk/aws-ec2",
1114
"packageVersion": "1.0.0-alpha.1",
1215
"packageJson": {
1316
"author": {
@@ -23,11 +26,14 @@
2326
},
2427
"aws-json": {
2528
"transforms": [
26-
{"name": "includeServices", "args": ["aws.protocols.tests.json#JsonProtocol"]}
29+
{
30+
"name": "includeServices",
31+
"args": ["aws.protocols.tests.json#JsonProtocol"]
32+
}
2733
],
2834
"plugins": {
2935
"typescript-codegen": {
30-
"package": "@aws-sdk/protocol-tests-aws-json",
36+
"package": "@aws-sdk/aws-json",
3137
"packageVersion": "1.0.0-alpha.1",
3238
"packageJson": {
3339
"author": {
@@ -43,11 +49,14 @@
4349
},
4450
"aws-query": {
4551
"transforms": [
46-
{"name": "includeServices", "args": ["aws.protocols.tests.query#AwsQuery"]}
52+
{
53+
"name": "includeServices",
54+
"args": ["aws.protocols.tests.query#AwsQuery"]
55+
}
4756
],
4857
"plugins": {
4958
"typescript-codegen": {
50-
"package": "@aws-sdk/protocol-tests-aws-query",
59+
"package": "@aws-sdk/aws-query",
5160
"packageVersion": "1.0.0-alpha.1",
5261
"packageJson": {
5362
"author": {
@@ -63,11 +72,14 @@
6372
},
6473
"aws-restjson": {
6574
"transforms": [
66-
{"name": "includeServices", "args": ["aws.protocols.tests.restjson#RestJson"]}
75+
{
76+
"name": "includeServices",
77+
"args": ["aws.protocols.tests.restjson#RestJson"]
78+
}
6779
],
6880
"plugins": {
6981
"typescript-codegen": {
70-
"package": "@aws-sdk/protocol-tests-aws-restjson",
82+
"package": "@aws-sdk/aws-restjson",
7183
"packageVersion": "1.0.0-alpha.1",
7284
"packageJson": {
7385
"author": {
@@ -83,11 +95,14 @@
8395
},
8496
"aws-restxml": {
8597
"transforms": [
86-
{"name": "includeServices", "args": ["aws.protocols.tests.restxml#RestXml"]}
98+
{
99+
"name": "includeServices",
100+
"args": ["aws.protocols.tests.restxml#RestXml"]
101+
}
87102
],
88103
"plugins": {
89104
"typescript-codegen": {
90-
"package": "@aws-sdk/protocol-tests-aws-restxml",
105+
"package": "@aws-sdk/aws-restxml",
91106
"packageVersion": "1.0.0-alpha.1",
92107
"packageJson": {
93108
"author": {

scripts/generate-clients/code-gen-dir.js

+23-14
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,35 @@ const { join, normalize } = require("path");
22

33
const CODE_GEN_ROOT = normalize(join(__dirname, "..", "..", "codegen"));
44

5-
const CODE_GEN_TASK_ROOT = join(CODE_GEN_ROOT, "sdk-codegen");
5+
const getCodeGenDirRoot = dir => join(CODE_GEN_ROOT, dir);
6+
const CODE_GEN_SDK_ROOT = getCodeGenDirRoot("sdk-codegen");
7+
const CODE_GEN_PROTOCOL_TESTS_ROOT = getCodeGenDirRoot("protocol-test-codegen");
68

79
const TEMP_CODE_GEN_INPUT_DIR = normalize(join(__dirname, ".aws-models"));
810

9-
const CODE_GEN_OUTPUT_DIR = normalize(
10-
join(
11-
__dirname,
12-
"..",
13-
"..",
14-
"codegen",
15-
"sdk-codegen",
16-
"build",
17-
"smithyprojections",
18-
"sdk-codegen"
19-
)
11+
const getCodeGenOutputDir = dir =>
12+
normalize(
13+
join(
14+
__dirname,
15+
"..",
16+
"..",
17+
"codegen",
18+
dir,
19+
"build",
20+
"smithyprojections",
21+
dir
22+
)
23+
);
24+
const CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR = getCodeGenOutputDir(
25+
"protocol-test-codegen"
2026
);
27+
const CODE_GEN_SDK_OUTPUT_DIR = getCodeGenOutputDir("sdk-codegen");
2128

2229
module.exports = {
2330
CODE_GEN_ROOT,
24-
CODE_GEN_TASK_ROOT,
25-
CODE_GEN_OUTPUT_DIR,
31+
CODE_GEN_SDK_ROOT,
32+
CODE_GEN_PROTOCOL_TESTS_ROOT,
33+
CODE_GEN_SDK_OUTPUT_DIR,
34+
CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR,
2635
TEMP_CODE_GEN_INPUT_DIR
2736
};

scripts/generate-clients/code-gen.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ const { readdirSync, lstatSync } = require("fs");
44
const { spawnProcess } = require("./spawn-process");
55
const {
66
CODE_GEN_ROOT,
7-
CODE_GEN_TASK_ROOT,
7+
CODE_GEN_SDK_ROOT,
88
TEMP_CODE_GEN_INPUT_DIR
99
} = require("./code-gen-dir");
1010
const Glob = require("glob");
1111

12-
async function generateClients(models) {
12+
const generateClients = async models => {
1313
let designatedModels = false;
1414
if (typeof models === "string") {
1515
//`models` is a folder path
@@ -53,16 +53,28 @@ async function generateClients(models) {
5353
if (designatedModels) {
5454
options.push(
5555
`-PmodelsDirProp=${path.relative(
56-
CODE_GEN_TASK_ROOT,
56+
CODE_GEN_SDK_ROOT,
5757
TEMP_CODE_GEN_INPUT_DIR
5858
)}`
5959
);
6060
}
61+
6162
await spawnProcess("./gradlew", options, {
6263
cwd: CODE_GEN_ROOT
6364
});
64-
}
65+
};
66+
67+
const generateProtocolTests = async () => {
68+
await spawnProcess(
69+
"./gradlew",
70+
[":protocol-test-codegen:clean", ":protocol-test-codegen:build"],
71+
{
72+
cwd: CODE_GEN_ROOT
73+
}
74+
);
75+
};
6576

6677
module.exports = {
67-
generateClients
78+
generateClients,
79+
generateProtocolTests
6880
};

scripts/generate-clients/code-prettify.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
const { spawnProcess } = require("./spawn-process");
2-
const { CODE_GEN_OUTPUT_DIR } = require("./code-gen-dir");
32

4-
const prettifyCode = async () => {
3+
const prettifyCode = async dir => {
54
await spawnProcess("./node_modules/.bin/prettier", [
65
"--write",
7-
`${CODE_GEN_OUTPUT_DIR}/**/*.{ts,js,md,json}`
6+
`${dir}/**/*.{ts,js,md,json}`
87
]);
98
};
109

scripts/generate-clients/copy-to-clients.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const {
77
existsSync,
88
writeFileSync
99
} = require("fs");
10-
const { CODE_GEN_OUTPUT_DIR } = require("./code-gen-dir");
1110

1211
const getOverwritablePredicate = packageName => pathName => {
1312
const overwritablePathnames = [
@@ -63,14 +62,10 @@ const mergeManifest = (fromContent, toContent) => {
6362
return merged;
6463
};
6564

66-
async function copyToClients(clientsDir) {
67-
for (const modelName of readdirSync(CODE_GEN_OUTPUT_DIR)) {
65+
const copyToClients = async (sourceDir, destinationDir) => {
66+
for (const modelName of readdirSync(sourceDir)) {
6867
if (modelName === "source") continue;
69-
const artifactPath = join(
70-
CODE_GEN_OUTPUT_DIR,
71-
modelName,
72-
"typescript-codegen"
73-
);
68+
const artifactPath = join(sourceDir, modelName, "typescript-codegen");
7469
const packageManifestPath = join(artifactPath, "package.json");
7570
if (!existsSync(packageManifestPath)) {
7671
console.error(`${modelName} generates empty client, skip.`);
@@ -81,8 +76,10 @@ async function copyToClients(clientsDir) {
8176
readFileSync(packageManifestPath).toString()
8277
);
8378
const packageName = packageManifest.name;
84-
console.log(`copying ${packageName} from ${artifactPath} to ${clientsDir}`);
85-
const destPath = join(clientsDir, packageName.replace("@aws-sdk/", ""));
79+
console.log(
80+
`copying ${packageName} from ${artifactPath} to ${destinationDir}`
81+
);
82+
const destPath = join(destinationDir, packageName.replace("@aws-sdk/", ""));
8683
const overwritablePredicate = getOverwritablePredicate(packageName);
8784
for (const packageSub of readdirSync(artifactPath)) {
8885
const packageSubPath = join(artifactPath, packageSub);
@@ -109,7 +106,7 @@ async function copyToClients(clientsDir) {
109106
}
110107
}
111108
}
112-
}
109+
};
113110

114111
module.exports = {
115112
copyToClients

scripts/generate-clients/index.js

+24-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
const yargs = require("yargs");
22
const path = require("path");
33
const { emptyDirSync, rmdirSync } = require("fs-extra");
4-
const { generateClients } = require("./code-gen");
4+
const { generateClients, generateProtocolTests } = require("./code-gen");
55
const { copyToClients } = require("./copy-to-clients");
66
const {
7-
CODE_GEN_OUTPUT_DIR,
7+
CODE_GEN_SDK_OUTPUT_DIR,
8+
CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR,
89
TEMP_CODE_GEN_INPUT_DIR
910
} = require("./code-gen-dir");
1011
const { prettifyCode } = require("./code-prettify");
1112

12-
const CLIENTS_DIR = path.normalize(path.join(__dirname, "..", "..", "clients"));
13+
const SDK_CLIENTS_DIR = path.normalize(
14+
path.join(__dirname, "..", "..", "clients")
15+
);
16+
const PROTOCOL_TESTS_CLIENTS_DIR = path.normalize(
17+
path.join(__dirname, "..", "..", "protocol_tests")
18+
);
1319

1420
const { models, globs, output: clientsDir } = yargs
1521
.alias("m", "models")
@@ -22,16 +28,27 @@ const { models, globs, output: clientsDir } = yargs
2228
.alias("o", "output")
2329
.string("o")
2430
.describe("o", "The output directory for built clients")
25-
.default("o", CLIENTS_DIR)
31+
.default("o", SDK_CLIENTS_DIR)
2632
.help().argv;
2733

2834
(async () => {
2935
try {
3036
await generateClients(models || globs);
31-
await prettifyCode();
32-
await copyToClients(clientsDir);
33-
emptyDirSync(CODE_GEN_OUTPUT_DIR);
37+
await generateProtocolTests();
38+
39+
await prettifyCode(CODE_GEN_SDK_OUTPUT_DIR);
40+
await prettifyCode(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR);
41+
42+
await copyToClients(CODE_GEN_SDK_OUTPUT_DIR, clientsDir);
43+
await copyToClients(
44+
CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR,
45+
PROTOCOL_TESTS_CLIENTS_DIR
46+
);
47+
48+
emptyDirSync(CODE_GEN_SDK_OUTPUT_DIR);
49+
emptyDirSync(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR);
3450
emptyDirSync(TEMP_CODE_GEN_INPUT_DIR);
51+
3552
rmdirSync(TEMP_CODE_GEN_INPUT_DIR);
3653
} catch (e) {
3754
console.log(e);

0 commit comments

Comments
 (0)