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(jsii-pacmak): option to disallow parallel generation of languages #1890

Merged
merged 4 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
63 changes: 48 additions & 15 deletions packages/jsii-pacmak/bin/jsii-pacmak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ import { ALL_BUILDERS, TargetName } from '../lib/targets';
"Translate code samples on-the-fly if they can't be found in the samples tablet",
default: true,
})
.option('parallel', {
type: 'boolean',
desc:
'Generate all configured targets in parallel (disabling this might help if you encounter EMFILE errors)',
default: true,
})
.version(VERSION_DESC)
.strict().argv;

Expand Down Expand Up @@ -165,21 +171,25 @@ import { ALL_BUILDERS, TargetName } from '../lib/targets';

// We run all target sets in parallel for minimal wall clock time
await Promise.all(
targetSets.map(async (targetSet) => {
logging.info(
`Packaging '${targetSet.targetType}' for ${describePackages(
targetSet,
)}`,
);
await timers.recordAsync(targetSet.targetType, () =>
buildTargetsForLanguage(
targetSet.targetType,
targetSet.modules,
perLanguageDirectory,
),
);
logging.info(`${targetSet.targetType} finished`);
}),
mapParallelOrSerial(
targetSets,
async (targetSet) => {
logging.info(
`Packaging '${targetSet.targetType}' for ${describePackages(
targetSet,
)}`,
);
await timers.recordAsync(targetSet.targetType, () =>
buildTargetsForLanguage(
targetSet.targetType,
targetSet.modules,
perLanguageDirectory,
),
);
logging.info(`${targetSet.targetType} finished`);
},
{ parallel: argv.parallel },
),
);
} finally {
if (argv.clean) {
Expand Down Expand Up @@ -266,3 +276,26 @@ function describePackages(target: TargetSet) {
}
return `${target.modules.length} modules`;
}

function mapParallelOrSerial<T, R>(
collection: readonly T[],
mapper: (item: T) => Promise<R>,
{ parallel }: { parallel: boolean },
): Array<Promise<R>> {
const result = new Array<Promise<R>>();
for (const item of collection) {
result.push(
result.length === 0 || parallel
? // Running parallel, or first element
mapper(item)
: // Wait for the previous promise, then make the next one
result[result.length - 1].then(
() => mapper(item),
(error) => {
throw error;
},
),
);
}
return result;
}
2 changes: 1 addition & 1 deletion packages/jsii-pacmak/test/build-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ done
# Multiple targets, build all at once into own directory
clean_dists
echo "Testing ALL-AT-ONCE build."
../bin/jsii-pacmak $packagedirs
../bin/jsii-pacmak --no-parallel $packagedirs