Skip to content

Commit

Permalink
Revert "Revert "Improve components infrastructure (#12145)" (#12679)" (
Browse files Browse the repository at this point in the history
…#12744)

* Revert "Revert "Improve components infrastructure (#12145)" (#12679)"

This reverts commit e2d57e2. The improvement to components infrastructure is now reinstated with the following changes:

* Check in release JS artifacts and use them as a fallback when it's not possible to build npmproj.
* Dont' build nodejs in source build.
  • Loading branch information
John Luo authored Aug 5, 2019
1 parent 397f924 commit 43350b5
Show file tree
Hide file tree
Showing 16 changed files with 161 additions and 55 deletions.
20 changes: 17 additions & 3 deletions .azure/pipelines/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ variables:
- ${{ if or(eq(variables['System.TeamProject'], 'public'), in(variables['Build.Reason'], 'PullRequest')) }}:
- name: _BuildArgs
value: ''

jobs:
# Code check
- template: jobs/default-build.yml
parameters:
jobName: Code_check
Expand All @@ -38,6 +40,10 @@ jobs:
steps:
- powershell: ./eng/scripts/CodeCheck.ps1 -ci
displayName: Run eng/scripts/CodeCheck.ps1
artifacts:
- name: Code_Check_Logs
path: artifacts/log/
publishOnError: true

# Build Windows (x64/x86)
- template: jobs/default-build.yml
Expand Down Expand Up @@ -171,6 +177,7 @@ jobs:
-bl:artifacts/log/build.macos.binlog
$(_BuildArgs)
installNodeJs: false
installJdk: false
artifacts:
- name: MacOS_x64_Packages
path: artifacts/packages/
Expand All @@ -191,7 +198,6 @@ jobs:
jobName: Linux_x64_build
jobDisplayName: "Build: Linux x64"
agentOs: Linux
installNodeJs: false
steps:
- script: ./build.sh
--ci
Expand All @@ -211,6 +217,7 @@ jobs:
--arch x64 \
--build-installers \
--no-build-deps \
--no-build-nodejs \
-p:OnlyPackPlatformSpecificPackages=true \
-p:BuildRuntimeArchive=false \
-p:LinuxInstallerType=deb \
Expand All @@ -224,12 +231,15 @@ jobs:
--arch x64 \
--build-installers \
--no-build-deps \
--no-build-nodejs \
-p:OnlyPackPlatformSpecificPackages=true \
-p:BuildRuntimeArchive=false \
-p:LinuxInstallerType=rpm \
-bl:artifacts/log/build.rpm.binlog \
$(_BuildArgs)
displayName: Build RPM installers
installNodeJs: false
installJdk: false
artifacts:
- name: Linux_x64_Packages
path: artifacts/packages/
Expand Down Expand Up @@ -260,6 +270,7 @@ jobs:
-bl:artifacts/log/build.linux-arm.binlog
$(_BuildArgs)
installNodeJs: false
installJdk: false
artifacts:
- name: Linux_arm_Packages
path: artifacts/packages/
Expand Down Expand Up @@ -290,6 +301,7 @@ jobs:
-bl:artifacts/log/build.arm64.binlog
$(_BuildArgs)
installNodeJs: false
installJdk: false
artifacts:
- name: Linux_arm64_Packages
path: artifacts/packages/
Expand Down Expand Up @@ -323,6 +335,7 @@ jobs:
-bl:artifacts/log/build.musl.binlog
$(_BuildArgs)
installNodeJs: false
installJdk: false
artifacts:
- name: Linux_musl_x64_Packages
path: artifacts/packages/
Expand All @@ -337,7 +350,7 @@ jobs:
parameters:
inputName: Linux_musl_x64

# Build Linux Musl arm64
# Build Linux Musl ARM64
- template: jobs/default-build.yml
parameters:
jobName: Linux_musl_arm64_build
Expand All @@ -356,6 +369,7 @@ jobs:
-bl:artifacts/log/build.musl.binlog
$(_BuildArgs)
installNodeJs: false
installJdk: false
artifacts:
- name: Linux_musl_arm64_Packages
path: artifacts/packages/
Expand Down Expand Up @@ -499,7 +513,7 @@ jobs:
version: 3.0.x
installationPath: $(DotNetCoreSdkDir)
includePreviewVersions: true
- script: ./eng/scripts/ci-source-build.sh --ci --configuration Release /p:BuildManaged=true
- script: ./eng/scripts/ci-source-build.sh --ci --configuration Release /p:BuildManaged=true /p:BuildNodeJs=false
displayName: Run ci-source-build.sh
- task: PublishBuildArtifacts@1
displayName: Upload logs
Expand Down
21 changes: 20 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,33 @@ elseif ($Projects) {
}
# When adding new sub-group build flags, add them to this check.
elseif((-not $BuildNative) -and (-not $BuildManaged) -and (-not $BuildNodeJS) -and (-not $BuildInstallers) -and (-not $BuildJava)) {
Write-Warning "No default group of projects was specified, so building the 'managed' subsets of projects. Run ``build.cmd -help`` for more details."
Write-Warning "No default group of projects was specified, so building the 'managed' and its dependent subsets of projects. Run ``build.cmd -help`` for more details."

# This goal of this is to pick a sensible default for `build.cmd` with zero arguments.
# Now that we support subfolder invokations of build.cmd, we will be pushing to have build.cmd build everything (-all) by default

$BuildManaged = $true
}

if ($BuildManaged -or ($All -and (-not $NoBuildManaged))) {
if ((-not $BuildNodeJS) -and (-not $NoBuildNodeJS)) {
$node = Get-Command node -ErrorAction Ignore -CommandType Application

if ($node) {
$nodeHome = Split-Path -Parent (Split-Path -Parent $node.Path)
Write-Host -f Magenta "Building of C# project is enabled and has dependencies on NodeJS projects. Building of NodeJS projects is enabled since node is detected in $nodeHome."
}
else {
Write-Host -f Magenta "Building of NodeJS projects is disabled since node is not detected on Path and no BuildNodeJs or NoBuildNodeJs setting is set explicitly."
$NoBuildNodeJS = $true
}
}

if ($NoBuildNodeJS){
Write-Warning "Some managed projects depend on NodeJS projects. Building NodeJS is disabled so the managed projects will fallback to using the output from previous builds. The output may not be correct or up to date."
}
}

if ($BuildInstallers) { $MSBuildArguments += "/p:BuildInstallers=true" }
if ($BuildManaged) { $MSBuildArguments += "/p:BuildManaged=true" }
if ($BuildNative) { $MSBuildArguments += "/p:BuildNative=true" }
Expand Down
17 changes: 16 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,29 @@ elif [ ! -z "$build_projects" ]; then
elif [ -z "$build_managed" ] && [ -z "$build_nodejs" ] && [ -z "$build_java" ] && [ -z "$build_native" ] && [ -z "$build_installers" ]; then
# This goal of this is to pick a sensible default for `build.sh` with zero arguments.
# We believe the most common thing our contributors will work on is C#, so if no other build group was picked, build the C# projects.
__warn "No default group of projects was specified, so building the 'managed' subset of projects. Run ``build.sh --help`` for more details."
__warn "No default group of projects was specified, so building the 'managed' and its dependent subset of projects. Run ``build.sh --help`` for more details."
build_managed=true
fi

if [ "$build_deps" = false ]; then
msbuild_args[${#msbuild_args[*]}]="-p:BuildProjectReferences=false"
fi

if [ "$build_managed" = true ] || (["$build_all" = true ] && [ "$build_managed" != false ]); then
if [ -z "$build_nodejs" ]; then
if [ -x "$(command -v node)" ]; then
__warn "Building of C# project is enabled and has dependencies on NodeJS projects. Building of NodeJS projects is enabled since node is detected on PATH."
else
__warn "Building of NodeJS projects is disabled since node is not detected on Path and no BuildNodeJs or NoBuildNodeJs setting is set explicitly."
build_nodejs=false
fi
fi

if [ "$build_nodejs" = false ]; then
__warn "Some managed projects depend on NodeJS projects. Building NodeJS is disabled so the managed projects will fallback to using the output from previous builds. The output may not be correct or up to date."
fi
fi

# Only set these MSBuild properties if they were explicitly set by build parameters.
[ ! -z "$build_java" ] && msbuild_args[${#msbuild_args[*]}]="-p:BuildJava=$build_java"
[ ! -z "$build_native" ] && msbuild_args[${#msbuild_args[*]}]="-p:BuildNative=$build_native"
Expand Down
6 changes: 4 additions & 2 deletions docs/BuildFromSource.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ The cause of this problem is that the solution you are using does not include th
```
### Common error: Unable to locate the .NET Core SDK
Executing `.\restore.cmd` or `.\build.cmd` may produce these errors:
> error : Unable to locate the .NET Core SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version.
> error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.
In most cases, this is because the option _Use previews of the .NET Core SDK_ in VS2019 is not checked. Start Visual Studio, go to _Tools > Options_ and check _Use previews of the .NET Core SDK_ under _Environment > Preview Features_.
## Building with Visual Studio Code
Using Visual Studio Code with this repo requires setting environment variables on command line first.
Expand Down Expand Up @@ -138,6 +138,8 @@ On macOS/Linux:
./build.sh
```

By default, all of the C# projects are built. Some C# projects requires NodeJS to be installed to compile JavaScript assets which are then checked in as source. If NodeJS is detected on the path, the NodeJS projects will be compiled as part of building C# projects. If NodeJS is not detected on the path, the JavaScript assets checked in previously will be used instead. To disable building NodeJS projects, specify /p:BuildNodeJs=false on the command line.

### Using `dotnet` on command line in this repo

Because we are using pre-release versions of .NET Core, you have to set a handful of environment variables
Expand Down
13 changes: 8 additions & 5 deletions eng/Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
</PropertyGroup>

<PropertyGroup Condition=" '$(BuildAllProjects)' == 'true' ">
<BuildNative>true</BuildNative>
<BuildManaged>true</BuildManaged>
<BuildNodeJS>true</BuildNodeJS>
<BuildJava>true</BuildJava>
<BuildNative Condition="'$(BuildNative)' == ''">true</BuildNative>
<BuildManaged Condition="'$(BuildManaged)' == ''">true</BuildManaged>
<BuildNodeJS Condition="'$(BuildNodeJS)' == ''">true</BuildNodeJS>
<BuildJava Condition="'$(BuildJava)' == ''">true</BuildJava>
</PropertyGroup>

<!-- These projects are always excluded, even when -projects is specified on command line. -->
<ItemGroup>
<!-- Explicitly excluded projects -->
<ProjectToExclude Include="$(ProjectToExclude)" />

<!-- These projects use 'legacy' csproj, which is not supported by dotnet-msbuild. -->
<ProjectToExclude Include="
Expand All @@ -31,6 +33,7 @@
$(RepoRoot)src\submodules\**\*.*proj;
$(RepoRoot)src\Installers\**\*.*proj;
$(RepoRoot)src\SignalR\clients\ts\**\node_modules\**\*.*proj;
$(RepoRoot)src\Components\Web.JS\node_modules\**\*.*proj;
$(RepoRoot)src\Components\Blazor\Templates\src\content\**\*.*proj;
$(RepoRoot)src\ProjectTemplates\Web.ProjectTemplates\content\**\*.csproj;
$(RepoRoot)src\ProjectTemplates\Web.ProjectTemplates\content\**\*.fsproj;
Expand All @@ -43,7 +46,6 @@
$(RepoRoot)src\Servers\Kestrel\perf\PlatformBenchmarks\**\*.csproj;
$(RepoRoot)src\SignalR\perf\benchmarkapps\**\*.csproj;
" />

</ItemGroup>

<Choose>
Expand Down Expand Up @@ -102,6 +104,7 @@
<ProjectToExclude Condition=" '$(BuildNative)' != 'true'" Include="@(NativeProjects)" />

<NodeJsProjects Include="
$(RepoRoot)src\Components\Web.JS\Microsoft.AspNetCore.Components.Web.JS.npmproj;
$(RepoRoot)src\SignalR\**\*.npmproj;
$(RepoRoot)src\Middleware\**\*.npmproj;
"
Expand Down
5 changes: 0 additions & 5 deletions eng/scripts/CodeCheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,6 @@ try {
& dotnet run -p "$repoRoot/eng/tools/BaselineGenerator/"
}

Write-Host "Re-generating Web.JS files"
Invoke-Block {
& dotnet build "$repoRoot\src\Components\Web.JS\Microsoft.AspNetCore.Components.Web.JS.npmproj"
}

Write-Host "Run git diff to check for pending changes"

# Redirect stderr to stdout because PowerShell does not consistently handle output to stderr
Expand Down
17 changes: 15 additions & 2 deletions eng/targets/Npm.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,28 @@
<IntermediateOutputPath>$([MSBuild]::NormalizeDirectory('$(BaseIntermediateOutputPath)'))$(Configuration)\</IntermediateOutputPath>
<InstallArgs Condition="'$(RestoreLockedMode)' == 'true'">--frozen-lockfile</InstallArgs>
<_BackupPackageJson>$(IntermediateOutputPath)$(MSBuildProjectName).package.json.bak</_BackupPackageJson>
<BuildDependsOn>
PrepareForBuild;
ResolveProjectReferences;
_Build;
</BuildDependsOn>
<NpmBuildArgs Condition="'$(NpmBuildArgs)' == ''">run build</NpmBuildArgs>
</PropertyGroup>

<ItemGroup>
<TSFiles Include="$(MSBuildProjectDirectory)\*\*.ts" />
<TSFiles Include="$(MSBuildProjectDirectory)\package.json" />
<TSFiles Include="$(MSBuildProjectDirectory)\*.npmproj" />
</ItemGroup>

<Target Name="_CheckForInvalidConfiguration">
<Error Text="Missing expected property: PackageId" Condition="'$(IsPackable)' != 'false' and '$(PackageId)' == ''" />

<Exec ContinueOnError="true" Command="node -v">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
</Exec>

<Error Text="Building *.npmproj but NodeJS was not detected on path. Ensure NodeJS is on path or disable building NodeJS projects with /p:BuildNodeJs=false. Skipping NodeJS projects will also skip managed projects depending on them, including Components, Mvc and Analysers." Condition="'$(ErrorCode)' != '0'"/>
</Target>

<Target Name="Restore">
Expand All @@ -36,13 +49,13 @@
BuildInParallel="true" />
</Target>

<Target Name="Build" DependsOnTargets="PrepareForBuild;ResolveProjectReferences;_Build" />
<Target Name="Build" DependsOnTargets="$(BuildDependsOn)" />

<Target Name="_Build"
Condition="'$(IsBuildable)' != 'false'"
Inputs="@(TSFiles)"
Outputs="$(BaseIntermediateOutputPath)\build-sentinel" >
<Yarn Command="run build" StandardOutputImportance="High" StandardErrorImportance="High" />
<Yarn Command="$(NpmBuildArgs)" StandardOutputImportance="High" StandardErrorImportance="High" />
<WriteLinesToFile Overwrite="true" File="$(BaseIntermediateOutputPath)\build-sentinel" />
</Target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,4 @@
<!-- loader.js is hard-coded to assume it can load .pdbs regardless of Debug/Release configuration -->
<BlazorEnableDebugging>true</BlazorEnableDebugging>
</PropertyGroup>

<ItemGroup>
</ItemGroup>
</Project>
10 changes: 10 additions & 0 deletions src/Components/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@

<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)THIRD-PARTY-NOTICES.txt" Pack="true" PackagePath="." />

<!-- Add a project dependency without reference output assemblies to enforce build order -->
<!-- Applying workaround for https://github.com/microsoft/msbuild/issues/2661 and https://github.com/dotnet/sdk/issues/952 -->
<ProjectReference
Condition="'$(ReferenceBlazorBuildLocally)' == 'true' and '$(BuildNodeJS)' != 'false'"
Include="$(RepoRoot)src\Components\Web.JS\Microsoft.AspNetCore.Components.Web.JS.npmproj"
ReferenceOutputAssemblies="false"
SkipGetTargetFrameworkProperties="true"
UndefineProperties="TargetFramework"
Private="false" />
</ItemGroup>

<Import Project="Blazor\Build\src\ReferenceFromSource.props" Condition="'$(ReferenceBlazorBuildLocally)' == 'true'" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
<Reference Include="Microsoft.Extensions.FileProviders.Embedded" />
<Reference Include="Microsoft.Extensions.Logging" />
<Reference Include="Microsoft.Extensions.ValueStopwatch.Sources" PrivateAssets="All" />

<!-- Add a project dependency without reference output assemblies to enforce build order -->
<!-- Applying workaround for https://github.com/microsoft/msbuild/issues/2661 and https://github.com/dotnet/sdk/issues/952 -->
<ProjectReference
Include="..\..\Web.JS\Microsoft.AspNetCore.Components.Web.JS.npmproj"
ReferenceOutputAssemblies="false"
SkipGetTargetFrameworkProperties="true"
UndefineProperties="TargetFramework"
Private="false"
Condition="'$(BuildNodeJS)' != 'false'" />
</ItemGroup>

<PropertyGroup>
Expand Down Expand Up @@ -53,12 +63,7 @@
</ItemGroup>

<PropertyGroup>
<!--
We check in the Release / Production build of blazor.*.js, but not the Debug builds. Consequently the former is always available to embed, the latter is only available
if Web.JS was built locally. Use the Debug build when available and building in Debug configuration.
-->
<BlazorServerJSFile>..\..\Web.JS\dist\Release\blazor.server.js</BlazorServerJSFile>
<BlazorServerJSFile Condition="'$(Configuration)' == 'Debug' AND Exists('..\..\Web.JS\dist\Debug\blazor.server.js')">..\..\Web.JS\dist\Debug\blazor.server.js</BlazorServerJSFile>
<BlazorServerJSFile>..\..\Web.JS\dist\$(Configuration)\blazor.server.js</BlazorServerJSFile>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\SignalR\clients\ts\signalr\signalr.npmproj" />
<ProjectReference Include="..\..\SignalR\clients\ts\signalr-protocol-msgpack\signalr-protocol-msgpack.npmproj" />
<ProjectReference
Include="..\..\SignalR\clients\ts\signalr\signalr.npmproj"
ReferenceOutputAssemblies="false"
SkipGetTargetFrameworkProperties="true"
UndefineProperties="TargetFramework"
Private="false" />
<ProjectReference
Include="..\..\SignalR\clients\ts\signalr-protocol-msgpack\signalr-protocol-msgpack.npmproj"
ReferenceOutputAssemblies="false"
SkipGetTargetFrameworkProperties="true"
UndefineProperties="TargetFramework"
Private="false" />
</ItemGroup>

<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Directory.Build.targets))\Directory.Build.targets" />
Expand Down
Loading

0 comments on commit 43350b5

Please sign in to comment.