Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Conversation

@wli3
Copy link

@wli3 wli3 commented Apr 4, 2018

This is the most tricky part of consume bring your own shim. CLI will need to select the most fit RID given the shims folder layout in nupkg. This function is to pick that.

Say there is folder win10-x64, win-x64, win, linux, CLI need to pick the right shim folder to use according to machine RID (say it is windows 10 x64). And this function take these rids as input and return win10-x64.

@wli3 wli3 requested a review from a team April 4, 2018 22:37
@nguerrera
Copy link
Contributor

@ericstj

@nguerrera
Copy link
Contributor

@eerhardt


if (supportedRuntimeIdentifiers.Any())
{
mostFitRuntimeIdentifier = supportedRuntimeIdentifiers.Where(r => IsAllOtherNodeOnPathToRoot(r, supportedRuntimeIdentifiers)).First();

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

}
}

private bool IsAllOtherNodeOnPathToRoot(string targetRuntimeIdentifierNode, IEnumerable<string> otherRuntimeIdentifierNodes)

This comment was marked as spam.

@nguerrera
Copy link
Contributor

nguerrera commented Apr 4, 2018

I'm having trouble understanding the code. Maybe because I don't understand the underlying API, or the terminology, or the problem. ;)

My first naive guess at how this should look is (pseudo code)

GetNearestRid(inputRid, candidateRids):
  if candidateRids contain inputRid: 
    return inputRid

  for each fallback of inputRid:
    if candidateRids contain fallback:
      return fallback

  return noMatch

Note: this can be O(N + M) where N is number of candidates and M is number of fallbacks from input.

Construct HashSet of candidates in O(N), enumerate fallbacks in O(M).

@wli3
Copy link
Author

wli3 commented Apr 4, 2018

@nguerrera i think this code is more about correctness. most of the case we will have only 3 RID (win-x64, win-x84, osx, all we have to sign). Worst case, the tree height of the full rid graph is about 6, big o notation won't apply here (it assumes it will scale to a big number which we dont'). I use HashSet because I want to say IsSuperSet. Or I have to do the "IsSuperSet" by myself, which I am not sure is easier to understand. This code is one off during dotnet tool install, so it is not on a hot path.

The pseudo code might work, but that requires order of "fallback". @eerhardt do fallback field of DependencyModel promise order? I am not sure from reading the code

@nguerrera
Copy link
Contributor

nguerrera commented Apr 4, 2018

I wasn't arguing this over what you have for perf, I just feel that it's always prudent to state the complexity when writing down an algorithm.

@nguerrera
Copy link
Contributor

nguerrera commented Apr 4, 2018

If the fallbacks are unordered, then "fallback" is a bad name. To my intuition, the pseudo code follows from directly from the name: try something then fall back to the next thing.

@nguerrera
Copy link
Contributor

nguerrera commented Apr 4, 2018

All of the test cases have the fallbacks ordered from most specific to least specific:

https://github.com/dotnet/core-setup/blob/6887ab556bc8302390782711dcdd75b75e769cf5/src/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextTests.cs#L130-L137

I'll wait for @eerhardt to confirm that we can assume this order, but if we can, then let's please do so. The code will be much easier to understand.

@wli3
Copy link
Author

wli3 commented Apr 4, 2018

@nguerrera agree, and due to it is not a tree, what i have won't work

