-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): build intermediates need to be captured by cache for DTE /…
… parallel builds (#596)
- Loading branch information
1 parent
2ea2570
commit cdea76e
Showing
19 changed files
with
221 additions
and
25 deletions.
There are no files selected for viewing
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
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,20 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
|
||
<TargetFramework>net6.0</TargetFramework> | ||
|
||
<Nullable>enable</Nullable> | ||
|
||
<ImplicitUsings>enable</ImplicitUsings> | ||
|
||
<OutputPath>../../../dist/demo/apps/webapi</OutputPath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
|
||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3"/> | ||
|
||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\libs\csharp-models\NxDotnet.Demo.Libs.CsharpModels.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,5 @@ | ||
namespace NxDotnet.Demo.Libs.CsharpModels; | ||
public class Class1 | ||
{ | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
demo/libs/csharp-models/NxDotnet.Demo.Libs.CsharpModels.csproj
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,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
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,28 @@ | ||
{ | ||
"name": "demo-csharp-models", | ||
"$schema": "../../../node_modules/nx/schemas/project-schema.json", | ||
"projectType": "library", | ||
"sourceRoot": "demo/libs/csharp-models", | ||
"targets": { | ||
"build": { | ||
"executor": "@nx-dotnet/core:build", | ||
"outputs": [ | ||
"{workspaceRoot}/dist/demo/libs/csharp-models", | ||
"{workspaceRoot}/dist/intermediates/demo/libs/csharp-models/obj" | ||
], | ||
"options": { | ||
"configuration": "Debug", | ||
"noDependencies": true | ||
}, | ||
"configurations": { | ||
"production": { | ||
"configuration": "Release" | ||
} | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nx-dotnet/core:format" | ||
} | ||
}, | ||
"tags": [] | ||
} |
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 |
---|---|---|
|
@@ -15,5 +15,5 @@ | |
} | ||
} | ||
}, | ||
"implicitDependencies": ["demo-apps-webapi"] | ||
"implicitDependencies": ["demo-webapi"] | ||
} |
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
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
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
132 changes: 132 additions & 0 deletions
132
packages/core/src/migrations/update-1.18.1/add-intermediate-outputs.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 |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { | ||
formatFiles, | ||
getProjects, | ||
logger, | ||
ProjectConfiguration, | ||
readNxJson, | ||
Tree, | ||
updateProjectConfiguration, | ||
writeJson, | ||
} from '@nrwl/devkit'; | ||
import { TargetDefaults } from 'nx/src/config/nx-json'; | ||
import { gt } from 'semver'; | ||
import { XmlDocument } from 'xmldoc'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const nxVersion = require('nx/package.json').version; | ||
|
||
export default function update(host: Tree) { | ||
const projects = getProjects(host); | ||
const directoryBuildPropsExists = host.exists('Directory.Build.props'); | ||
const directoryBuildPropsUpdated = | ||
directoryBuildPropsExists && updateDirectoryBuildProps(host); | ||
|
||
for (const [project, configuration] of projects) { | ||
const changed = updateTargetOutputs( | ||
directoryBuildPropsUpdated, | ||
configuration, | ||
); | ||
if (changed) { | ||
updateProjectConfiguration(host, project, configuration); | ||
} | ||
} | ||
|
||
updateTargetDefaults(host, directoryBuildPropsUpdated); | ||
|
||
formatFiles(host); | ||
} | ||
|
||
function updateDirectoryBuildProps(host: Tree): boolean { | ||
const contents = host.read('Directory.Build.props', 'utf-8'); | ||
if (!contents) { | ||
logger.warn('Unable to read "Directory.Build.props"'); | ||
return false; | ||
} | ||
const xml = new XmlDocument(contents); | ||
const propertyGroups = xml.childrenNamed('PropertyGroup'); | ||
const outputManipulationGroup = propertyGroups.find((group) => | ||
group.childNamed('OutputPath'), | ||
); | ||
if (!outputManipulationGroup) { | ||
logger.warn( | ||
'Unable to find property group containing output manipulation in Directory.Build.props', | ||
); | ||
return false; | ||
} | ||
outputManipulationGroup.children.push( | ||
new XmlDocument( | ||
`<BaseIntermediateOutputPath>$(RepoRoot)dist/intermediates/$(ProjectRelativePath)/obj</BaseIntermediateOutputPath>`, | ||
), | ||
); | ||
outputManipulationGroup.children.push( | ||
new XmlDocument( | ||
`<IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>`, | ||
), | ||
); | ||
host.write('Directory.Build.props', xml.toString()); | ||
return true; | ||
} | ||
|
||
function updateTargetOutputs( | ||
directoryBuildPropsUpdated: boolean, | ||
configuration: ProjectConfiguration, | ||
): boolean { | ||
let changed = false; | ||
|
||
const targets = Object.values(configuration.targets ?? {}).filter( | ||
(x) => x.executor === '@nx-dotnet/core:build', | ||
); | ||
|
||
for (const target of targets) { | ||
if (directoryBuildPropsUpdated) { | ||
if (!target.outputs?.some((x) => x.includes('intermediates'))) { | ||
const prefix = gt(nxVersion, '15.0.0-beta.0') ? '{workspaceRoot}/' : ''; | ||
target.outputs?.push( | ||
prefix + `dist/intermediates/${configuration.root}`, | ||
); | ||
changed = true; | ||
} | ||
} else { | ||
if (!target.outputs?.some((x) => x.includes('obj'))) { | ||
const prefix = gt(nxVersion, '15.0.0-beta.0') | ||
? '{projectRoot}/' | ||
: `${configuration.root}/`; | ||
target.outputs?.push(prefix + `obj`); | ||
changed = true; | ||
} | ||
} | ||
} | ||
return changed; | ||
} | ||
|
||
function updateTargetDefaults(host: Tree, directoryBuildPropsUpdated: boolean) { | ||
let changed = false; | ||
const nxJson = readNxJson(); | ||
const targetDefaults: TargetDefaults | undefined = nxJson.targetDefaults; | ||
|
||
if (!targetDefaults) { | ||
return; | ||
} | ||
|
||
const configuration = targetDefaults['@nx-dotnet/core:build']; | ||
if (configuration) { | ||
if (directoryBuildPropsUpdated) { | ||
if (!configuration.outputs?.some((x) => x.includes('intermediates'))) { | ||
configuration.outputs?.push( | ||
`{workspaceRoot}/dist/intermediates/{projectRoot}`, | ||
); | ||
changed = true; | ||
} | ||
} else { | ||
if (!configuration.outputs?.some((x) => x.includes('obj'))) { | ||
configuration.outputs?.push(`{projectRoot}/obj`); | ||
changed = true; | ||
} | ||
} | ||
} | ||
|
||
if (changed) { | ||
writeJson(host, 'nx.json', nxJson); | ||
} | ||
} |
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