Skip to content

Commit

Permalink
Merged PR 515054: Enable solution builds from VS, VS Code, and 'dotne…
Browse files Browse the repository at this point in the history
…t' CLI on all platforms

With these changes, our routing code (Microsoft.Azure.Devices.Routing.Core) now handles the Antlr4 code-gen directly in the CSPROJ file. You don't need to run our buildBranch script first; you can build our codebase in the following ways:
- Visual Studio IDE on Windows
- Visual Studio for Mac
- VS Code on Windows/Linux/Mac
- `dotnet build .` on the command line in Windows/Linux/Mac

Of course you can still use buildBranch, but it's effectively just calling `dotnet build` against the solution file (it also does a publish).

NOTES:
- The new .vscode/tasks.json file enables Ctrl-Shift-B (or equivalent) from VS Code on any platform; I thought it was worth checking it in.
- VS builds on Windows still use IKVM so you don't have to install Java. Everything else expects java to be there.
  • Loading branch information
damonbarry committed Nov 13, 2017
1 parent 69edb19 commit 7c344bd
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ FakesAssemblies/
*.opt

.vs/
.vscode/
.vscode/launch.json

launchSettings.json
target/
Expand Down
19 changes: 19 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Microsoft.Azure.Devices.Edge.sln"
],
"problemMatcher": "$msCompile",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
Expand All @@ -23,7 +22,7 @@
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.7.0" />
</ItemGroup>

<ItemGroup Condition="'$(BuildingInsideVisualStudio)' == 'true'">
<ItemGroup Condition="'$(BuildingInsideVisualStudio)' == 'true' And '$(OS)' == 'Windows_NT'">
<Antlr4 Include="grammar\Condition.g4">
<Generator>MSBuild:Compile</Generator>
<CustomToolNamespace>Microsoft.Azure.Devices.Routing.Core.Query</CustomToolNamespace>
Expand Down Expand Up @@ -55,9 +54,30 @@
</ItemGroup>

<ItemGroup>
<Folder Include="grammar\generated\" />
<Antlr4Inputs Include="grammar\*.g4;query\jsonpath\*.g4" />
<Antlr4Outputs Include="grammar\generated\**\*.cs" />
<Antlr4Outputs Condition="'@(Antlr4Outputs)' == ''" Include="grammar\generated\dummy.cs" />
</ItemGroup>

<Target Name="Antlr4CodeGen" BeforeTargets="Antlr4Sources" Inputs="@(Antlr4Inputs)" Outputs="@(Antlr4Outputs)"
Condition="'$(BuildingInsideVisualStudio)' != 'true' Or '$(OS)' != 'Windows_NT'">
<PropertyGroup>
<FullAntlr4ToolLocation>$(NuGetPackageRoot)antlr4.codegenerator/4.6.1-beta002/tools/antlr4-csharp-4.6.1-SNAPSHOT-complete.jar</FullAntlr4ToolLocation>
</PropertyGroup>
<Exec Command="java -version" EchoOff="true" />
<MakeDir Directories="grammar\generated" />
<Exec Command="java -jar $(FullAntlr4ToolLocation) %(Antlr4Inputs.Identity) -package Microsoft.Azure.Devices.Routing.Core -Dlanguage=CSharp_v4_5 -visitor -listener -o grammar/generated" />
<CreateProperty Value="true">
<Output TaskParameter="ValueSetByTask" PropertyName="Antlr4CodeGenRan" />
</CreateProperty>
</Target>

<Target Name="Antlr4Sources" BeforeTargets="CoreCompile">
<ItemGroup Condition="'$(Antlr4CodeGenRan)' == 'true'">
<Compile Include="grammar\generated\**\*.cs" />
</ItemGroup>
</Target>

<ItemGroup>
<ProjectReference Include="..\..\..\edge-util\src\Microsoft.Azure.Devices.Edge.Util\Microsoft.Azure.Devices.Edge.Util.csproj" />
</ItemGroup>
Expand Down
10 changes: 0 additions & 10 deletions scripts/linux/buildBranch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ SLN_PATTERN='Microsoft.Azure.*.sln'
CSPROJ_PATTERN='*.csproj'
TEST_CSPROJ_PATTERN='*Test.csproj'
FUNCTION_BINDING_CSPROJ_PATTERN='*Binding.csproj'
ANTLR_PATTERN='*.g4'
ROOT_FOLDER=$BUILD_REPOSITORY_LOCALPATH
PUBLISH_FOLDER=$BUILD_BINARIESDIRECTORY/publish
RELEASE_TESTS_FOLDER=$BUILD_BINARIESDIRECTORY/release-tests
Expand Down Expand Up @@ -57,15 +56,6 @@ while read soln; do
$DOTNET_ROOT_PATH/dotnet restore $soln
done < <(find $ROOT_FOLDER -type f -name $SLN_PATTERN)

echo "Generating Antlr code files"

while read g4file; do
echo "Generating .cs files for - $g4file"
OUTPUT_DIR=$(dirname "$g4file")/generated
mkdir -p $OUTPUT_DIR
java -jar ~/.nuget/packages/antlr4.codegenerator/4.6.1-beta002/tools/antlr4-csharp-4.6.1-SNAPSHOT-complete.jar $g4file -package Microsoft.Azure.Devices.Routing.Core -Dlanguage=CSharp_v4_5 -visitor -listener -o $OUTPUT_DIR
done < <(find $ROOT_FOLDER -type f -name $ANTLR_PATTERN)

echo "Building all solutions in repo"
RES=0
while read soln; do
Expand Down
21 changes: 0 additions & 21 deletions scripts/windows/buildBranch.bat
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ if not defined CONFIGURATION (

set SLN_PATTERN=Microsoft.Azure.*.sln
set CSPROJ_PATTERN=*.csproj
set ANTLR_PATTERN=*.g4
set DOTNET_ROOT_PATH=%AGENT_WORKFOLDER%\dotnet
set PUBLISH_FOLDER=%BUILD_BINARIESDIRECTORY%\publish
set SRC_DOCKER_DIR=%BUILD_REPOSITORY_LOCALPATH%\docker
Expand Down Expand Up @@ -60,26 +59,6 @@ for /r %%f in (%SLN_PATTERN%) do (
if !ERRORLEVEL! neq 0 exit /b 1
)

echo.
echo Generating Antlr code files
echo.

set JAVA_COMMAND=java
where %JAVA_COMMAND% >nul 2>&1
if %ERRORLEVEL% neq 0 (
REM Fallback to using IKVM if Java isn't installed. Java is preferred for Antlr codegen
REM because it's a lot faster.
set "JAVA_COMMAND=%UserProfile%\.nuget\packages\Antlr4.CodeGenerator\4.6.1-beta002\tools\ikvm.exe"
)

for /r %%a in (%ANTLR_PATTERN%) do (
set GENERATED_PATH=%%~dpagenerated
echo Generating .cs files for - %%a
if not exist "!GENERATED_PATH!" mkdir "!GENERATED_PATH!"
"%JAVA_COMMAND%" -jar "%UserProfile%/.nuget/packages/Antlr4.CodeGenerator/4.6.1-beta002/tools/antlr4-csharp-4.6.1-SNAPSHOT-complete.jar" %%a -package Microsoft.Azure.Devices.Routing.Core -Dlanguage=CSharp_v4_5 -visitor -listener -o "!GENERATED_PATH!"
if !ERRORLEVEL! neq 0 exit /b 1
)

echo.
echo Building all solutions in repo
echo.
Expand Down

0 comments on commit 7c344bd

Please sign in to comment.