@wli3 wli3 closed this Apr 4, 2018
@wli3 wli3 reopened this Apr 4, 2018
@wli3 wli3 changed the title WIP Add TryGetMostFitRuntimeIdentifier WIP [just for discussion won't work] Add TryGetMostFitRuntimeIdentifier Apr 4, 2018
@wli3
Copy link
Author

wli3 commented Apr 5, 2018

I printed by json of Windows DependencyContext.RuntimeGraph object It looks like having a reasonable order

Windows DependencyContext.RuntimeGraph object click to expand

[
  {
      "Runtime": "win-arm",
      "Fallbacks": [
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win-arm64",
      "Fallbacks": [
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win-x64",
      "Fallbacks": [
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win-x86",
      "Fallbacks": [
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win",
      "Fallbacks": [
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win-aot",
      "Fallbacks": [
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win-arm-aot",
      "Fallbacks": [
          "win-aot",
          "win-arm",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win-arm-corert",
      "Fallbacks": [
          "win-corert",
          "win-arm",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win-arm64-aot",
      "Fallbacks": [
          "win-aot",
          "win-arm64",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win-arm64-corert",
      "Fallbacks": [
          "win-corert",
          "win-arm64",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win-corert",
      "Fallbacks": [
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win-x64-aot",
      "Fallbacks": [
          "win-aot",
          "win-x64",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win-x64-corert",
      "Fallbacks": [
          "win-corert",
          "win-x64",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win-x86-aot",
      "Fallbacks": [
          "win-aot",
          "win-x86",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win-x86-corert",
      "Fallbacks": [
          "win-corert",
          "win-x86",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win10",
      "Fallbacks": [
          "win81",
          "win8",
          "win7",
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win10-aot",
      "Fallbacks": [
          "win10",
          "win81-aot",
          "win81",
          "win8-aot",
          "win8",
          "win7-aot",
          "win7",
          "win-aot",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win10-arm",
      "Fallbacks": [
          "win10",
          "win81-arm",
          "win81",
          "win8-arm",
          "win8",
          "win7-arm",
          "win7",
          "win-arm",
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win10-arm-aot",
      "Fallbacks": [
          "win10-aot",
          "win10-arm",
          "win10",
          "win81-arm-aot",
          "win81-aot",
          "win81-arm",
          "win81",
          "win8-arm-aot",
          "win8-aot",
          "win8-arm",
          "win8",
          "win7-arm-aot",
          "win7-aot",
          "win7-arm",
          "win7",
          "win-arm-aot",
          "win-aot",
          "win-arm",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win10-arm-corert",
      "Fallbacks": [
          "win10-corert",
          "win10-arm",
          "win10",
          "win81-arm-corert",
          "win81-corert",
          "win81-arm",
          "win81",
          "win8-arm-corert",
          "win8-corert",
          "win8-arm",
          "win8",
          "win7-arm-corert",
          "win7-corert",
          "win7-arm",
          "win7",
          "win-arm-corert",
          "win-corert",
          "win-arm",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win10-arm64",
      "Fallbacks": [
          "win10",
          "win81-arm64",
          "win81",
          "win8-arm64",
          "win8",
          "win7-arm64",
          "win7",
          "win-arm64",
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win10-arm64-aot",
      "Fallbacks": [
          "win10-aot",
          "win10-arm64",
          "win10",
          "win81-arm64-aot",
          "win81-aot",
          "win81-arm64",
          "win81",
          "win8-arm64-aot",
          "win8-aot",
          "win8-arm64",
          "win8",
          "win7-arm64-aot",
          "win7-aot",
          "win7-arm64",
          "win7",
          "win-arm64-aot",
          "win-aot",
          "win-arm64",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win10-arm64-corert",
      "Fallbacks": [
          "win10-corert",
          "win10-arm64",
          "win10",
          "win81-arm64-corert",
          "win81-corert",
          "win81-arm64",
          "win81",
          "win8-arm64-corert",
          "win8-corert",
          "win8-arm64",
          "win8",
          "win7-arm64-corert",
          "win7-corert",
          "win7-arm64",
          "win7",
          "win-arm64-corert",
          "win-corert",
          "win-arm64",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win10-corert",
      "Fallbacks": [
          "win10",
          "win81-corert",
          "win81",
          "win8-corert",
          "win8",
          "win7-corert",
          "win7",
          "win-corert",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win10-x64",
      "Fallbacks": [
          "win10",
          "win81-x64",
          "win81",
          "win8-x64",
          "win8",
          "win7-x64",
          "win7",
          "win-x64",
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win10-x64-aot",
      "Fallbacks": [
          "win10-aot",
          "win10-x64",
          "win10",
          "win81-x64-aot",
          "win81-aot",
          "win81-x64",
          "win81",
          "win8-x64-aot",
          "win8-aot",
          "win8-x64",
          "win8",
          "win7-x64-aot",
          "win7-aot",
          "win7-x64",
          "win7",
          "win-x64-aot",
          "win-aot",
          "win-x64",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win10-x64-corert",
      "Fallbacks": [
          "win10-corert",
          "win10-x64",
          "win10",
          "win81-x64-corert",
          "win81-corert",
          "win81-x64",
          "win81",
          "win8-x64-corert",
          "win8-corert",
          "win8-x64",
          "win8",
          "win7-x64-corert",
          "win7-corert",
          "win7-x64",
          "win7",
          "win-x64-corert",
          "win-corert",
          "win-x64",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win10-x86",
      "Fallbacks": [
          "win10",
          "win81-x86",
          "win81",
          "win8-x86",
          "win8",
          "win7-x86",
          "win7",
          "win-x86",
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win10-x86-aot",
      "Fallbacks": [
          "win10-aot",
          "win10-x86",
          "win10",
          "win81-x86-aot",
          "win81-aot",
          "win81-x86",
          "win81",
          "win8-x86-aot",
          "win8-aot",
          "win8-x86",
          "win8",
          "win7-x86-aot",
          "win7-aot",
          "win7-x86",
          "win7",
          "win-x86-aot",
          "win-aot",
          "win-x86",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win10-x86-corert",
      "Fallbacks": [
          "win10-corert",
          "win10-x86",
          "win10",
          "win81-x86-corert",
          "win81-corert",
          "win81-x86",
          "win81",
          "win8-x86-corert",
          "win8-corert",
          "win8-x86",
          "win8",
          "win7-x86-corert",
          "win7-corert",
          "win7-x86",
          "win7",
          "win-x86-corert",
          "win-corert",
          "win-x86",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win7",
      "Fallbacks": [
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win7-aot",
      "Fallbacks": [
          "win7",
          "win-aot",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win7-arm",
      "Fallbacks": [
          "win7",
          "win-arm",
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win7-arm-aot",
      "Fallbacks": [
          "win7-aot",
          "win7-arm",
          "win7",
          "win-arm-aot",
          "win-aot",
          "win-arm",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win7-arm-corert",
      "Fallbacks": [
          "win7-corert",
          "win7-arm",
          "win7",
          "win-arm-corert",
          "win-corert",
          "win-arm",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win7-arm64",
      "Fallbacks": [
          "win7",
          "win-arm64",
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win7-arm64-aot",
      "Fallbacks": [
          "win7-aot",
          "win7-arm64",
          "win7",
          "win-arm64-aot",
          "win-aot",
          "win-arm64",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win7-arm64-corert",
      "Fallbacks": [
          "win7-corert",
          "win7-arm64",
          "win7",
          "win-arm64-corert",
          "win-corert",
          "win-arm64",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win7-corert",
      "Fallbacks": [
          "win7",
          "win-corert",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win7-x64",
      "Fallbacks": [
          "win7",
          "win-x64",
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win7-x64-aot",
      "Fallbacks": [
          "win7-aot",
          "win7-x64",
          "win7",
          "win-x64-aot",
          "win-aot",
          "win-x64",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win7-x64-corert",
      "Fallbacks": [
          "win7-corert",
          "win7-x64",
          "win7",
          "win-x64-corert",
          "win-corert",
          "win-x64",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win7-x86",
      "Fallbacks": [
          "win7",
          "win-x86",
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win7-x86-aot",
      "Fallbacks": [
          "win7-aot",
          "win7-x86",
          "win7",
          "win-x86-aot",
          "win-aot",
          "win-x86",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win7-x86-corert",
      "Fallbacks": [
          "win7-corert",
          "win7-x86",
          "win7",
          "win-x86-corert",
          "win-corert",
          "win-x86",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win8",
      "Fallbacks": [
          "win7",
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win8-aot",
      "Fallbacks": [
          "win8",
          "win7-aot",
          "win7",
          "win-aot",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win8-arm",
      "Fallbacks": [
          "win8",
          "win7-arm",
          "win7",
          "win-arm",
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win8-arm-aot",
      "Fallbacks": [
          "win8-aot",
          "win8-arm",
          "win8",
          "win7-arm-aot",
          "win7-aot",
          "win7-arm",
          "win7",
          "win-arm-aot",
          "win-aot",
          "win-arm",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win8-arm-corert",
      "Fallbacks": [
          "win8-corert",
          "win8-arm",
          "win8",
          "win7-arm-corert",
          "win7-corert",
          "win7-arm",
          "win7",
          "win-arm-corert",
          "win-corert",
          "win-arm",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win8-arm64",
      "Fallbacks": [
          "win8",
          "win7-arm64",
          "win7",
          "win-arm64",
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win8-arm64-aot",
      "Fallbacks": [
          "win8-aot",
          "win8-arm64",
          "win8",
          "win7-arm64-aot",
          "win7-aot",
          "win7-arm64",
          "win7",
          "win-arm64-aot",
          "win-aot",
          "win-arm64",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win8-arm64-corert",
      "Fallbacks": [
          "win8-corert",
          "win8-arm64",
          "win8",
          "win7-arm64-corert",
          "win7-corert",
          "win7-arm64",
          "win7",
          "win-arm64-corert",
          "win-corert",
          "win-arm64",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win8-corert",
      "Fallbacks": [
          "win8",
          "win7-corert",
          "win7",
          "win-corert",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win8-x64",
      "Fallbacks": [
          "win8",
          "win7-x64",
          "win7",
          "win-x64",
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win8-x64-aot",
      "Fallbacks": [
          "win8-aot",
          "win8-x64",
          "win8",
          "win7-x64-aot",
          "win7-aot",
          "win7-x64",
          "win7",
          "win-x64-aot",
          "win-aot",
          "win-x64",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win8-x64-corert",
      "Fallbacks": [
          "win8-corert",
          "win8-x64",
          "win8",
          "win7-x64-corert",
          "win7-corert",
          "win7-x64",
          "win7",
          "win-x64-corert",
          "win-corert",
          "win-x64",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win8-x86",
      "Fallbacks": [
          "win8",
          "win7-x86",
          "win7",
          "win-x86",
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win8-x86-aot",
      "Fallbacks": [
          "win8-aot",
          "win8-x86",
          "win8",
          "win7-x86-aot",
          "win7-aot",
          "win7-x86",
          "win7",
          "win-x86-aot",
          "win-aot",
          "win-x86",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win8-x86-corert",
      "Fallbacks": [
          "win8-corert",
          "win8-x86",
          "win8",
          "win7-x86-corert",
          "win7-corert",
          "win7-x86",
          "win7",
          "win-x86-corert",
          "win-corert",
          "win-x86",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win81",
      "Fallbacks": [
          "win8",
          "win7",
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win81-aot",
      "Fallbacks": [
          "win81",
          "win8-aot",
          "win8",
          "win7-aot",
          "win7",
          "win-aot",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win81-arm",
      "Fallbacks": [
          "win81",
          "win8-arm",
          "win8",
          "win7-arm",
          "win7",
          "win-arm",
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win81-arm-aot",
      "Fallbacks": [
          "win81-aot",
          "win81-arm",
          "win81",
          "win8-arm-aot",
          "win8-aot",
          "win8-arm",
          "win8",
          "win7-arm-aot",
          "win7-aot",
          "win7-arm",
          "win7",
          "win-arm-aot",
          "win-aot",
          "win-arm",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win81-arm-corert",
      "Fallbacks": [
          "win81-corert",
          "win81-arm",
          "win81",
          "win8-arm-corert",
          "win8-corert",
          "win8-arm",
          "win8",
          "win7-arm-corert",
          "win7-corert",
          "win7-arm",
          "win7",
          "win-arm-corert",
          "win-corert",
          "win-arm",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win81-arm64",
      "Fallbacks": [
          "win81",
          "win8-arm64",
          "win8",
          "win7-arm64",
          "win7",
          "win-arm64",
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win81-arm64-aot",
      "Fallbacks": [
          "win81-aot",
          "win81-arm64",
          "win81",
          "win8-arm64-aot",
          "win8-aot",
          "win8-arm64",
          "win8",
          "win7-arm64-aot",
          "win7-aot",
          "win7-arm64",
          "win7",
          "win-arm64-aot",
          "win-aot",
          "win-arm64",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win81-arm64-corert",
      "Fallbacks": [
          "win81-corert",
          "win81-arm64",
          "win81",
          "win8-arm64-corert",
          "win8-corert",
          "win8-arm64",
          "win8",
          "win7-arm64-corert",
          "win7-corert",
          "win7-arm64",
          "win7",
          "win-arm64-corert",
          "win-corert",
          "win-arm64",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win81-corert",
      "Fallbacks": [
          "win81",
          "win8-corert",
          "win8",
          "win7-corert",
          "win7",
          "win-corert",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win81-x64",
      "Fallbacks": [
          "win81",
          "win8-x64",
          "win8",
          "win7-x64",
          "win7",
          "win-x64",
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win81-x64-aot",
      "Fallbacks": [
          "win81-aot",
          "win81-x64",
          "win81",
          "win8-x64-aot",
          "win8-aot",
          "win8-x64",
          "win8",
          "win7-x64-aot",
          "win7-aot",
          "win7-x64",
          "win7",
          "win-x64-aot",
          "win-aot",
          "win-x64",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win81-x64-corert",
      "Fallbacks": [
          "win81-corert",
          "win81-x64",
          "win81",
          "win8-x64-corert",
          "win8-corert",
          "win8-x64",
          "win8",
          "win7-x64-corert",
          "win7-corert",
          "win7-x64",
          "win7",
          "win-x64-corert",
          "win-corert",
          "win-x64",
          "win",
          "corert",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win81-x86",
      "Fallbacks": [
          "win81",
          "win8-x86",
          "win8",
          "win7-x86",
          "win7",
          "win-x86",
          "win",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win81-x86-aot",
      "Fallbacks": [
          "win81-aot",
          "win81-x86",
          "win81",
          "win8-x86-aot",
          "win8-aot",
          "win8-x86",
          "win8",
          "win7-x86-aot",
          "win7-aot",
          "win7-x86",
          "win7",
          "win-x86-aot",
          "win-aot",
          "win-x86",
          "win",
          "aot",
          "any",
          "base"
      ]
  },
  {
      "Runtime": "win81-x86-corert",
      "Fallbacks": [
          "win81-corert",
          "win81-x86",
          "win81",
          "win8-x86-corert",
          "win8-corert",
          "win8-x86",
          "win8",
          "win7-x86-corert",
          "win7-corert",
          "win7-x86",
          "win7",
          "win-x86-corert",
          "win-corert",
          "win-x86",
          "win",
          "corert",
          "any",
          "base"
      ]
  }
]
</p>
</details>

@wli3 wli3 changed the title WIP [just for discussion won't work] Add TryGetMostFitRuntimeIdentifier WIP Add TryGetMostFitRuntimeIdentifier Apr 5, 2018
@wli3
Copy link
Author

wli3 commented Apr 5, 2018

Rewrite to what Nick suggested

@eerhardt
Copy link
Member

eerhardt commented Apr 5, 2018

The "runtime" section of the .deps.json file is rather simple (which is why it is so bloated). It is simple because it removes the host from having to contain any "graph" logic at all. (Should it be depth-first vs. breadth-first? etc)

The graph simply says, given a RID, here is the ordered list of fallback RIDs to use.

    "win10-x64": [
      "win10",
      "win81-x64",
      "win81",
      "win8-x64",
      "win8",
      "win7-x64",
      "win7",
      "win-x64",
      "win",
      "any",
      "base"
    ],

So, given win10-x64, if you can't find the asset using that RID, check win10, if not found, win81-x64, and so on. The graph is flattened into a single list, and there is no need probe any other RIDs. This is all the info you will need.

You can see this yourself by looking at the host code:

https://github.com/dotnet/core-setup/blob/4b628f43fc5989c8a3923cb074b905dbc458f11c/src/corehost/cli/deps_format.cpp#L175-L193

This code first checks the host_rid (i.e. the concrete RID of the machine). If that isn't found, then walk through the fallbacks of the host_rid in order and find the first RID that contains assets, and use it.

}

RuntimeFallbacks runtimeFallbacks
= DependencyContext.RuntimeGraph.Where(g => g.Runtime == RuntimeEnvironment.GetRuntimeIdentifier()).Single();

This comment was marked as spam.

{
mostFitRuntimeIdentifier = null;

if (!SupportsCurrentRuntime())

This comment was marked as spam.


if (!SupportsCurrentRuntime())
{
return false;

This comment was marked as spam.

RuntimeFallbacks runtimeFallbacks
= DependencyContext.RuntimeGraph.Where(g => g.Runtime == RuntimeEnvironment.GetRuntimeIdentifier()).Single();

if (candidateRuntimeIdentifiers.Contains(runtimeFallbacks.Runtime))

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


foreach (var r in runtimeFallbacks.Fallbacks)
{
if (candidateRuntimeIdentifiers.Contains(r))

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

{
var frameworkDependencyFile = new FrameworkDependencyFile();
frameworkDependencyFile.TryGetMostFitRuntimeIdentifier(new[] { "win", "win", "any" }, out string mostFitRid).Should().BeTrue();
mostFitRid.Should().Be("win");

This comment was marked as spam.

@wli3
Copy link
Author

wli3 commented Apr 6, 2018

Talked to Nick, we should extract a static function with FallBack Runtimes and target runtime passed in. And test the gut carefully

@wli3 wli3 force-pushed the TryGetMostFitRuntimeIdentifier branch from 93a6603 to b60ff2b Compare April 6, 2018 21:54
@wli3 wli3 changed the base branch from release/2.1.3xx to master April 6, 2018 21:55
@wli3 wli3 changed the title WIP Add TryGetMostFitRuntimeIdentifier Add TryGetMostFitRuntimeIdentifier Apr 6, 2018
@wli3
Copy link
Author

wli3 commented Apr 6, 2018

@nguerrera I extracted the static method. Used dictionary to keep original, and used distinct to remove dup like "Win" and "win".

I re-targeted master. No more WIP


var runtimeFallbacksIncludesRuntime =
runtimeFallbacks.Fallbacks.ToList();
runtimeFallbacksIncludesRuntime.Insert(0, runtimeFallbacks.Runtime);

This comment was marked as spam.

This comment was marked as spam.

runtimeFallbacksCandidates =
runtimeGraph
.Where(g => string.Equals(g.Runtime, currentRuntimeIdentifier, StringComparison.OrdinalIgnoreCase))
.ToArray();

This comment was marked as spam.

This comment was marked as spam.

}
else
{
runtimeFallbacksCandidates = new RuntimeFallbacks[0];

This comment was marked as spam.

This comment was marked as spam.

@wli3 wli3 force-pushed the TryGetMostFitRuntimeIdentifier branch from cecebc6 to 4eb24cc Compare April 6, 2018 23:41
@wli3 wli3 merged commit 2f01bb4 into dotnet:master Apr 7, 2018
@wli3 wli3 deleted the TryGetMostFitRuntimeIdentifier branch April 7, 2018 00:40
livarcocc added a commit to livarcocc/cli-1 that referenced this pull request Apr 16, 2018
* master: (49 commits)
  Add back 'nuget-build' feed for: NuGet.Versioning 4.7.0-rtm.5081
  Slight re-ordering...
  Add back 'Roslyn' feed for: Microsoft.NETCore.Compilers 2.8.0-beta4-62811-05
  Trim back the 'unnecessary' nuget feeds.
  Insert NuGet Build 4.7.0-rtm.5081 into cli
  Terminate the 'StartsWith' string in the badge existence check. (dotnet#9049)
  Update coresetup, coresetup, coresetup, roslyn to preview3-26411-06, preview3-26411-06, preview3-26411-06, beta4-62811-05, respectively
  consume bring your own shim(byos) (dotnet#9018)
  Fixing typos...
  Updating the dev-certs message displayed in the first run experience.
  Fix merge to only update core-setup and Roslyn versions.
  LOC CHECKIN | dotnet/cli master | 20180409
  Add TryGetMostFitRuntimeIdentifier (dotnet#8997)
  Adapt to no config file Apphost shim
  Update CoreSetup, CoreSetup, CoreSetup, Roslyn to preview3-26406-06, preview3-26406-06, preview3-26406-06, beta4-62806-08, respectively
  Revert links on Readme to master
  Add test cases per PR feedback
  Tweak --no-build messages based on PR feedback
  Update CoreSetup, CoreSetup, CoreSetup, Roslyn to preview3-26405-02, preview3-26405-02, preview3-26405-02, beta4-62805-01, respectively
  Disabling msbuild node reuse for CLI full build.
  ...

 Conflicts:
	build/DependencyVersions.props
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants