Merge pull request #210372 from hadilq/androidenv/generate-package.xml-files
androidenv: generate package.xml in packages' directory
This commit is contained in:
commit
bf9433fd4c
3 changed files with 8706 additions and 459 deletions
|
@ -4,6 +4,59 @@
|
|||
let
|
||||
extraParams = removeAttrs args [ "packages" "os" "buildInputs" "nativeBuildInputs" "patchesInstructions" ];
|
||||
sortedPackages = builtins.sort (x: y: builtins.lessThan x.name y.name) packages;
|
||||
|
||||
mkXmlAttrs = attrs:
|
||||
lib.concatStrings (lib.mapAttrsToList (name: value: " ${name}=\"${value}\"") attrs);
|
||||
mkXmlValues = attrs:
|
||||
lib.concatStrings (lib.mapAttrsToList (name: value:
|
||||
let
|
||||
tag = builtins.head (builtins.match "([^:]+).*" name);
|
||||
in
|
||||
if builtins.typeOf value == "string" then "<${tag}>${value}</${tag}>" else mkXmlDoc name value
|
||||
) attrs);
|
||||
mkXmlDoc = name: doc:
|
||||
let
|
||||
tag = builtins.head (builtins.match "([^:]+).*" name);
|
||||
hasXmlAttrs = builtins.hasAttr "element-attributes" doc;
|
||||
xmlValues = removeAttrs doc [ "element-attributes" ];
|
||||
hasXmlValues = builtins.length (builtins.attrNames xmlValues) > 0;
|
||||
in
|
||||
if hasXmlAttrs && hasXmlValues then "<${tag}${mkXmlAttrs doc.element-attributes}>${mkXmlValues xmlValues }</${tag}>"
|
||||
else if hasXmlAttrs && !hasXmlValues then "<${tag}${mkXmlAttrs doc.element-attributes}/>"
|
||||
else if !hasXmlAttrs && hasXmlValues then "<${tag}>${mkXmlValues xmlValues}</${tag}>"
|
||||
else "<${tag}/>";
|
||||
mkXmlPackage = package: ''
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<ns2:repository
|
||||
xmlns:ns2="http://schemas.android.com/repository/android/common/02"
|
||||
xmlns:ns3="http://schemas.android.com/repository/android/common/01"
|
||||
xmlns:ns4="http://schemas.android.com/repository/android/generic/01"
|
||||
xmlns:ns5="http://schemas.android.com/repository/android/generic/02"
|
||||
xmlns:ns6="http://schemas.android.com/sdk/android/repo/addon2/01"
|
||||
xmlns:ns7="http://schemas.android.com/sdk/android/repo/addon2/02"
|
||||
xmlns:ns8="http://schemas.android.com/sdk/android/repo/addon2/03"
|
||||
xmlns:ns9="http://schemas.android.com/sdk/android/repo/repository2/01"
|
||||
xmlns:ns10="http://schemas.android.com/sdk/android/repo/repository2/02"
|
||||
xmlns:ns11="http://schemas.android.com/sdk/android/repo/repository2/03"
|
||||
xmlns:ns12="http://schemas.android.com/sdk/android/repo/sys-img2/03"
|
||||
xmlns:ns13="http://schemas.android.com/sdk/android/repo/sys-img2/02"
|
||||
xmlns:ns14="http://schemas.android.com/sdk/android/repo/sys-img2/01"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<license id="${package.license}" type="text">${lib.concatStringsSep "---" (mkLicenses package.license)}</license>
|
||||
<localPackage path="${builtins.replaceStrings [ "/" ] [ ";" ] package.path}" obsolete="${
|
||||
if (lib.hasAttrByPath [ "obsolete" ] package)
|
||||
then package.obsolete else "false"
|
||||
}">
|
||||
${mkXmlDoc "type-details" package.type-details}
|
||||
${mkXmlDoc "revision" package.revision-details}
|
||||
${lib.optionalString (lib.hasAttrByPath [ "dependencies" ] package)
|
||||
(mkXmlDoc "dependencies" package.dependencies)
|
||||
}
|
||||
<display-name>${package.displayName}</display-name>
|
||||
<uses-license ref="${package.license}"/>
|
||||
</localPackage>
|
||||
</ns2:repository>
|
||||
'';
|
||||
in
|
||||
stdenv.mkDerivation ({
|
||||
inherit buildInputs;
|
||||
|
@ -44,6 +97,12 @@ stdenv.mkDerivation ({
|
|||
cd $packageBaseDir
|
||||
cp -a $extractedZip/* .
|
||||
${patchesInstructions.${package.name}}
|
||||
|
||||
if [ ! -f $packageBaseDir/package.xml ]; then
|
||||
cat << EOF > $packageBaseDir/package.xml
|
||||
${mkXmlPackage package}
|
||||
EOF
|
||||
fi
|
||||
'') packages);
|
||||
|
||||
# Some executables that have been patched with patchelf may not work any longer after they have been stripped.
|
||||
|
|
|
@ -29,6 +29,49 @@ def image_url value, dir
|
|||
end
|
||||
end
|
||||
|
||||
# Returns a JSON with the data and structure of the input XML
|
||||
def to_json_collector doc
|
||||
json = {}
|
||||
index = 0
|
||||
doc.element_children.each { |node|
|
||||
if node.children.length == 1 and node.children.first.text?
|
||||
json["#{node.name}:#{index}"] ||= node.content
|
||||
index += 1
|
||||
next
|
||||
end
|
||||
json["#{node.name}:#{index}"] ||= to_json_collector node
|
||||
index += 1
|
||||
}
|
||||
element_attributes = {}
|
||||
doc.attribute_nodes.each do |attr|
|
||||
if attr.name == "type"
|
||||
type = attr.value.split(':', 2).last
|
||||
case attr.value
|
||||
when 'generic:genericDetailsType'
|
||||
element_attributes["xsi:type"] ||= "ns5:#{type}"
|
||||
when 'addon:extraDetailsType'
|
||||
element_attributes["xsi:type"] ||= "ns8:#{type}"
|
||||
when 'addon:mavenType'
|
||||
element_attributes["xsi:type"] ||= "ns8:#{type}"
|
||||
when 'sdk:platformDetailsType'
|
||||
element_attributes["xsi:type"] ||= "ns11:#{type}"
|
||||
when 'sdk:sourceDetailsType'
|
||||
element_attributes["xsi:type"] ||= "ns11:#{type}"
|
||||
when 'sys-img:sysImgDetailsType'
|
||||
element_attributes["xsi:type"] ||= "ns12:#{type}"
|
||||
when 'addon:addonDetailsType' then
|
||||
element_attributes["xsi:type"] ||= "ns8:#{type}"
|
||||
end
|
||||
else
|
||||
element_attributes[attr.name] ||= attr.value
|
||||
end
|
||||
end
|
||||
if !element_attributes.empty?
|
||||
json['element-attributes'] ||= element_attributes
|
||||
end
|
||||
json
|
||||
end
|
||||
|
||||
# Returns a tuple of [type, revision, revision components] for a package node.
|
||||
def package_revision package
|
||||
type_details = package.at_css('> type-details')
|
||||
|
@ -148,7 +191,7 @@ def fixup value
|
|||
else
|
||||
[k, v]
|
||||
end
|
||||
end.sort {|(k1, v1), (k2, v2)| k1 <=> k2}]
|
||||
end.sort {|(k1, v1), (k2, v2)| k1 <=> k2 }]
|
||||
end
|
||||
|
||||
# Normalize the specified license text.
|
||||
|
@ -189,7 +232,12 @@ def parse_package_xml doc
|
|||
display_name = text package.at_css('> display-name')
|
||||
uses_license = package.at_css('> uses-license')
|
||||
uses_license &&= uses_license['ref']
|
||||
obsolete ||= package['obsolete']
|
||||
type_details = to_json_collector package.at_css('> type-details')
|
||||
revision_details = to_json_collector package.at_css('> revision')
|
||||
archives = package_archives(package) {|url| repo_url url}
|
||||
dependencies_xml = package.at_css('> dependencies')
|
||||
dependencies = to_json_collector dependencies_xml if dependencies_xml
|
||||
|
||||
target = (packages[name] ||= {})
|
||||
target = (target[revision] ||= {})
|
||||
|
@ -199,6 +247,10 @@ def parse_package_xml doc
|
|||
target['revision'] ||= revision
|
||||
target['displayName'] ||= display_name
|
||||
target['license'] ||= uses_license if uses_license
|
||||
target['obsolete'] ||= obsolete if obsolete == 'true'
|
||||
target['type-details'] ||= type_details
|
||||
target['revision-details'] ||= revision_details
|
||||
target['dependencies'] ||= dependencies if dependencies
|
||||
target['archives'] ||= {}
|
||||
merge target['archives'], archives
|
||||
end
|
||||
|
@ -218,11 +270,17 @@ def parse_image_xml doc
|
|||
display_name = text package.at_css('> display-name')
|
||||
uses_license = package.at_css('> uses-license')
|
||||
uses_license &&= uses_license['ref']
|
||||
obsolete &&= package['obsolete']
|
||||
type_details = to_json_collector package.at_css('> type-details')
|
||||
revision_details = to_json_collector package.at_css('> revision')
|
||||
archives = package_archives(package) {|url| image_url url, components[-2]}
|
||||
dependencies_xml = package.at_css('> dependencies')
|
||||
dependencies = to_json_collector dependencies_xml if dependencies_xml
|
||||
|
||||
target = images
|
||||
components.each do |component|
|
||||
target = (target[component] ||= {})
|
||||
target[component] ||= {}
|
||||
target = target[component]
|
||||
end
|
||||
|
||||
target['name'] ||= "system-image-#{revision}"
|
||||
|
@ -230,6 +288,10 @@ def parse_image_xml doc
|
|||
target['revision'] ||= revision
|
||||
target['displayName'] ||= display_name
|
||||
target['license'] ||= uses_license if uses_license
|
||||
target['obsolete'] ||= obsolete if obsolete
|
||||
target['type-details'] ||= type_details
|
||||
target['revision-details'] ||= revision_details
|
||||
target['dependencies'] ||= dependencies if dependencies
|
||||
target['archives'] ||= {}
|
||||
merge target['archives'], archives
|
||||
end
|
||||
|
@ -249,7 +311,12 @@ def parse_addon_xml doc
|
|||
display_name = text package.at_css('> display-name')
|
||||
uses_license = package.at_css('> uses-license')
|
||||
uses_license &&= uses_license['ref']
|
||||
obsolete &&= package['obsolete']
|
||||
type_details = to_json_collector package.at_css('> type-details')
|
||||
revision_details = to_json_collector package.at_css('> revision')
|
||||
archives = package_archives(package) {|url| repo_url url}
|
||||
dependencies_xml = package.at_css('> dependencies')
|
||||
dependencies = to_json_collector dependencies_xml if dependencies_xml
|
||||
|
||||
case type
|
||||
when 'addon:addonDetailsType'
|
||||
|
@ -278,6 +345,10 @@ def parse_addon_xml doc
|
|||
target['revision'] ||= revision
|
||||
target['displayName'] ||= display_name
|
||||
target['license'] ||= uses_license if uses_license
|
||||
target['obsolete'] ||= obsolete if obsolete
|
||||
target['type-details'] ||= type_details
|
||||
target['revision-details'] ||= revision_details
|
||||
target['dependencies'] ||= dependencies if dependencies
|
||||
target['archives'] ||= {}
|
||||
merge target['archives'], archives
|
||||
end
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue