Skip to content

Commit

Permalink
[build] r8 now builds on both Windows & MacOS
Browse files Browse the repository at this point in the history
Context: http://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html

Overview of changes:
- Fixed tab characters, formatting, spacing
- To get `depot_tools`, we now just use the download on all
  platforms--not using a submodule anymore
- Use the `UnzipDirectoryChildren` task from `xa-prep-tasks`, so
  `r8.csproj` doesn't depend on `Xamarin.Android.Build.Tasks`
- `_BootstrapDepotTools` runs the `gclient` command, which *on first
  run* downloads all dependencies required for `depot_tools`, such as
  gradle. This was a hard requirement for Windows especially, since it
  downloads python.
- Use the `SetEnvironmentVariable` task to configure `PATH`.
  `depot_tools` has an odd requirement of being in `PATH`, but the
  `EnvironmentVariables` property on the `<Exec />` task was not
  sufficient. On Windows, the way `external\r8\tools\gradle.py`
  invokes `.bat` files in `depot_tools`--I could not get things to
  work unless doing it this way.
- Various targets for `depot_tools` use Inputs/Outputs so they aren't
  running every time.
- Removed `depot_tools.tpnitems` to `src`, since it is no longer a
  submodule and we don't redistribute it. Is that correct?
  • Loading branch information
