Skip to content

Commit

Permalink
fix: remove XML declaration from glib schemas (#972)
Browse files Browse the repository at this point in the history
This is a workaround so [we don't
fail](https://github.com/ubuntu/adsys/actions/runs/8809678726/job/24180895123)
when parsing schemas with invalid XML declarations, such as
[`org.gnome.Extensions.gschema.xml`](https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/41b94ccf11a66c5b315f834061cdec82a622f4ec/subprojects/extensions-app/data/org.gnome.Extensions.gschema.xml).
Interestingly this doesn't seem to bother `glib-compile-schemas` but
fails with most XML parsers (including Go's parser).

While I've already fixed this
[upstream](https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3281),
it'll take a while until the updated version feeds into Ubuntu so we
need a workaround within adsys too, otherwise we are blocked from
refreshing the ADMX/ADML files.

For simplicity I've opted to remove the XML declaration line if it
occurs, this way we don't concern ourselves checking for specific syntax
errors.

Fixes #955 / UDENG-2730
  • Loading branch information
GabrielNagy authored Apr 25, 2024
2 parents 418a5b7 + 73d5db3 commit 45d2dd4
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The applications corresponding to these identifiers will be displayed in the fav
- Default for 20.04: `[ 'ubiquity.desktop', 'firefox.desktop', 'thunderbird.desktop', 'org.gnome.Nautilus.desktop', 'rhythmbox.desktop', 'libreoffice-writer.desktop', 'snap-store_ubuntu-software.desktop', 'yelp.desktop' ]`
- Default for 22.04: `[ 'ubuntu-desktop-installer_ubuntu-desktop-installer.desktop', 'ubiquity.desktop', 'firefox_firefox.desktop', 'thunderbird.desktop', 'org.gnome.Nautilus.desktop', 'rhythmbox.desktop', 'libreoffice-writer.desktop', 'snap-store_ubuntu-software.desktop', 'yelp.desktop' ]`
- Default for 23.10: `[ 'ubuntu-desktop-installer_ubuntu-desktop-installer.desktop', 'ubiquity.desktop', 'firefox_firefox.desktop', 'thunderbird.desktop', 'org.gnome.Nautilus.desktop', 'rhythmbox.desktop', 'libreoffice-writer.desktop', 'snap-store_snap-store.desktop', 'yelp.desktop' ]`
- Default for 24.04: `[ 'ubuntu-desktop-installer_ubuntu-desktop-installer.desktop', 'ubiquity.desktop', 'firefox_firefox.desktop', 'thunderbird.desktop', 'org.gnome.Nautilus.desktop', 'rhythmbox.desktop', 'libreoffice-writer.desktop', 'snap-store_snap-store.desktop', 'yelp.desktop' ]`
- Default for 24.04: `[ 'ubuntu-desktop-bootstrap_ubuntu-desktop-bootstrap.desktop', 'firefox_firefox.desktop', 'thunderbird_thunderbird.desktop', 'org.gnome.Nautilus.desktop', 'org.gnome.Rhythmbox3.desktop', 'libreoffice-writer.desktop', 'snap-store_snap-store.desktop', 'yelp.desktop' ]`

Note: default system value is used for "Not Configured" and enforced if "Disabled".

Expand Down
11 changes: 11 additions & 0 deletions internal/ad/admxgen/dconf/dconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package dconf

import (
"bytes"
"encoding/xml"
"errors"
"fmt"
Expand Down Expand Up @@ -252,6 +253,16 @@ func loadSchemasFromDisk(path string) (entries map[string]schemaEntry, defaultsF
return nil, nil, errors.New(gotext.Get("cannot read schema data: %v", err))
}

// Remove XML declaration from the schema, if any. This is to account for badly formatted XML files which don't appear to bother
// glib-compile-schemas, so we should aim for similar leniency.
if xmlStart := bytes.Index(d, []byte("<?xml")); xmlStart != -1 {
if xmlEnd := bytes.Index(d[xmlStart:], []byte("?>")); xmlEnd != -1 {
// Adjust xmlEnd to account for the relative position and length of "?>"
xmlEnd += xmlStart + 2
d = d[xmlEnd:]
}
}

var sl schemaList
if err := xml.Unmarshal(d, &sl); err != nil {
return nil, nil, errors.New(gotext.Get("%s is an invalid schema: %v", p, err))
Expand Down
3 changes: 3 additions & 0 deletions internal/ad/admxgen/dconf/dconf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func TestGenerate(t *testing.T) {
"Description starting with obsolete is ignored": {root: "deprecated_keys"},
"Description containing deprecated without starting by it is not ignored": {root: "deprecated_keys"},

"Malformed XML declaration is successfully parsed": {root: "malformed_xml_declaration"},
"Missing XML declaration is successfully parsed": {root: "missing_xml_declaration"},

// Error cases
"Unsupported key type": {root: "exotic_type", wantErr: true},
"Enum does not exist": {root: "nonexistent_enum", wantErr: true},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- objectpath: "/com/ubuntu/simple/simple-text-property"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- objectpath: "/com/ubuntu/simple/simple-text-property"
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
default: '''choice 2'''
note: default system value is used for "Not Configured" and enforced if "Disabled".
choices:
- choice 1
- choice 2
- choice 3
- choice 1
- choice 2
- choice 3
release: "20.04"
type: dconf
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
default: '''up'''
note: default system value is used for "Not Configured" and enforced if "Disabled".
choices:
- left
- right
- up
- down
- left
- right
- up
- down
release: "20.04"
type: dconf
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
default: '''HIGH'''
note: default system value is used for "Not Configured" and enforced if "Disabled".
choices:
- LOW
- MEDIUM
- HIGH
- MAXIMUM
- LOW
- MEDIUM
- HIGH
- MAXIMUM
release: "20.04"
type: dconf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- key: /com/ubuntu/simple/simple-text-property
displayname: simple-text-property summary
explaintext: simple-text-property description
elementtype: text
metaenabled:
empty: ''''''
meta: s
metadisabled:
meta: s
default: '''simple-text-property Default Value'''
note: default system value is used for "Not Configured" and enforced if "Disabled".
release: "20.04"
type: dconf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- key: /com/ubuntu/simple/simple-text-property
displayname: simple-text-property summary
explaintext: simple-text-property description
elementtype: text
metaenabled:
empty: ''''''
meta: s
metadisabled:
meta: s
default: '''simple-text-property Default Value'''
note: default system value is used for "Not Configured" and enforced if "Disabled".
release: "20.04"
type: dconf
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
meta: s
metadisabled:
meta: s
default: '''This is the simple-text-property-overridden-by-multiple-files overridden
Value'''
default: '''This is the simple-text-property-overridden-by-multiple-files overridden Value'''
note: default system value is used for "Not Configured" and enforced if "Disabled".
release: "20.04"
type: dconf
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
meta: s
metadisabled:
meta: s
default: '''Overridden simple-text-property-overridden-ubuntu-gnome Value For Ubuntu
Session'''
default: '''Overridden simple-text-property-overridden-ubuntu-gnome Value For Ubuntu Session'''
note: default system value is used for "Not Configured" and enforced if "Disabled".
release: "20.04"
type: dconf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="gsettings-ubuntu-touch-schemas">
<schema path="/com/ubuntu/simple/" id="com.ubuntu.simple">
<key type="s" name="simple-text-property">
<default>'simple-text-property Default Value'</default>
<summary>simple-text-property summary</summary>
<description>simple-text-property description</description>
</key>
<key type="s" name="simple-text-property-no-description">
<default>'simple-text-property-no-description Default Value'</default>
<summary>simple-text-property-no-description summary</summary>
</key>
<key type="s" name="simple-text-property-no-default">
<summary>simple-text-property-no-default summary</summary>
<description>simple-text-property-no-default description</description>
</key>
<key type="s" name="simple-text-property-no-summary">
<default>'simple-text-property-no-summary Default Value'</default>
<description>simple-text-property-no-summary description</description>
</key>
</schema>
</schemalist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<schemalist gettext-domain="gsettings-ubuntu-touch-schemas">
<schema path="/com/ubuntu/simple/" id="com.ubuntu.simple">
<key type="s" name="simple-text-property">
<default>'simple-text-property Default Value'</default>
<summary>simple-text-property summary</summary>
<description>simple-text-property description</description>
</key>
<key type="s" name="simple-text-property-no-description">
<default>'simple-text-property-no-description Default Value'</default>
<summary>simple-text-property-no-description summary</summary>
</key>
<key type="s" name="simple-text-property-no-default">
<summary>simple-text-property-no-default summary</summary>
<description>simple-text-property-no-default description</description>
</key>
<key type="s" name="simple-text-property-no-summary">
<default>'simple-text-property-no-summary Default Value'</default>
<description>simple-text-property-no-summary description</description>
</key>
</schema>
</schemalist>
2 changes: 1 addition & 1 deletion policies/Ubuntu/all/Ubuntu.adml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Supported on Ubuntu 20.04, 22.04, 23.10, 24.04.</string>
- Default for 20.04: [ &#39;ubiquity.desktop&#39;, &#39;firefox.desktop&#39;, &#39;thunderbird.desktop&#39;, &#39;org.gnome.Nautilus.desktop&#39;, &#39;rhythmbox.desktop&#39;, &#39;libreoffice-writer.desktop&#39;, &#39;snap-store_ubuntu-software.desktop&#39;, &#39;yelp.desktop&#39; ]
- Default for 22.04: [ &#39;ubuntu-desktop-installer_ubuntu-desktop-installer.desktop&#39;, &#39;ubiquity.desktop&#39;, &#39;firefox_firefox.desktop&#39;, &#39;thunderbird.desktop&#39;, &#39;org.gnome.Nautilus.desktop&#39;, &#39;rhythmbox.desktop&#39;, &#39;libreoffice-writer.desktop&#39;, &#39;snap-store_ubuntu-software.desktop&#39;, &#39;yelp.desktop&#39; ]
- Default for 23.10: [ &#39;ubuntu-desktop-installer_ubuntu-desktop-installer.desktop&#39;, &#39;ubiquity.desktop&#39;, &#39;firefox_firefox.desktop&#39;, &#39;thunderbird.desktop&#39;, &#39;org.gnome.Nautilus.desktop&#39;, &#39;rhythmbox.desktop&#39;, &#39;libreoffice-writer.desktop&#39;, &#39;snap-store_snap-store.desktop&#39;, &#39;yelp.desktop&#39; ]
- Default for 24.04: [ &#39;ubuntu-desktop-installer_ubuntu-desktop-installer.desktop&#39;, &#39;ubiquity.desktop&#39;, &#39;firefox_firefox.desktop&#39;, &#39;thunderbird.desktop&#39;, &#39;org.gnome.Nautilus.desktop&#39;, &#39;rhythmbox.desktop&#39;, &#39;libreoffice-writer.desktop&#39;, &#39;snap-store_snap-store.desktop&#39;, &#39;yelp.desktop&#39; ]
- Default for 24.04: [ &#39;ubuntu-desktop-bootstrap_ubuntu-desktop-bootstrap.desktop&#39;, &#39;firefox_firefox.desktop&#39;, &#39;thunderbird_thunderbird.desktop&#39;, &#39;org.gnome.Nautilus.desktop&#39;, &#39;org.gnome.Rhythmbox3.desktop&#39;, &#39;libreoffice-writer.desktop&#39;, &#39;snap-store_snap-store.desktop&#39;, &#39;yelp.desktop&#39; ]

Note: default system value is used for &#34;Not Configured&#34; and enforced if &#34;Disabled&#34;.

Expand Down
2 changes: 1 addition & 1 deletion policies/Ubuntu/lts-only/Ubuntu.adml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Supported on Ubuntu 20.04, 22.04, 24.04.</string>
- Key: /org/gnome/shell/favorite-apps
- Default for 20.04: [ &#39;ubiquity.desktop&#39;, &#39;firefox.desktop&#39;, &#39;thunderbird.desktop&#39;, &#39;org.gnome.Nautilus.desktop&#39;, &#39;rhythmbox.desktop&#39;, &#39;libreoffice-writer.desktop&#39;, &#39;snap-store_ubuntu-software.desktop&#39;, &#39;yelp.desktop&#39; ]
- Default for 22.04: [ &#39;ubuntu-desktop-installer_ubuntu-desktop-installer.desktop&#39;, &#39;ubiquity.desktop&#39;, &#39;firefox_firefox.desktop&#39;, &#39;thunderbird.desktop&#39;, &#39;org.gnome.Nautilus.desktop&#39;, &#39;rhythmbox.desktop&#39;, &#39;libreoffice-writer.desktop&#39;, &#39;snap-store_ubuntu-software.desktop&#39;, &#39;yelp.desktop&#39; ]
- Default for 24.04: [ &#39;ubuntu-desktop-installer_ubuntu-desktop-installer.desktop&#39;, &#39;ubiquity.desktop&#39;, &#39;firefox_firefox.desktop&#39;, &#39;thunderbird.desktop&#39;, &#39;org.gnome.Nautilus.desktop&#39;, &#39;rhythmbox.desktop&#39;, &#39;libreoffice-writer.desktop&#39;, &#39;snap-store_snap-store.desktop&#39;, &#39;yelp.desktop&#39; ]
- Default for 24.04: [ &#39;ubuntu-desktop-bootstrap_ubuntu-desktop-bootstrap.desktop&#39;, &#39;firefox_firefox.desktop&#39;, &#39;thunderbird_thunderbird.desktop&#39;, &#39;org.gnome.Nautilus.desktop&#39;, &#39;org.gnome.Rhythmbox3.desktop&#39;, &#39;libreoffice-writer.desktop&#39;, &#39;snap-store_snap-store.desktop&#39;, &#39;yelp.desktop&#39; ]

Note: default system value is used for &#34;Not Configured&#34; and enforced if &#34;Disabled&#34;.

Expand Down

0 comments on commit 45d2dd4

Please sign in to comment.