Skip to content

Commit 96d4e81

Browse files
authored
chore(interfaces): submodule names for interface submodules are incorrect (#36036)
### Reason for this change Go packaging was failing with ``` #STDERR> awsimagebuilder/internal/types.go:4:2: "github.com/aws/aws-cdk-go/awscdk/interfaces/awsimagebuilder" imported and not used #STDERR> awsimagebuilder/internal/types.go:8:28: undefined: IComponentRef ``` However as it turns out the generated `jsiirc` were using the wrong path. They were missing the required `.` (fullstop) prefix, thus the written package names were not being considered by jsii at all. For go, we also need to update the interfaces package name to a unique name: Before: ``` package awsimagebuilder ``` After: ``` package interfacesawsimagebuilder ``` ### Description of changes Use the correct `jsiirc` filename. Ensure a unique package name for go is used. ### Describe any new or updated permissions being added n/a ### Description of how you validated changes Test pipeline is passing. Manually tested go packaging. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 773b5c4 commit 96d4e81

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

packages/aws-cdk-lib/interfaces/.jsiirc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
},
99
"python": {
1010
"module": "aws_cdk.interfaces"
11+
},
12+
"go": {
13+
"packageName": "interfaces"
1114
}
1215
}
1316
}

packages/aws-cdk-lib/scripts/submodules/index.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as path from 'node:path';
2-
import { createLibraryReadme, ModuleDefinition } from '@aws-cdk/pkglint';
2+
import { createLibraryReadme } from '@aws-cdk/pkglint';
33
import { topo } from '@aws-cdk/spec2cdk';
44
import * as fs from 'fs-extra';
55

@@ -84,25 +84,27 @@ async function ensureInterfaceSubmoduleJsiiJsonRc(submodule: topo.ModuleMapEntry
8484
const interfacesModuleJsiiRcPath = path.join(interfacesModulePath, '.jsiirc.json');
8585
const interfacesModuleJsiiRc = JSON.parse(await fs.readFile(interfacesModuleJsiiRcPath, 'utf-8'));
8686

87-
const jsiiRcPath = path.join(interfacesModulePath, 'generated', `${submodule.name}-interfaces.generated.jsiirc.json`);
87+
const jsiiRcPath = path.join(interfacesModulePath, 'generated', `.${submodule.name}-interfaces.generated.jsiirc.json`);
8888

8989
const jsiirc = {
9090
targets: {
91-
...combineLanguageNamespace('java', 'package', 'javaPackage'),
92-
...combineLanguageNamespace('dotnet', 'namespace', 'dotnetPackage'),
93-
...combineLanguageNamespace('python', 'module', 'pythonModuleName'),
94-
// No Go...
91+
...combineLanguageNamespace('java', 'package', submodule.definition?.javaPackage),
92+
...combineLanguageNamespace('dotnet', 'namespace', submodule.definition?.dotnetPackage),
93+
...combineLanguageNamespace('python', 'module', submodule.definition?.pythonModuleName),
94+
...combineLanguageNamespace('go', 'packageName', submodule.definition?.moduleName.replace(/[^a-z0-9.]/gi, '')),
9595
},
9696
};
9797
await fs.writeJson(jsiiRcPath, jsiirc, { spaces: 2 });
9898

99-
function combineLanguageNamespace(language: string, whatName: string, k: keyof ModuleDefinition) {
100-
const ns = `${interfacesModuleJsiiRc.targets[language][whatName]}.${lastPart(submodule.definition?.[k] ?? 'undefined')}`;
101-
if (ns.includes('undefined')) {
102-
throw new Error(`Could not build child namespace for language ${language} from ${JSON.stringify(interfacesModuleJsiiRc.targets[language])} and ${k} from ${JSON.stringify(submodule.definition)}`);
99+
function combineLanguageNamespace(language: string, whatName: string, fromDef?: string) {
100+
if (fromDef == null) {
101+
throw new Error(`Could not build child namespace for language ${language} from ${JSON.stringify(interfacesModuleJsiiRc.targets[language])} and definition ${JSON.stringify(submodule.definition)}`);
103102
}
104103

105-
return { [language]: { [whatName]: ns } };
104+
const nsParts = [interfacesModuleJsiiRc.targets[language][whatName], lastPart(fromDef)];
105+
const nsSep = language === 'go' ? '' : '.';
106+
107+
return { [language]: { [whatName]: nsParts.join(nsSep) } };
106108
}
107109
}
108110

tools/@aws-cdk/spec2cdk/lib/util/jsii.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ModuleDefinition } from '@aws-cdk/pkglint';
12
import * as naming from '../naming';
23

34
export interface PackageBaseNames {
@@ -21,15 +22,16 @@ export const AWS_CDK_LIB_BASE_NAMES: PackageBaseNames = {
2122
* @param bases - provide different package base names and overwrite jsii targets
2223
* @returns the module definition
2324
*/
24-
export function namespaceToModuleDefinition(namespace: string, bases: PackageBaseNames = AWS_CDK_LIB_BASE_NAMES) {
25+
export function namespaceToModuleDefinition(namespace: string, bases: PackageBaseNames = AWS_CDK_LIB_BASE_NAMES): ModuleDefinition {
26+
// [aws-s3, AWS, S3]
2527
const { moduleName, moduleFamily, moduleBaseName } = naming.modulePartsFromNamespace(namespace);
26-
const submoduleName = moduleName.replace('-', '_');
28+
const submoduleName = moduleName.replace('-', '_'); // aws_s3
2729

28-
const lowcaseModuleName = moduleBaseName.toLocaleLowerCase();
29-
const packageName = `${bases.javascript}/${moduleName}`;
30+
const lowcaseModuleName = moduleBaseName.toLocaleLowerCase(); // s3
31+
const packageName = `${bases.javascript}/${moduleName}`; // aws-cdk-lib/aws-s3
3032

3133
// dotnet names
32-
const dotnetPackage = `${bases.dotnet}.${moduleFamily}.${moduleBaseName}`;
34+
const dotnetPackage = `${bases.dotnet}.${moduleFamily}.${moduleBaseName}`; // Amazon.CDK.AWS.S3
3335

3436
// java names
3537
const javaGroupId = bases.java;
@@ -41,8 +43,8 @@ export function namespaceToModuleDefinition(namespace: string, bases: PackageBas
4143
moduleFamily === 'AWS' ? lowcaseModuleName : `${moduleFamily.toLocaleLowerCase()}-${lowcaseModuleName}`;
4244

4345
// python names
44-
const pythonDistName = `${bases.python}.${moduleName}`;
45-
const pythonModuleName = pythonDistName.replace(/-/g, '_');
46+
const pythonDistName = `${bases.python}.${moduleName}`; // aws-cdk.aws-s3
47+
const pythonModuleName = pythonDistName.replace(/-/g, '_'); // aws_cdk.aws_s3
4648

4749
return {
4850
namespace,

0 commit comments

Comments
 (0)