Skip to content
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

feat(rosetta): extract and compile samples into "tablets" #925

Merged
merged 24 commits into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d990d68
feat(rosetta): extract and compile samples into "tablets"
rix0rrr Oct 31, 2019
7a0bd5c
Update some expectations
Nov 1, 2019
b90923f
WIP
Nov 1, 2019
2c6f2a3
Make `extract` use worker threads if available
Nov 1, 2019
78cbf8f
Update README
Nov 4, 2019
b34d736
Review comments
rix0rrr Nov 7, 2019
51a6bae
Try to make Python build succeed from a dirty state
rix0rrr Nov 7, 2019
d3b82c0
Merge remote-tracking branch 'origin/master' into huijbers/extract-sa…
Nov 11, 2019
224037f
Missing &&
Nov 11, 2019
8a0d470
Merge remote-tracking branch 'origin/master' into huijbers/extract-sa…
Nov 11, 2019
5380991
Fix pacmak unified build sanity
Nov 12, 2019
6efc55c
Render HTML comments as-is
Nov 12, 2019
965848f
Add backwards compatible support for literate examples
Nov 12, 2019
db49b0e
Merge remote-tracking branch 'origin/master' into huijbers/extract-sa…
Nov 12, 2019
b059c5c
Fix dependencies on packages outside the compile set
Nov 12, 2019
c489266
Use the right output dir for source-only mode
Nov 12, 2019
d30c3ef
Add test for different pacmak build modes
Nov 12, 2019
9e97489
Only include existing directories
Nov 13, 2019
4eb11e3
Satisfy eslint
Nov 13, 2019
c81f1cc
Merge remote-tracking branch 'origin/master' into huijbers/extract-sa…
Nov 13, 2019
42512e2
Handle @ signs in examples
Nov 13, 2019
34a397a
Merge remote-tracking branch 'origin/master' into huijbers/extract-sa…
Nov 13, 2019
9f597f3
Satisfy eslint
Nov 13, 2019
a63e55e
Don't report diagnostics originating from hidden source
Nov 13, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ tsconfig.tsbuildinfo
dist/
.vscode
*.tsbuildinfo
*.tabl.json
3 changes: 2 additions & 1 deletion packages/jsii-calc-base-of-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "jsii",
"build": "jsii && jsii-rosetta",
"test": "diff-test test/assembly.jsii .jsii",
"test:update": "npm run build && UPDATE_DIFF=1 npm run test"
},
"devDependencies": {
"jsii": "^0.20.5",
"jsii-rosetta": "^0.20.5",
"jsii-build-tools": "^0.20.5"
},
"jsii": {
Expand Down
5 changes: 3 additions & 2 deletions packages/jsii-calc-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "jsii",
"build": "jsii && jsii-rosetta",
"test": "diff-test test/assembly.jsii .jsii",
"test:update": "npm run build && UPDATE_DIFF=1 npm run test"
},
Expand All @@ -36,6 +36,7 @@
},
"devDependencies": {
"jsii": "^0.20.5",
"jsii-rosetta": "^0.20.5",
"jsii-build-tools": "^0.20.5"
},
"jsii": {
Expand All @@ -59,4 +60,4 @@
},
"versionFormat": "short"
}
}
}
4 changes: 4 additions & 0 deletions packages/jsii-calc-lib/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@

# Include .jsii
!.jsii


# Exclude jsii outdir
dist
5 changes: 3 additions & 2 deletions packages/jsii-calc-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "jsii",
"build": "jsii && jsii-rosetta",
"test": "diff-test test/assembly.jsii .jsii",
"test:update": "npm run build && UPDATE_DIFF=1 npm run test"
},
Expand All @@ -38,6 +38,7 @@
},
"devDependencies": {
"jsii": "^0.20.5",
"jsii-rosetta": "^0.20.5",
"jsii-build-tools": "^0.20.5"
},
"jsii": {
Expand All @@ -63,4 +64,4 @@
},
"versionFormat": "short"
}
}
}
17 changes: 12 additions & 5 deletions packages/jsii-calc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

This library is used to demonstrate and test the features of JSII

## Sphinx
## How to use running sum API:

