summary refs log tree commit diff
path: root/pkgs/development/mobile/androidenv/convertpackages.xsl
blob: 5c36deb73c088a356a1e64424b070cfbd6b41de4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:common="http://schemas.android.com/repository/android/common/01"
  xmlns:generic="http://schemas.android.com/repository/android/generic/01"
  xmlns:sdk="http://schemas.android.com/sdk/android/repo/repository2/01"
  xmlns:sdk-common="http://schemas.android.com/sdk/android/repo/common/01"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <xsl:output omit-xml-declaration="yes" indent="no" />

  <!-- Template that puts a google HTTP prefix in front of relative URLs -->
  <xsl:template name="repository-url">
    <xsl:variable name="raw-url" select="complete/url"/>
    <xsl:choose>
      <xsl:when test="starts-with($raw-url, 'http')">
        <xsl:value-of select="$raw-url"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>https://dl.google.com/android/repository/</xsl:text>
        <xsl:value-of select="$raw-url"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="/sdk:sdk-repository">
{fetchurl}:

{
  <!-- Convert all remote packages -->
  <xsl:for-each select="remotePackage[not(contains(@path, ';') and substring-after(@path, ';') = 'latest')]"><xsl:sort select="@path" />

  <!-- Extract the package name from the path -->
  <xsl:variable name="name">
    <xsl:choose>
      <xsl:when test="contains(@path, ';')">
        <xsl:value-of select="substring-before(@path, ';')" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="@path" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <!-- Compose version string from version attributes -->
  <xsl:variable name="revision">
    <xsl:choose>
      <!-- Compose revision for a generic package from the revision attributes -->
      <xsl:when test="type-details/@xsi:type='generic:genericDetailsType'">
        <xsl:choose>
          <xsl:when test="revision/major">
            <xsl:value-of select="revision/major" />
          </xsl:when>
        </xsl:choose>
        <xsl:choose>
          <xsl:when test="revision/minor">.<xsl:value-of select="revision/minor" />
          </xsl:when>
        </xsl:choose>
        <xsl:choose>
          <xsl:when test="revision/micro">.<xsl:value-of select="revision/micro" />
          </xsl:when>
        </xsl:choose>
        <xsl:choose>
          <xsl:when test="revision/preview">-rc<xsl:value-of select="revision/preview" />
          </xsl:when>
        </xsl:choose>
      </xsl:when>
      <!-- Compose revision of a platform SDK from the API-level or codename if the latter exists -->
      <xsl:when test="type-details/@xsi:type='sdk:platformDetailsType'">
        <xsl:choose>
          <xsl:when test="not(type-details/codename='')">
            <xsl:value-of select="type-details/codename" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="type-details/api-level" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <!-- Compose revision of a source SDK from the API-level -->
      <xsl:when test="type-details/@xsi:type='sdk:sourceDetailsType'">
        <xsl:value-of select="type-details/api-level" />
      </xsl:when>
    </xsl:choose>
  </xsl:variable>

  <xsl:choose>
    <xsl:when test="@path='emulator'"> <!-- An emulator package provides one archive per operating system but the same versions -->
  "<xsl:value-of select="$name" />"."<xsl:value-of select="$revision" />".<xsl:value-of select="archives/archive/host-os" /> = {
    </xsl:when>
    <xsl:otherwise>
  "<xsl:value-of select="$name" />"."<xsl:value-of select="$revision" />" = {
    </xsl:otherwise>
  </xsl:choose>
    name = "<xsl:value-of select="$name" />";
    path = "<xsl:value-of select="translate(@path, ';', '/')" />";
    revision = "<xsl:value-of select="$revision" />";
    displayName = "<xsl:value-of select="display-name" />";
    archives = {
      <xsl:for-each select="archives/archive[not(host-os)]">
        all = fetchurl {
          url = <xsl:call-template name="repository-url"/>;
          sha1 = "<xsl:value-of select="complete/checksum" />";
        };
      </xsl:for-each>
      <xsl:for-each select="archives/archive[host-os and not(host-os = 'windows')]">
        <xsl:value-of select="host-os" /> = fetchurl {
        url = <xsl:call-template name="repository-url"/>;
        sha1 = "<xsl:value-of select="complete/checksum" />";
      };
      </xsl:for-each>
    };
  };
  </xsl:for-each>
}
  </xsl:template>
</xsl:stylesheet>