Skip to content

Commit

Permalink
Add python script to generate BUILD.gn used by chromium Android proje…
Browse files Browse the repository at this point in the history
…ct (#43)

Chromium projects use GN as Makefile to build the whole project. Add BUILD.gn for fluent icon, so that we can integrate it to Edge Android project conveniently. There is a GN target named "fluent_icon_resources" in the BUILD.gn. If other module need to use the fluent icon resources, we only need add a dependence to "fluent_icon_resources" in other BUILD.gn file.

Co-authored-by: huilliu <[email protected]>
  • Loading branch information
huilliu and huilliu authored Jul 9, 2020
1 parent e9865b3 commit 9501e3c
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ importer/dist/*

.vscode/

android/library/src/main/res/drawable/
xcuserdata
/ios/FluentIcons/Tests
60 changes: 60 additions & 0 deletions importer/generate_build_gn_android.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion importer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down

0 comments on commit 9501e3c

Please sign in to comment.