@@ -670,8 +670,9 @@ def valid_ndk_path(path):
670
670
error_msg = ('The path %s or its child file "source.properties" '
671
671
'does not exist.' )
672
672
)
673
-
674
- write_android_ndk_workspace_rule (android_ndk_home_path )
673
+ write_action_env_to_bazelrc ('ANDROID_NDK_HOME' , android_ndk_home_path )
674
+ write_action_env_to_bazelrc ('ANDROID_NDK_API_LEVEL' ,
675
+ check_ndk_level (android_ndk_home_path ))
675
676
676
677
677
678
def create_android_sdk_rule (environ_cp ):
@@ -733,41 +734,12 @@ def valid_build_tools(version):
733
734
error_msg = ('The selected SDK does not have build-tools version %s '
734
735
'available.' ))
735
736
736
- write_android_sdk_workspace_rule (android_sdk_home_path ,
737
- android_build_tools_version ,
738
- android_api_level )
739
-
740
-
741
- def write_android_sdk_workspace_rule (android_sdk_home_path ,
742
- android_build_tools_version ,
743
- android_api_level ):
744
- print ('Writing android_sdk_workspace rule.\n ' )
745
- with open (_TF_WORKSPACE , 'a' ) as f :
746
- f .write ("""
747
- android_sdk_repository(
748
- name="androidsdk",
749
- api_level=%s,
750
- path="%s",
751
- build_tools_version="%s")\n
752
- """ % (android_api_level , android_sdk_home_path , android_build_tools_version ))
753
-
754
-
755
- def write_android_ndk_workspace_rule (android_ndk_home_path ):
756
- print ('Writing android_ndk_workspace rule.' )
757
- ndk_api_level = check_ndk_level (android_ndk_home_path )
758
- if int (ndk_api_level ) not in _SUPPORTED_ANDROID_NDK_VERSIONS :
759
- print ('WARNING: The API level of the NDK in %s is %s, which is not '
760
- 'supported by Bazel (officially supported versions: %s). Please use '
761
- 'another version. Compiling Android targets may result in confusing '
762
- 'errors.\n ' % (android_ndk_home_path , ndk_api_level ,
763
- _SUPPORTED_ANDROID_NDK_VERSIONS ))
764
- with open (_TF_WORKSPACE , 'a' ) as f :
765
- f .write ("""
766
- android_ndk_repository(
767
- name="androidndk",
768
- path="%s",
769
- api_level=%s)\n
770
- """ % (android_ndk_home_path , ndk_api_level ))
737
+ write_action_env_to_bazelrc ('ANDROID_BUILD_TOOLS_VERSION' ,
738
+ android_build_tools_version )
739
+ write_action_env_to_bazelrc ('ANDROID_SDK_API_LEVEL' ,
740
+ android_api_level )
741
+ write_action_env_to_bazelrc ('ANDROID_SDK_HOME' ,
742
+ android_sdk_home_path )
771
743
772
744
773
745
def check_ndk_level (android_ndk_home_path ):
@@ -780,18 +752,16 @@ def check_ndk_level(android_ndk_home_path):
780
752
781
753
revision = re .search (r'Pkg.Revision = (\d+)' , filedata )
782
754
if revision :
783
- return revision .group (1 )
784
- return None
785
-
786
-
787
- def workspace_has_any_android_rule ():
788
- """Check the WORKSPACE for existing android_*_repository rules."""
789
- with open (_TF_WORKSPACE , 'r' ) as f :
790
- workspace = f .read ()
791
- has_any_rule = re .search (r'^android_[ns]dk_repository' ,
792
- workspace ,
793
- re .MULTILINE )
794
- return has_any_rule
755
+ ndk_api_level = revision .group (1 )
756
+ else :
757
+ raise Exception ('Unable to parse NDK revision.' )
758
+ if int (ndk_api_level ) not in _SUPPORTED_ANDROID_NDK_VERSIONS :
759
+ print ('WARNING: The API level of the NDK in %s is %s, which is not '
760
+ 'supported by Bazel (officially supported versions: %s). Please use '
761
+ 'another version. Compiling Android targets may result in confusing '
762
+ 'errors.\n ' % (android_ndk_home_path , ndk_api_level ,
763
+ _SUPPORTED_ANDROID_NDK_VERSIONS ))
764
+ return ndk_api_level
795
765
796
766
797
767
def set_gcc_host_compiler_path (environ_cp ):
@@ -1223,7 +1193,7 @@ def set_tf_cuda_compute_capabilities(environ_cp):
1223
1193
# Check whether all capabilities from the input is valid
1224
1194
all_valid = True
1225
1195
# Remove all whitespace characters before splitting the string
1226
- # that users may insert by accident, as this will result in error
1196
+ # that users may insert by accident, as this will result in error
1227
1197
tf_cuda_compute_capabilities = '' .join (tf_cuda_compute_capabilities .split ())
1228
1198
for compute_capability in tf_cuda_compute_capabilities .split (',' ):
1229
1199
m = re .match ('[0-9]+.[0-9]+' , compute_capability )
@@ -1556,21 +1526,15 @@ def main():
1556
1526
set_build_strip_flag ()
1557
1527
set_windows_build_flags ()
1558
1528
1559
- if workspace_has_any_android_rule ():
1560
- print ('The WORKSPACE file has at least one of ["android_sdk_repository", '
1561
- '"android_ndk_repository"] already set. Will not ask to help '
1562
- 'configure the WORKSPACE. Please delete the existing rules to '
1563
- 'activate the helper.\n ' )
1564
- else :
1565
- if get_var (
1566
- environ_cp , 'TF_SET_ANDROID_WORKSPACE' , 'android workspace' ,
1567
- False ,
1568
- ('Would you like to interactively configure ./WORKSPACE for '
1569
- 'Android builds?' ),
1570
- 'Searching for NDK and SDK installations.' ,
1571
- 'Not configuring the WORKSPACE for Android builds.' ):
1572
- create_android_ndk_rule (environ_cp )
1573
- create_android_sdk_rule (environ_cp )
1529
+ if get_var (
1530
+ environ_cp , 'TF_SET_ANDROID_WORKSPACE' , 'android workspace' ,
1531
+ False ,
1532
+ ('Would you like to interactively configure ./WORKSPACE for '
1533
+ 'Android builds?' ),
1534
+ 'Searching for NDK and SDK installations.' ,
1535
+ 'Not configuring the WORKSPACE for Android builds.' ):
1536
+ create_android_ndk_rule (environ_cp )
1537
+ create_android_sdk_rule (environ_cp )
1574
1538
1575
1539
print ('Preconfigured Bazel build configs. You can use any of the below by '
1576
1540
'adding "--config=<>" to your build command. See tools/bazel.rc for '
0 commit comments