jonathanpeppers committed Jul 31, 2018
1 parent 9bd0fe6 commit 3766aa7
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 56 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@
path = external/xamarin-android-tools
url = https://github.com/xamarin/xamarin-android-tools
branch = master
[submodule "external/depot_tools"]
path = external/depot_tools
url = https://chromium.googlesource.com/chromium/tools/depot_tools.git
[submodule "external/r8"]
path = external/r8
url = https://r8.googlesource.com/r8
Expand Down
1 change: 1 addition & 0 deletions Xamarin.Android.sln
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.Android.Tools.AndroidSdk-Tests", "external\xamarin-android-tools\src\Xamarin.Android.Tools.AndroidSdk\Tests\Xamarin.Android.Tools.AndroidSdk-Tests.csproj", "{1E5501E8-49C1-4659-838D-CC9720C5208F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "r8", "src\r8\r8.csproj", "{1BAFA0CC-0377-46CE-AB7B-7BB2E7B62F63}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "proprietary", "build-tools\proprietary\proprietary.csproj", "{D93CAC27-3893-42A3-99F1-2BCA72E186F4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "download-bundle", "build-tools\download-bundle\download-bundle.csproj", "{1DA0CB12-5508-4E83-A242-0C8D6D99A49B}"
Expand Down
1 change: 0 additions & 1 deletion external/depot_tools
Submodule depot_tools deleted from a16b4c
9 changes: 0 additions & 9 deletions external/depot_tools.tpnitems

This file was deleted.

126 changes: 83 additions & 43 deletions src/r8/r8.targets
Original file line number Diff line number Diff line change
@@ -1,76 +1,116 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<UsingTask TaskName="Xamarin.Android.Tasks.Unzip" AssemblyFile="Xamarin.Android.Build.Tasks.dll" />
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.DownloadUri" />
<UsingTask AssemblyFile="..\..\bin\Build$(Configuration)\xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.DownloadUri" />
<UsingTask AssemblyFile="..\..\bin\Build$(Configuration)\xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.SetEnvironmentVariable" />
<UsingTask AssemblyFile="..\..\bin\Build$(Configuration)\Xamarin.Android.Tools.BootstrapTasks.dll" TaskName="Xamarin.Android.Tools.BootstrapTasks.UnzipDirectoryChildren" />

<!-- public targets -->

<Target Name="Build" DependsOnTargets="_SetupDepotTools;_BuildR8;_CopyR8" />
<Target Name="Clean" DependsOnTargets="_CleanR8;_CleanDepotTools" />
<PropertyGroup>
<BuildDependsOn>
_DownloadDepotTools;
_UnzipDepotTools;
_SetDepotToolsEnvironment;
_BootstrapDepotTools;
_BuildR8;
_CopyR8;
</BuildDependsOn>
<CleanDependsOn>
_SetDepotToolsEnvironment;
_CleanR8;
_CleanDepotTools;
</CleanDependsOn>
</PropertyGroup>
<Target Name="Build" DependsOnTargets="$(BuildDependsOn)" />
<Target Name="Clean" DependsOnTargets="$(CleanDependsOn)" />

<!-- depot_tools -->
<!--
depot_tools, a set of git extensions from Chromium
http://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html
-->

<!-- Why do people split files and make build scripts unreadable? That's unacceptable. Therefore properties are here. Always consider code readability. -->
<PropertyGroup>
<_WindowsDepotToolzZipDownload>..\..\bin\Build$(Configuration)\depot_tools.zip</_WindowsDepotToolzZipDownload>
<_DepotToolsZip>..\..\bin\Build$(Configuration)\depot_tools.zip</_DepotToolsZip>
<_PathToDepotTools>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\depot_tools'))</_PathToDepotTools>
</PropertyGroup>

<Target Name="_SetupDepotTools" DependsOnTargets="_SetupDepotToolsWindows" />
<Target Name="_CleanDepotTools" DependsOnTargets="_CleanDepotToolsWindows" />

<Target Name="_SetupDepotToolsWindows" Condition="$(HostOS) == 'Windows'">
<Target Name="_DownloadDepotTools">
<DownloadUri
SourceUris="https://storage.googleapis.com/chrome-infra/depot_tools.zip"
DestinationFiles="$(_WindowsDepotToolzZipDownload)"
SourceUris="https://storage.googleapis.com/chrome-infra/depot_tools.zip"
DestinationFiles="$(_DepotToolsZip)"
/>
<Unzip
Sources="$(_WindowsDepotToolsZipDownload)"
Destination="bin\Build$(Configuration)\depot_tools"
/>
</Target>

<Target Name="_CleanDepotToolsWindows" Condition="$(HostOS) == 'Windows'">
<RemoveDir Directories="bin\Build$(Configuration)\depot_tools" />
<Target Name="_UnzipDepotTools"
Inputs="$(_DepotToolsZip)"
Outputs="$(_PathToDepotTools)\unzip.stamp">
<UnzipDirectoryChildren
HostOS="$(HostOS)"
NoSubdirectory="True"
SourceFiles="$(_DepotToolsZip)"
DestinationFolder="$(_PathToDepotTools)"
/>
<Touch
Files="$(_PathToDepotTools)\unzip.stamp"
AlwaysCreate="True"
/>
</Target>

<!--
NOTE: depot_tools has an odd requirement of being in PATH
I am also getting some odd failures on Windows, if not specifying namespace for <SetEnvironmentVariable />
-->

<!-- r8 -->
<Target Name="_SetDepotToolsEnvironment">
<Xamarin.Android.BuildTools.PrepTasks.SetEnvironmentVariable
Name="PATH"
Value="$(_PathToDepotTools)$(PathSeparator)$(PATH)"
/>
</Target>

<PropertyGroup>
<_PathToDepotTools Condition="'$(HostOS)' == 'Windows'">..\..\bin\Build$(Configuration)\depot_tools</_PathToDepotTools>
<_PathToDepotTools Condition="'$(HostOS)' != 'Windows'">..\..\external\depot_tools</_PathToDepotTools>
<_Sep Condition="'$(HostOS)' == 'Windows'">;</_Sep>
<_Sep Condition="'$(HostOS)' != 'Windows'">:</_Sep>
<_W Condition="'$(HostOS)' == 'Windows'">"</_W>
<_W Condition="'$(HostOS)' != 'Windows'"></_W> <_EnvForDepotTools>PATH=$(_W)$(_PathToDepotTools)$(_W)$(_Sep)$(PATH)</_EnvForDepotTools>
</PropertyGroup>
<!-- This "bootstraps" depot_tools, such as downloading/installing gradle and python -->

<Target Name="_BuildR8" DependsOnTargets="_SetupDepotTools">
<Exec
Command="..\..\external\r8\tools\gradle.py d8 r8"
WorkingDirectory="..\..\external\r8"
EnvironmentVariables="$(_EnvForDepotTools)"
/>
<Target Name="_BootstrapDepotTools"
Inputs="$(_PathToDepotTools)\unzip.stamp"
Outputs="$(_PathToDepotTools)\bootstrap.stamp">
<Exec Command="gclient --version" />
<Touch
Files="$(_PathToDepotTools)\bootstrap.stamp"
AlwaysCreate="True"
/>
</Target>

<Target Name="_CleanDepotTools">
<Delete Files="$(_DepotToolsZip)" />
<RemoveDir Directories="$(_PathToDepotTools)" />
</Target>

<!-- r8 -->

<Target Name="_BuildR8">
<Exec
Command="python tools\gradle.py d8 r8"
WorkingDirectory="..\..\external\r8"
/>
</Target>

<Target Name="_CopyR8">
<Copy
SourceFiles="..\..\external\r8\build\libs\d8.jar"
DestinationFolder="$(XAInstallPrefix)\xbuild\Xamarin\Android\"
SkipUnchangedFiles="true"
SourceFiles="..\..\external\r8\build\libs\d8.jar"
DestinationFolder="$(XAInstallPrefix)\xbuild\Xamarin\Android\"
SkipUnchangedFiles="true"
/>
<Copy
SourceFiles="..\..\external\r8\build\libs\r8.jar"
DestinationFolder="$(XAInstallPrefix)\xbuild\Xamarin\Android\"
SkipUnchangedFiles="true"
SourceFiles="..\..\external\r8\build\libs\r8.jar"
DestinationFolder="$(XAInstallPrefix)\xbuild\Xamarin\Android\"
SkipUnchangedFiles="true"
/>
</Target>

<Target Name="_CleanR8">
<Exec
Command="..\..\external\r8\tools\gradle.py clean"
WorkingDirectory="..\..\external\r8"
EnvironmentVariables="$(_EnvForDepotTools)"
Command="python tools\gradle.py clean"
WorkingDirectory="..\..\external\r8"
/>
</Target>

Expand Down

0 comments on commit 3766aa7

Please sign in to comment.