-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(go): run "go build" on generated code (#2485)
To ensure the generated go code is formatted and compiles by executing `go fmt` and `go build` on the output directory. Similar to other languages, in order to be able to build the go module within mono-repos (and in the jsii repo itself), we need to be able to resolve local dependencies. This is done in the following way: 1. Create a list of `dist/go` candidates (based on the `jsii.outdir` relative to dependency package dirs) 2. Add to this list the current `outDir`, in case `--outdir` is used 3. Iterate over the module's dependencies (_recursively_) and for each candidate `dist` directory, check if we can find a `<goModule>/go.mod` file that contains a `module <moduleName>` directive. 4. If we find one, we append a `replace` directive with a relative path to our own `go.mod` which tells `go fmt` and `go build` to find the dependency locally. 5. At the end, we restore the original `go.mod` file so that the published one will not include the `replace` directives. TESTING: this is primarily tested using the `test:build` target of `jsii-pacmak` which generates & builds the go code for the "calc" fixture (in all pacmak execution variants). NOTE: running `go fmt` on the generated sources turned out to be problematic because sources are generated in parallel by default, and therefore it was not possible to resolve local dependencies at that time (which is required since `go fmt` processes `go.mod`). Resolves #2463
- Loading branch information
Elad Ben-Israel
authored
Jan 28, 2021
1 parent
4b03834
commit d3602ec
Showing
22 changed files
with
1,049 additions
and
690 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...sii/go-runtime/build-tools/.eslintrc.yaml → packages/@jsii/go-runtime/.eslintrc.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
/jsii-calc/ | ||
*.generated.go | ||
|
||
*.js | ||
*.d.ts |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import * as path from 'path'; | ||
|
||
export const runtimePath = path.resolve(__dirname, '..', 'jsii-runtime-go'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../../../tsconfig-base", | ||
"include": ["**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,34 @@ | ||
import { IVeryBaseInterface, VeryBaseProps } from '@scope/jsii-calc-base-of-base'; | ||
import { | ||
IVeryBaseInterface, | ||
VeryBaseProps, | ||
StaticConsumer as StaticConsumerBase, | ||
} from '@scope/jsii-calc-base-of-base'; | ||
|
||
/** | ||
* A base class. | ||
*/ | ||
export abstract class Base { | ||
/** | ||
* @returns the name of the class (to verify native type names are created for derived classes). | ||
*/ | ||
public typeName() { | ||
return (this.constructor as any).name; | ||
} | ||
/** | ||
* @returns the name of the class (to verify native type names are created for derived classes). | ||
*/ | ||
public typeName() { | ||
return (this.constructor as any).name; | ||
} | ||
} | ||
|
||
export interface BaseProps extends VeryBaseProps { | ||
readonly bar: string; | ||
readonly bar: string; | ||
} | ||
|
||
export interface IBaseInterface extends IVeryBaseInterface { | ||
bar(): void; | ||
} | ||
bar(): void; | ||
} | ||
|
||
/** | ||
* Hides the transitive dependency of base-of-base | ||
*/ | ||
export class StaticConsumer { | ||
public static consume(...args: any[]) { | ||
return StaticConsumerBase.consume(...args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.