Skip to content

Commit

Permalink
Embed dotnet-generator into pacmak (#157)
Browse files Browse the repository at this point in the history
Since dotnet uses an external program to generate .NET, we need this
tool to be available when running pacmak.

This change embeds the .NET code generator (and all needed deps) into
jsii-pacmak. Size of pacmak tarball is not 4MiB (not so bad).

Also: change all modules that are not published to npm to "private: true"

Update tgz with placeholders.
  • Loading branch information
Elad Ben-Israel authored Aug 7, 2018
1 parent 3e681d1 commit 64ced3f
Show file tree
Hide file tree
Showing 16 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/jsii-dotnet-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.6.2",
"description": ".NET code generator for jsii assemblies",
"main": "index.js",
"private": true,
"scripts": {
"gen": "/bin/bash ./generate.sh",
"build": "/bin/bash ./build.sh",
Expand Down
1 change: 1 addition & 0 deletions packages/jsii-dotnet-jsonmodel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.6.2",
"description": ".NET json model for jsii spec and api.",
"main": "index.js",
"private": true,
"scripts": {
"gen": "/bin/bash ./generate.sh",
"build": "/bin/bash ./build.sh",
Expand Down
1 change: 1 addition & 0 deletions packages/jsii-dotnet-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.6.2",
"description": ".NET client for jsii runtime",
"main": "index.js",
"private": true,
"scripts": {
"gen": "/bin/bash ./generate.sh",
"build": "/bin/bash ./build.sh",
Expand Down
1 change: 1 addition & 0 deletions packages/jsii-java-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Java client for jsii runtime",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"private": true,
"scripts": {
"gen": "/bin/bash ./generate.sh",
"build": "tsc && npm run gen && cd project && mvn deploy -D altDeploymentRepository=local::default::file://${PWD}/../maven-repo",
Expand Down
1 change: 1 addition & 0 deletions packages/jsii-pacmak/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
lib/version.ts
lib/targets/dotnet-generator/
5 changes: 5 additions & 0 deletions packages/jsii-pacmak/generate.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/bin/bash
set -euo pipefail

# embed the dotnet code generator program as a resource
dng="lib/targets/dotnet-generator"
mkdir -p ${dng}
rsync -av node_modules/jsii-dotnet-generator/cli/publish/ ${dng}/

commit=${CODEBUILD_RESOLVED_SOURCE_VERSION:-}
# CODEBUILD_RESOLVED_SOURCE_VERSION is not defined (i.e. local build or CodePipeline build),
# use the HEAD commit hash
Expand Down
3 changes: 1 addition & 2 deletions packages/jsii-pacmak/lib/targets/dotnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ class DotNetGenerator implements IGenerator {

public save(outdir: string, tarball: string): Promise<any> {
return new Promise<number>((resolve, reject) => {
const runtimeRoot = path.dirname(require.resolve('jsii-dotnet-generator/package.json'));
const cliPath = path.join(runtimeRoot, 'cli', 'publish', 'Amazon.JSII.Generator.CLI.dll');
const cliPath = path.join(__dirname, 'dotnet-generator', 'Amazon.JSII.Generator.CLI.dll');
const cli = childProcess.spawn(
'dotnet',
[cliPath, '--jsii', this.jsiiFile, '--tarball', tarball, '--output', outdir],
Expand Down
5 changes: 3 additions & 2 deletions packages/jsii-pacmak/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "bash generate.sh && tsc && chmod +x bin/jsii-pacmak && tslint -p .",
"gen": "/bin/bash generate.sh",
"build": "npm run gen && tsc && chmod +x bin/jsii-pacmak && tslint -p .",
"watch": "tsc -w",
"lint": "tslint -p . --force",
"test": "/bin/bash test/diff-test.sh",
Expand All @@ -22,13 +23,13 @@
"clone": "^2.1.1",
"codemaker": "^0.6.2",
"fs-extra": "^4.0.3",
"jsii-dotnet-generator": "^0.6.2",
"jsii-spec": "^0.6.2",
"spdx-license-list": "^4.1.0",
"xmlbuilder": "^10.0.0",
"yargs": "^12.0.0"
},
"devDependencies": {
"jsii-dotnet-generator": "^0.6.2",
"@scope/jsii-calc-lib": "^0.6.2",
"@types/clone": "^0.1.30",
"@types/fs-extra": "^4.0.8",
Expand Down
15 changes: 8 additions & 7 deletions packages/jsii-pacmak/test/diff-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,13 @@ function assert-generator() {

# put the real expected tarball instead of the placeholder
for expected_tarball_placeholder in $(find ${expected} -name "*.tgz" || true); do
rm -f ${expected_tarball_placeholder} && cp ${expected_tarball} ${expected_tarball_placeholder}
rm -f ${expected_tarball_placeholder}
cp ${expected_tarball} ${expected_tarball_placeholder}
done

echo "Running jsii-pacmak test for ${module}"
../bin/jsii-pacmak --outdir ${outdir} ${module_root} --code-only --no-fingerprint

# change the placeholder back
for tarball_placeholder in $(find ${original_expected} -name "*.tgz" || true); do
echo "Placeholder for the expected module tarball" > ${tarball_placeholder}
echo "The diff-test.sh harness will replace it with the real expected tarball" >> ${tarball_placeholder}
done

if ! diff --strip-trailing-cr -arq ${outdir} ${expected}; then
if [ -n "${UPDATE_DIFF:-}" ]; then
echo "⚡️ UPDATE_DIFF is set, overwriting ${original_expected}"
Expand All @@ -60,6 +55,12 @@ function assert-generator() {
success=false
fi
fi

# change the placeholder back (we do this after UPDATE_DIFF)
for tarball_placeholder in $(find ${original_expected} -name "*.tgz" || true); do
echo "Placeholder for the expected module tarball" > ${tarball_placeholder}
echo "The diff-test.sh harness will replace it with the real expected tarball" >> ${tarball_placeholder}
done
}

assert-generator jsii-calc-base
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions packages/jsii-ruby-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Ruby client for jsii runtime",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"private": true,
"scripts": {
"gen": "/bin/bash generate.sh",
"deps": "cd project && bundle install",
Expand Down

0 comments on commit 64ced3f

Please sign in to comment.