This file will be incorporated into the sphinx documentation.
First, create a calculator:

If this file starts with an "H1" line (in our case `# jsii Calculator`), this
heading will be used as the Sphinx topic name. Otherwise, the name of the module
(`jsii-calc`) will be used instead.
```ts
const calculator = new calc.Calculator();
```

Then call some operations:


```ts fixture=with-calculator
calculator.add(10);
```

## Code Samples

Expand Down
5 changes: 3 additions & 2 deletions packages/jsii-calc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "jsii",
"build": "jsii && jsii-rosetta --compile",
"watch": "jsii -w",
"test": "node test/test.calc.js && diff-test test/assembly.jsii .jsii",
"test:update": "npm run build && UPDATE_DIFF=1 npm run test"
Expand All @@ -43,6 +43,7 @@
},
"devDependencies": {
"jsii": "^0.20.5",
"jsii-rosetta": "^0.20.5",
"jsii-build-tools": "^0.20.5"
},
"jsii": {
Expand Down Expand Up @@ -100,4 +101,4 @@
]
}
]
}
}
3 changes: 3 additions & 0 deletions packages/jsii-calc/rosetta/default.ts-fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import calc = require('.');

/// here
4 changes: 4 additions & 0 deletions packages/jsii-calc/rosetta/with-calculator.ts-fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import calc = require('.');
const calculator = new calc.Calculator();

/// here
4 changes: 2 additions & 2 deletions packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
},
"name": "jsii-calc",
"readme": {
"markdown": "# jsii Calculator\n\nThis library is used to demonstrate and test the features of JSII\n\n## Sphinx\n\nThis file will be incorporated into the sphinx documentation.\n\nIf this file starts with an \"H1\" line (in our case `# jsii Calculator`), this\nheading will be used as the Sphinx topic name. Otherwise, the name of the module\n(`jsii-calc`) will be used instead.\n\n## Code Samples\n\n```ts\n/* This is totes a magic comment in here, just you wait! */\nconst foo = 'bar';\n```\n"
"markdown": "# jsii Calculator\n\nThis library is used to demonstrate and test the features of JSII\n\n## How to use running sum API:\n\nFirst, create a calculator:\n\n```ts\nconst calculator = new calc.Calculator();\n```\n\nThen call some operations:\n\n\n```ts fixture=with-calculator\ncalculator.add(10);\n```\n\n## Code Samples\n\n```ts\n/* This is totes a magic comment in here, just you wait! */\nconst foo = 'bar';\n```\n"
},
"repository": {
"directory": "packages/jsii-calc",
Expand Down Expand Up @@ -11128,5 +11128,5 @@
}
},
"version": "0.20.5",
"fingerprint": "g9C1lL8c+vgxBjOWVBFMMPlcwkF3Z81xxTAGfc73x9o="
"fingerprint": "/MRTbTnRC1UWxsPIrca+9Yo1IBKsEueT75P22pQoV1o="
}
31 changes: 25 additions & 6 deletions packages/jsii-pacmak/bin/jsii-pacmak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import path = require('path');
import process = require('process');
import yargs = require('yargs');
import { Rosetta } from 'jsii-rosetta';
import logging = require('../lib/logging');
import { Timers } from '../lib/timer';
import { VERSION_DESC } from '../lib/version';
Expand Down Expand Up @@ -78,6 +79,15 @@ import { ALL_BUILDERS, TargetName } from '../lib/targets';
desc: 'Auto-update .npmignore to exclude the output directory and include the .jsii file',
default: true
})
.option('rosetta-tablet', {
type: 'string',
desc: 'Location of a jsii-rosetta tablet with sample translations (created using \'jsii-rosetta extract\')'
rix0rrr marked this conversation as resolved.
Show resolved Hide resolved
})
.option('rosetta-translate-live', {
type: 'boolean',
desc: 'Translate code samples on-the-fly if they can\'t be found in the samples tablet',
default: true
})
.version(VERSION_DESC)
.strict()
.argv;
Expand All @@ -89,6 +99,11 @@ import { ALL_BUILDERS, TargetName } from '../lib/targets';

const timers = new Timers();

