File tree Expand file tree Collapse file tree 3 files changed +19
-8
lines changed
test/rules/android_sdk_repository Expand file tree Collapse file tree 3 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,9 @@ AndroidRevisionInfo = provider(
2626 },
2727)
2828
29+ def is_android_revision (input ):
30+ return all ([c .isdigit () for c in input .strip ().split ("." )])
31+
2932def parse_android_revision (input ):
3033 """Parse and Android revision string and return an AndroidRevisionInfo.
3134
@@ -35,10 +38,10 @@ def parse_android_revision(input):
3538 Returns:
3639 An AndroidRevisionInfo provider representing the input.
3740 """
38- input = input .strip ()
39- parts = input .split ("." )
40- if len (parts ) < 1 :
41+ if not is_android_revision (input ):
4142 fail ("Invalid Android revision %s" % input )
43+ parts = input .strip ().split ("." )
44+
4245 major = int (parts [0 ]) if len (parts ) >= 1 else 0
4346 minor = int (parts [1 ]) if len (parts ) >= 2 else 0
4447 micro = int (parts [2 ]) if len (parts ) >= 3 else 0
Original file line number Diff line number Diff line change 1414
1515"""Bazel rule for Android sdk repository."""
1616
17- load ("//rules:android_revision.bzl" , "compare_android_revisions" , "parse_android_revision" )
17+ load (
18+ "//rules:android_revision.bzl" ,
19+ "compare_android_revisions" ,
20+ "is_android_revision" ,
21+ "parse_android_revision" ,
22+ )
1823
1924_SDK_REPO_TEMPLATE = Label (":template.bzl" )
2025_EMPTY_SDK_REPO_TEMPLATE = Label (":empty.template.bzl" )
@@ -59,8 +64,9 @@ def _newest_build_tools(repo_ctx, android_sdk_path):
5964 return None
6065 for entry in build_tools_path .readdir ():
6166 name = entry .basename
62- revision = parse_android_revision (name )
63- highest = compare_android_revisions (highest , revision )
67+ if is_android_revision (name ):
68+ revision = parse_android_revision (name )
69+ highest = compare_android_revisions (highest , revision )
6470 return highest
6571
6672def _find_system_images (repo_ctx , android_sdk_path ):
Original file line number Diff line number Diff line change @@ -110,10 +110,12 @@ EOF
110110}
111111
112112function test_build_tools_largest() {
113- # create several build tools
113+ # create several build tools, including ones with malformed names
114+ # (e.g. .DStore) to confirm they are properly excluded and do not cause
115+ # crashes.
114116 local sdk_path=" $( create_android_sdk) "
115117 add_platforms " ${sdk_path} " 31
116- add_build_tools " ${sdk_path} " 10.1.2 20.2.3 30.3.4
118+ add_build_tools " ${sdk_path} " 10.1.2 20.2.3 30.3.4 .DStore
117119
118120 # Add to repository.
119121 cat >> WORKSPACE << EOF
You can’t perform that action at this time.
0 commit comments