Skip to content

Commit fe6e1b4

Browse files
committed
Fixes for framework export.
* Fix stripping of some code blocks * Rewrite javadoc pointing to *Async methods to strip out the Async suffix * Write git sha to changed_jetpack_sha instead of changed_jetpack_changeid to clarify that it should be a sha (to facilitate git log) Test: export Change-Id: Ie77e2bd3d8964835d869b54b76ddfc9f3e3a8fb6
1 parent 17f795f commit fe6e1b4

3 files changed

Lines changed: 26 additions & 12 deletions

File tree

‎appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/observer/ObserverSpecCtsTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void testFilterSchemas() {
3636
"Schema1", "Schema2", "Schema3", "Schema4");
3737
}
3838

39-
// @exportToFramework:startStrip
39+
// @exportToFramework:startStrip()
4040

4141
@Document
4242
public static class King {
@@ -74,5 +74,5 @@ public void testFilterSchemas_documentClass() throws Exception {
7474
"Schema1", "Schema2", "King", "Queen", "Schema3", "Schema4", "Jack", "Ace");
7575
}
7676

77-
// @exportToFramework:endStrip
77+
// @exportToFramework:endStrip()
7878
}

‎appsearch/appsearch/src/main/java/androidx/appsearch/app/GlobalSearchSession.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ public interface GlobalSearchSession extends Closeable {
5353
* @param request a request containing a namespace and IDs of the documents to retrieve.
5454
*/
5555
@NonNull
56+
// @exportToFramework:startStrip()
5657
@RequiresFeature(
5758
enforcement = "androidx.appsearch.app.Features#isFeatureSupported",
5859
name = Features.GLOBAL_SEARCH_SESSION_GET_BY_ID)
60+
// @exportToFramework:endStrip()
5961
ListenableFuture<AppSearchBatchResult<String, GenericDocument>> getByDocumentIdAsync(
6062
@NonNull String packageName,
6163
@NonNull String databaseName,

‎appsearch/exportToFramework.py‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
'../../../prebuilts/tools/common/google-java-format/google-java-format')
7272

7373
# Miscellaneous constants
74-
CHANGEID_FILE_NAME = 'synced_jetpack_changeid.txt'
74+
SHA_FILE_NAME = 'synced_jetpack_sha.txt'
7575

7676

7777
class ExportToFramework:
@@ -133,7 +133,7 @@ def _TransformCommonCode(self, contents):
133133
flags=re.MULTILINE)
134134

135135
# Apply in-place replacements
136-
return (contents
136+
contents = (contents
137137
.replace('androidx.appsearch.app', 'android.app.appsearch')
138138
.replace(
139139
'androidx.appsearch.localstorage.',
@@ -161,12 +161,18 @@ def _TransformCommonCode(self, contents):
161161
.replace('@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)', '')
162162
.replace('Preconditions.checkNotNull(', 'Objects.requireNonNull(')
163163
.replace('ObjectsCompat.', 'Objects.')
164+
164165
.replace('/*@exportToFramework:CurrentTimeMillisLong*/', '@CurrentTimeMillisLong')
165166
.replace('/*@exportToFramework:UnsupportedAppUsage*/', '@UnsupportedAppUsage')
166167
.replace('<!--@exportToFramework:hide-->', '@hide')
167168
.replace('// @exportToFramework:skipFile()', '')
168169
)
169170

171+
# Jetpack methods have the Async suffix, but framework doesn't. Strip the Async suffix
172+
# to allow the same documentation to compile for both.
173+
contents = re.sub(r'(#[a-zA-Z0-9_]+)Async}', r'\1}', contents)
174+
return contents
175+
170176
def _TransformTestCode(self, contents):
171177
contents = (contents
172178
.replace('androidx.appsearch.testutil.', 'android.app.appsearch.testutil.')
@@ -318,18 +324,18 @@ def ExportCode(self):
318324
self._ExportImplCode()
319325
self._FormatWrittenFiles()
320326

321-
def WriteChangeIdFile(self, changeid):
322-
"""Copies the changeid of the most recent public CL into a file on the framework side.
327+
def WriteShaFile(self, sha):
328+
"""Copies the git sha of the most recent public CL into a file on the framework side.
323329
324330
This file is used for tracking, to determine what framework is synced to.
325331
326-
You must always provide a changeid of an exported, preferably even submitted CL. If you
327-
abandon the CL pointed to by this changeid, the next person syncing framework will be unable
328-
to find what CL it is synced to.
332+
You must always provide a sha of a submitted submitted git commit. If you abandon the CL
333+
pointed to by this sha, the next person syncing framework will be unable to find what CL it
334+
is synced to.
329335
"""
330-
file_path = os.path.join(self._framework_appsearch_root, CHANGEID_FILE_NAME)
336+
file_path = os.path.join(self._framework_appsearch_root, SHA_FILE_NAME)
331337
with open(file_path, 'w') as fh:
332-
print(changeid, file=fh)
338+
print(sha, file=fh)
333339
print('Wrote "%s"' % file_path)
334340

335341

@@ -339,6 +345,12 @@ def WriteChangeIdFile(self, changeid):
339345
sys.argv[0]),
340346
file=sys.stderr)
341347
sys.exit(1)
348+
if sys.argv[2].startswith('I'):
349+
print('Error: Git sha "%s" looks like a changeid. Please provide a git sha instead.' % (
350+
sys.argv[2]),
351+
file=sys.stderr)
352+
sys.exit(1)
353+
342354
source_dir = os.path.normpath(os.path.dirname(sys.argv[0]))
343355
dest_dir = os.path.normpath(sys.argv[1])
344356
dest_dir = os.path.join(dest_dir, 'packages/modules/AppSearch')
@@ -349,4 +361,4 @@ def WriteChangeIdFile(self, changeid):
349361
sys.exit(1)
350362
exporter = ExportToFramework(source_dir, dest_dir)
351363
exporter.ExportCode()
352-
exporter.WriteChangeIdFile(sys.argv[2])
364+
exporter.WriteShaFile(sys.argv[2])

0 commit comments

Comments
 (0)