-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
- Loading branch information
1 parent
709eaea
commit d56bbd9
Showing
4 changed files
with
341 additions
and
406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import io | ||
import os | ||
import subprocess | ||
import sys | ||
import tempfile | ||
import xml.etree.ElementTree as ET | ||
|
||
|
||
def add_source_exclusions(path): | ||
tree = ET.parse(path) | ||
root = tree.getroot() | ||
|
||
ns = 'https://schema.gradle.org/dependency-verification' | ||
ET.register_namespace('', ns) | ||
configuration = root.find(f'{{{ns}}}configuration') | ||
trusted_artifacts = ET.SubElement( | ||
configuration, f'{{{ns}}}trusted-artifacts') | ||
|
||
for regex in [ | ||
r'.*-javadoc[.]jar', | ||
r'.*-sources[.]jar', | ||
r'.*-src[.]zip', | ||
]: | ||
ET.SubElement(trusted_artifacts, f'{{{ns}}}trust', attrib={ | ||
'file': regex, | ||
'regex': 'true', | ||
}) | ||
|
||
# Match gradle's formatting exactly. | ||
ET.indent(tree, ' ') | ||
root.tail = '\n' | ||
|
||
with io.BytesIO() as f: | ||
# etree's xml_declaration=True uses single quotes in the header. | ||
f.write(b'<?xml version="1.0" encoding="UTF-8"?>\n') | ||
tree.write(f) | ||
serialized = f.getvalue().replace(b' />', b'/>') | ||
|
||
with open(path, 'wb') as f: | ||
f.write(serialized) | ||
|
||
|
||
def main(): | ||
root_dir = os.path.join(sys.path[0], '..') | ||
xml_file = os.path.join(sys.path[0], 'verification-metadata.xml') | ||
|
||
try: | ||
os.remove(xml_file) | ||
except FileNotFoundError: | ||
pass | ||
|
||
# Gradle will sometimes fail to add verification entries for artifacts that | ||
# are already cached. | ||
with tempfile.TemporaryDirectory() as temp_dir: | ||
env = os.environ | {'GRADLE_USER_HOME': temp_dir} | ||
|
||
subprocess.check_call( | ||
[ | ||
'./gradlew' + ('.bat' if os.name == 'nt' else ''), | ||
'--write-verification-metadata', 'sha512', | ||
'--no-daemon', | ||
'build', | ||
'zipDebug', | ||
# Requires signing. | ||
'-x', 'assembleRelease', | ||
], | ||
env=env, | ||
cwd=root_dir, | ||
) | ||
|
||
# Add exclusions to allow Android Studio to download sources. | ||
add_source_exclusions(xml_file) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.