const rosetta = new Rosetta({ liveConversion: argv['rosetta-translate-live'] });
if (argv['rosetta-tablet']) {
await rosetta.loadTabletFromFile(argv['rosetta-tablet']);
}

const modulesToPackage = await findJsiiModules(argv._, argv.recurse);
logging.info(`Found ${modulesToPackage.length} modules to package`);
if (modulesToPackage.length === 0) {
Expand All @@ -114,9 +129,12 @@ import { ALL_BUILDERS, TargetName } from '../lib/targets';
});

await timers.recordAsync('load jsii', () => {
logging.info('Loading jsii assemblies');
logging.info('Loading jsii assemblies and translations');
return Promise.all(modulesToPackage
.map(m => m.load()));
.map(async m => {
await m.load();
await rosetta.addAssembly(m.assembly.spec, m.moduleDirectory);
}));
});

try {
Expand Down Expand Up @@ -155,19 +173,20 @@ import { ALL_BUILDERS, TargetName } from '../lib/targets';

async function buildTargetsForLanguage(targetLanguage: string, modules: JsiiModule[], perLanguageDirectory: boolean) {
// ``argv.target`` is guaranteed valid by ``yargs`` through the ``choices`` directive.
const builder = ALL_BUILDERS[targetLanguage as TargetName];
if (!builder) {
const factory = ALL_BUILDERS[targetLanguage as TargetName];
if (!factory) {
throw new Error(`Unsupported target: '${targetLanguage}'`);
}

await builder.buildModules(modules, {
await factory(modules, {
clean: argv.clean,
codeOnly: argv['code-only'],
rosetta,
force: argv.force,
fingerprint: argv.fingerprint,
arguments: argv,
languageSubdirectory: perLanguageDirectory,
});
}).buildModules();
}
})().catch(err => {
process.stderr.write(`${err.stack}\n`);
Expand Down
36 changes: 19 additions & 17 deletions packages/jsii-pacmak/lib/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import logging = require('./logging');
import { JsiiModule } from './packaging';
import { TargetConstructor, Target } from './target';
import { Scratch } from './util';
import { Rosetta } from 'jsii-rosetta';

export interface BuildOptions {
/**
Expand Down Expand Up @@ -36,6 +37,11 @@ export interface BuildOptions {
* Whether to add an additional subdirectory for the target language
*/
languageSubdirectory?: boolean;

/**
* The Rosetta instance to load examples from
*/
rosetta: Rosetta;
}

/**
Expand All @@ -44,32 +50,27 @@ export interface BuildOptions {
* Building can happen one target at a time, or multiple targets at a time.
*/
export interface TargetBuilder {
buildModules(modules: JsiiModule[], options: BuildOptions): Promise<void>;
}

/**
* Return the output directory if all modules have the same directory
*/
export function allOutputDirectoriesTheSame(modules: JsiiModule[]): boolean {
if (modules.length === 0) { return true; }
const ret = modules[0].outputDirectory;
return modules.every(m => m.outputDirectory === ret);
buildModules(): Promise<void>;
}

/**
* Builds the targets for the given language sequentially
*/
export class OneByOneBuilder implements TargetBuilder {
public constructor(private readonly targetName: string, private readonly targetConstructor: TargetConstructor) {
public constructor(
private readonly targetName: string,
private readonly targetConstructor: TargetConstructor,
private readonly modules: JsiiModule[],
private readonly options: BuildOptions) {

}

public async buildModules(modules: JsiiModule[], options: BuildOptions): Promise<void> {
for (const module of modules) {
if (options.codeOnly) {
await this.generateModuleCode(module, options);
public async buildModules(): Promise<void> {
for (const module of this.modules) {
if (this.options.codeOnly) {
await this.generateModuleCode(module, this.options);
} else {
await this.buildModule(module, options);
await this.buildModule(module, this.options);
}
}
}
Expand Down Expand Up @@ -110,7 +111,8 @@ export class OneByOneBuilder implements TargetBuilder {
assembly: module.assembly,
fingerprint: options.fingerprint,
force: options.force,
arguments: options.arguments
arguments: options.arguments,
rosetta: options.rosetta,
});
}

Expand Down
Loading