Skip to content

Commit

Permalink
reenable workloads and add test for verification
Browse files Browse the repository at this point in the history
  • Loading branch information
baronfel committed Apr 16, 2022
1 parent f17dcc5 commit cf51545
Show file tree
Hide file tree
Showing 28 changed files with 141 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": "0.2.0",
"configurations": [
{
"name": "Launch Tool 5.0 graph resolver",
"name": "Launch Tool 6.0 graph resolver",
"type": "coreclr",
"request": "launch",
"program": "${workspaceFolder}/src/Ionide.ProjInfo.Tool/bin/Debug/net6.0/Ionide.ProjInfo.Tool.dll",
Expand All @@ -20,7 +20,7 @@
"justMyCode": true,
},
{
"name": "Launch Tool 5.0 normal resolver",
"name": "Launch Tool 6.0 normal resolver",
"type": "coreclr",
"request": "launch",
"program": "${workspaceFolder}/src/Ionide.ProjInfo.Tool/bin/Debug/net6.0/Ionide.ProjInfo.Tool.dll",
Expand Down
2 changes: 1 addition & 1 deletion src/Ionide.ProjInfo.Tool/Ionide.ProjInfo.Tool.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFramework>net6.0</TargetFramework>
<PackAsTool>true</PackAsTool>
<ToolCommandName>proj-info</ToolCommandName>
</PropertyGroup>
Expand Down
12 changes: 6 additions & 6 deletions src/Ionide.ProjInfo/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ module Init =
Environment.SetEnvironmentVariable("MSBUILD_EXE_PATH", msbuild)
Environment.SetEnvironmentVariable("MSBuildExtensionsPath", ensureTrailer sdkRoot.FullName)
Environment.SetEnvironmentVariable("MSBuildSDKsPath", Path.Combine(sdkRoot.FullName, "Sdks"))
// .net 6 sdk includes workload stuff and this breaks for some reason
Environment.SetEnvironmentVariable("MSBuildEnableWorkloadResolver", "false")

match System.Environment.GetEnvironmentVariable "DOTNET_HOST_PATH" with
| null
Expand Down Expand Up @@ -791,8 +789,10 @@ type WorkspaceLoaderViaProjectGraph private (toolsPath, ?globalProperties: (stri
let buildProjs =
result.ResultsByNode.Keys
|> Seq.collect (fun (pgn: ProjectGraphNode) ->
seq { yield pgn.ProjectInstance
yield! Seq.map (fun (pr:ProjectGraphNode) -> pr.ProjectInstance) pgn.ProjectReferences })
seq {
yield pgn.ProjectInstance
yield! Seq.map (fun (pr: ProjectGraphNode) -> pr.ProjectInstance) pgn.ProjectReferences
})
|> Seq.toList

logger.info (
Expand All @@ -805,8 +805,8 @@ type WorkspaceLoaderViaProjectGraph private (toolsPath, ?globalProperties: (stri

let projects =
buildProjs
|> List.distinctBy (fun (p:ProjectInstance) -> p.FullPath)
|> Seq.map (fun (p:ProjectInstance) ->
|> List.distinctBy (fun (p: ProjectInstance) -> p.FullPath)
|> Seq.map (fun (p: ProjectInstance) ->

p.FullPath, ProjectLoader.getLoadedProjectInfo p.FullPath customProperties (ProjectLoader.LoadedProject p))

Expand Down
17 changes: 16 additions & 1 deletion test/Ionide.ProjInfo.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,9 +1158,23 @@ let debugTests toolsPath workspaceLoader (workspaceFactory: ToolsPath -> IWorksp
let parsed = loader.LoadProjects [ projPath ] |> Seq.toList

printfn "%A" parsed

)

let expensiveTests toolsPath (workspaceFactory: ToolsPath -> IWorkspaceLoader) =
ptest "can load project that uses workloads" {
// this one requires a lot of setup that I didn't want to check in because it's huge.
// before you can run this test you need to have
// * installed the android workload: `dotnet workload install android`
// * installed the android sdk. This seems to mostly be done from VS or Android Studio
// then you can actually crack this project
let projPath = Path.Combine(__SOURCE_DIRECTORY__, "..", "examples", "sample-workload", "sample-workload.csproj")
let loader = workspaceFactory toolsPath
let parsed = loader.LoadProjects [ projPath ] |> Seq.toList
let projInfo = parsed[0]
let references = projInfo.OtherOptions |> Seq.filter (fun opt -> opt.StartsWith "-r:")
Expect.exists references (fun r -> r.Contains "packs" && r.Contains "Microsoft.Android.") "Should have found a reference to android dlls in the packs directory"
}

let testProjectLoadBadData =
testCase |> withLog "Does not crash when loading malformed cache data" (fun logger fs ->
let testDir = inDir fs "sample_netsdk_bad_cache"
Expand Down Expand Up @@ -1270,4 +1284,5 @@ let tests toolsPath =
testLegacyFrameworkProject toolsPath "can load legacy project file" false (fun (tools, props) -> WorkspaceLoader.Create(tools, globalProperties = props))
testLegacyFrameworkMultiProject toolsPath "can load legacy multi project file" false (fun (tools, props) -> WorkspaceLoader.Create(tools, globalProperties = props))
testProjectLoadBadData
expensiveTests toolsPath WorkspaceLoader.Create
]
5 changes: 5 additions & 0 deletions test/examples/sample-workload/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true">
</application>
</manifest>
14 changes: 14 additions & 0 deletions test/examples/sample-workload/MainActivity.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace sample_workload

open Android.App
open Android.Content
open Android.OS
open Xamarin.Android

[<Activity(Label = "@string/app_name", MainLauncher = true)>]
type MainActivity() =
inherit Activity()

override x.OnCreate(savedInstanceState: Bundle) =
``base``.OnCreate(savedInstanceState)
``base``.SetContentView(Resource.Layout.activity_main)
44 changes: 44 additions & 0 deletions test/examples/sample-workload/Resources/AboutResources.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Images, layout descriptions, binary blobs and string dictionaries can be included
in your application as resource files. Various Android APIs are designed to
operate on the resource IDs instead of dealing with images, strings or binary blobs
directly.

For example, a sample Android app that contains a user interface layout (main.xml),
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
would keep its resources in the "Resources" directory of the application:

Resources/
drawable/
icon.png

layout/
main.xml

values/
strings.xml

In order to get the build system to recognize Android resources, set the build action to
"AndroidResource". The native Android APIs do not operate directly with filenames, but
instead operate on resource IDs. When you compile an Android application that uses resources,
the build system will package the resources for distribution and generate a class called "Resource"
(this is an Android convention) that contains the tokens for each one of the resources
included. For example, for the above Resources layout, this is what the Resource class would expose:

public class Resource {
public class Drawable {
public const int icon = 0x123;
}

public class Layout {
public const int main = 0x456;
}

public class Strings {
public const int first_string = 0xabc;
public const int second_string = 0xbcd;
}
}

You would then use Resource.Drawable.icon to reference the drawable/icon.png file, or
Resource.Layout.main to reference the layout/main.xml file, or Resource.Strings.first_string
to reference the first string in the dictionary file values/strings.xml.
13 changes: 13 additions & 0 deletions test/examples/sample-workload/Resources/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/app_text" />
</RelativeLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#2C3E50</color>
</resources>
4 changes: 4 additions & 0 deletions test/examples/sample-workload/Resources/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="app_name">sample_workload</string>
<string name="app_text">Hello, Android!</string>
</resources>
22 changes: 22 additions & 0 deletions test/examples/sample-workload/sample-workload.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-android</TargetFramework>
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
<RootNamespace>sample_workload</RootNamespace>
<OutputType>Exe</OutputType>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<ApplicationId>com.companyname.sample_workload</ApplicationId>
<ApplicationVersion>1</ApplicationVersion>
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
</PropertyGroup>

<ItemGroup>
<Compile Include="MainActivity.fs" />
<PackageReference
Include="FSharp.Android.Resource"
Version="1.0.1" />
</ItemGroup>

</Project>

0 comments on commit cf51545

Please sign in to comment.