Skip to content

Commit ce3817e

Browse files
authored
reenable workloads and add test for verification (#152)
1 parent f17dcc5 commit ce3817e

28 files changed

+141
-10
lines changed

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"version": "0.2.0",
66
"configurations": [
77
{
8-
"name": "Launch Tool 5.0 graph resolver",
8+
"name": "Launch Tool 6.0 graph resolver",
99
"type": "coreclr",
1010
"request": "launch",
1111
"program": "${workspaceFolder}/src/Ionide.ProjInfo.Tool/bin/Debug/net6.0/Ionide.ProjInfo.Tool.dll",
@@ -20,7 +20,7 @@
2020
"justMyCode": true,
2121
},
2222
{
23-
"name": "Launch Tool 5.0 normal resolver",
23+
"name": "Launch Tool 6.0 normal resolver",
2424
"type": "coreclr",
2525
"request": "launch",
2626
"program": "${workspaceFolder}/src/Ionide.ProjInfo.Tool/bin/Debug/net6.0/Ionide.ProjInfo.Tool.dll",

src/Ionide.ProjInfo.Tool/Ionide.ProjInfo.Tool.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>net6.0</TargetFrameworks>
5+
<TargetFramework>net6.0</TargetFramework>
66
<PackAsTool>true</PackAsTool>
77
<ToolCommandName>proj-info</ToolCommandName>
88
</PropertyGroup>

src/Ionide.ProjInfo/Library.fs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ module Init =
211211
Environment.SetEnvironmentVariable("MSBUILD_EXE_PATH", msbuild)
212212
Environment.SetEnvironmentVariable("MSBuildExtensionsPath", ensureTrailer sdkRoot.FullName)
213213
Environment.SetEnvironmentVariable("MSBuildSDKsPath", Path.Combine(sdkRoot.FullName, "Sdks"))
214-
// .net 6 sdk includes workload stuff and this breaks for some reason
215-
Environment.SetEnvironmentVariable("MSBuildEnableWorkloadResolver", "false")
216214

217215
match System.Environment.GetEnvironmentVariable "DOTNET_HOST_PATH" with
218216
| null
@@ -791,8 +789,10 @@ type WorkspaceLoaderViaProjectGraph private (toolsPath, ?globalProperties: (stri
791789
let buildProjs =
792790
result.ResultsByNode.Keys
793791
|> Seq.collect (fun (pgn: ProjectGraphNode) ->
794-
seq { yield pgn.ProjectInstance
795-
yield! Seq.map (fun (pr:ProjectGraphNode) -> pr.ProjectInstance) pgn.ProjectReferences })
792+
seq {
793+
yield pgn.ProjectInstance
794+
yield! Seq.map (fun (pr: ProjectGraphNode) -> pr.ProjectInstance) pgn.ProjectReferences
795+
})
796796
|> Seq.toList
797797

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

806806
let projects =
807807
buildProjs
808-
|> List.distinctBy (fun (p:ProjectInstance) -> p.FullPath)
809-
|> Seq.map (fun (p:ProjectInstance) ->
808+
|> List.distinctBy (fun (p: ProjectInstance) -> p.FullPath)
809+
|> Seq.map (fun (p: ProjectInstance) ->
810810

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

test/Ionide.ProjInfo.Tests/Tests.fs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,9 +1158,23 @@ let debugTests toolsPath workspaceLoader (workspaceFactory: ToolsPath -> IWorksp
11581158
let parsed = loader.LoadProjects [ projPath ] |> Seq.toList
11591159

11601160
printfn "%A" parsed
1161-
11621161
)
11631162

1163+
let expensiveTests toolsPath (workspaceFactory: ToolsPath -> IWorkspaceLoader) =
1164+
ptest "can load project that uses workloads" {
1165+
// this one requires a lot of setup that I didn't want to check in because it's huge.
1166+
// before you can run this test you need to have
1167+
// * installed the android workload: `dotnet workload install android`
1168+
// * installed the android sdk. This seems to mostly be done from VS or Android Studio
1169+
// then you can actually crack this project
1170+
let projPath = Path.Combine(__SOURCE_DIRECTORY__, "..", "examples", "sample-workload", "sample-workload.csproj")
1171+
let loader = workspaceFactory toolsPath
1172+
let parsed = loader.LoadProjects [ projPath ] |> Seq.toList
1173+
let projInfo = parsed[0]
1174+
let references = projInfo.OtherOptions |> Seq.filter (fun opt -> opt.StartsWith "-r:")
1175+
Expect.exists references (fun r -> r.Contains "packs" && r.Contains "Microsoft.Android.") "Should have found a reference to android dlls in the packs directory"
1176+
}
1177+
11641178
let testProjectLoadBadData =
11651179
testCase |> withLog "Does not crash when loading malformed cache data" (fun logger fs ->
11661180
let testDir = inDir fs "sample_netsdk_bad_cache"
@@ -1270,4 +1284,5 @@ let tests toolsPath =
12701284
testLegacyFrameworkProject toolsPath "can load legacy project file" false (fun (tools, props) -> WorkspaceLoader.Create(tools, globalProperties = props))
12711285
testLegacyFrameworkMultiProject toolsPath "can load legacy multi project file" false (fun (tools, props) -> WorkspaceLoader.Create(tools, globalProperties = props))
12721286
testProjectLoadBadData
1287+
expensiveTests toolsPath WorkspaceLoader.Create
12731288
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true">
4+
</application>
5+
</manifest>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace sample_workload
2+
3+
open Android.App
4+
open Android.Content
5+
open Android.OS
6+
open Xamarin.Android
7+
8+
[<Activity(Label = "@string/app_name", MainLauncher = true)>]
9+
type MainActivity() =
10+
inherit Activity()
11+
12+
override x.OnCreate(savedInstanceState: Bundle) =
13+
``base``.OnCreate(savedInstanceState)
14+
``base``.SetContentView(Resource.Layout.activity_main)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Images, layout descriptions, binary blobs and string dictionaries can be included
2+
in your application as resource files. Various Android APIs are designed to
3+
operate on the resource IDs instead of dealing with images, strings or binary blobs
4+
directly.
5+
6+
For example, a sample Android app that contains a user interface layout (main.xml),
7+
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
8+
would keep its resources in the "Resources" directory of the application:
9+
10+
Resources/
11+
drawable/
12+
icon.png
13+
14+
layout/
15+
main.xml
16+
17+
values/
18+
strings.xml
19+
20+
In order to get the build system to recognize Android resources, set the build action to
21+
"AndroidResource". The native Android APIs do not operate directly with filenames, but
22+
instead operate on resource IDs. When you compile an Android application that uses resources,
23+
the build system will package the resources for distribution and generate a class called "Resource"
24+
(this is an Android convention) that contains the tokens for each one of the resources
25+
included. For example, for the above Resources layout, this is what the Resource class would expose:
26+
27+
public class Resource {
28+
public class Drawable {
29+
public const int icon = 0x123;
30+
}
31+
32+
public class Layout {
33+
public const int main = 0x456;
34+
}
35+
36+
public class Strings {
37+
public const int first_string = 0xabc;
38+
public const int second_string = 0xbcd;
39+
}
40+
}
41+
42+
You would then use Resource.Drawable.icon to reference the drawable/icon.png file, or
43+
Resource.Layout.main to reference the layout/main.xml file, or Resource.Strings.first_string
44+
to reference the first string in the dictionary file values/strings.xml.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
xmlns:tools="http://schemas.android.com/tools"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent">
8+
<TextView
9+
android:layout_width="wrap_content"
10+
android:layout_height="wrap_content"
11+
android:layout_centerInParent="true"
12+
android:text="@string/app_text" />
13+
</RelativeLayout>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
3+
<background android:drawable="@color/ic_launcher_background"/>
4+
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
5+
</adaptive-icon>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
3+
<background android:drawable="@color/ic_launcher_background"/>
4+
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
5+
</adaptive-icon>

0 commit comments

Comments
 (0)