diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index ac84dfb155..87759e82bb 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -76,3 +76,7 @@ jobs: arguments: assembleRelease build-root-directory: android wrapper-directory: android + + - name: Generate BUILD.gn file for Android + run: python3 generate_build_gn_android.py + working-directory: importer diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 210a9d1080..f9cfe26dba 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -58,6 +58,10 @@ jobs: build-root-directory: android wrapper-directory: android + - name: Generate BUILD.gn file for Android + run: python3 generate_build_gn_android.py + working-directory: importer + ## Publish # Needs to be "-E" instead of "-r" on macOS - name: Replace version numbers in README.md diff --git a/.gitignore b/.gitignore index 2db7fb8b26..3e1da83535 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,5 @@ importer/dist/* .vscode/ -android/library/src/main/res/drawable/ xcuserdata /ios/FluentIcons/Tests diff --git a/importer/generate_build_gn_android.py b/importer/generate_build_gn_android.py new file mode 100644 index 0000000000..e10388fa44 --- /dev/null +++ b/importer/generate_build_gn_android.py @@ -0,0 +1,60 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT license. + +import os + +LIBRARY_NAME = 'library' + +def process_assets(): + project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + android_directory = os.path.join(project_root, "android") + icon_assets_path = os.path.join(android_directory, LIBRARY_NAME, "src", "main", "res", "drawable") + color_assets_path = os.path.join(android_directory, LIBRARY_NAME, "src", "main", "res", "color") + + #icons + icon_file_names = [] + for file_name in os.listdir(icon_assets_path): + if not file_name.endswith('.xml'): + continue + icon_file_names.append(file_name) + icon_file_names.sort() + + #colors + color_file_names = [] + for file_name in os.listdir(color_assets_path): + if not file_name.endswith('.xml'): + continue + color_file_names.append(file_name) + color_file_names.sort() + + + # Generate BUILD.gn for GN build system + gn_path = os.path.join(android_directory, "BUILD.gn") + if os.path.exists(gn_path): + os.remove(gn_path) + + with open(gn_path, 'w+') as gn_file: + gn_file.write("#\n") + gn_file.write("# Copyright (c) Microsoft Corporation. All rights reserved.\n") + gn_file.write("#\n") + gn_file.write("# This file is auto generated\n") + gn_file.write("# Do not make edits or they will be removed later\n") + gn_file.write("#\n\n") + gn_file.write("import(\"//build/config/android/rules.gni\")\n\n") + gn_file.write("android_resources(\"fluent_icon_resources\") {\n") + gn_file.write(" custom_package = \"com.microsoft.fluent.mobile.icons\"\n") + gn_file.write(" sources = [\n") + + for file_name in icon_file_names: + file_path = " \"../android/library/src/main/res/drawable/" + file_name + "\",\n" + gn_file.write(file_path) + + for file_name in color_file_names: + file_path = " \"../android/library/src/main/res/color/" + file_name + "\",\n" + gn_file.write(file_path) + + gn_file.write(" ]\n") + gn_file.write("}\n") + +if __name__ == '__main__': + process_assets() diff --git a/importer/package.json b/importer/package.json index f4be067ff7..442eb4081a 100644 --- a/importer/package.json +++ b/importer/package.json @@ -8,7 +8,7 @@ "clean": "rm -rf dist/*", "build:android": "node generate.js --source=../assets --dest=./dist --extension=svg && sh tools/vd-tool/bin/vd-tool -c -in ./dist -out ./dist && rm ./dist/*.svg && avocado $(find ./dist/ -type f ! -name \"*_selector.xml\") && replace '#212121' '@color/fluent_default_icon_tint' ./dist/* && replace '\"http://schemas.android.com/apk/res/android\"' '\"http://schemas.android.com/apk/res/android\" android:autoMirrored=\"true\"' $(awk '$0=\"./dist/\"$0\".xml\"' rtl.txt)", "build:ios": "node generate.js --source=../assets --dest=./dist --extension=pdf", - "deploy:android": "npm run build:android && rm -rf ../android/library/src/main/res/drawable && cp -a ./dist/. ../android/library/src/main/res/drawable && npm run clean", + "deploy:android": "npm run build:android && rm -rf ../android/library/src/main/res/drawable && mkdir ../android/library/src/main/res/drawable && cp -a ./dist/*.xml ../android/library/src/main/res/drawable && npm run clean", "deploy:ios": "npm run build:ios && python3 process_ios_assets.py && npm run clean" }, "author": "Microsoft Inc.",