move ftl into top level ftl/ folder; make it source of truth for aqt

This avoids the need to modify the external repo before new strings
can be used in aqt.
This commit is contained in:
Damien Elmes 2020-11-18 16:17:19 +10:00
parent a86ce5a1d4
commit fcb3283a9d
40 changed files with 57 additions and 28 deletions

14
ftl/BUILD.bazel Normal file
View File

@ -0,0 +1,14 @@
filegroup(
name = "ftl",
srcs = [
"@rslib_ftl//:files",
"@extra_ftl//:files",
] + glob(["**/*.ftl"]),
visibility = ["//rslib:__subpackages__"],
)
# export this file as a way of locating the top level folder in $(location ...)
exports_files(
["BUILD.bazel"],
visibility = ["//rslib:__subpackages__"],
)

View File

@ -135,12 +135,6 @@ filegroup(
exports_files(["l10n.toml"])
"""
# native.new_local_repository(
# name = "rslib_ftl",
# path = "../anki-i18n/core",
# build_file_content = i18n_build_content,
# )
new_git_repository(
name = "rslib_ftl",
build_file_content = i18n_build_content,
@ -150,12 +144,6 @@ exports_files(["l10n.toml"])
)
if not native.existing_rule("extra_ftl"):
# native.new_local_repository(
# name = "extra_ftl",
# path = "../anki-i18n/qtftl",
# build_file_content = i18n_build_content,
# )
new_git_repository(
name = "extra_ftl",
build_file_content = i18n_build_content,

View File

@ -3,14 +3,6 @@ load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary", "rust_library", "rust
load("@io_bazel_rules_rust//cargo:cargo_build_script.bzl", "cargo_build_script")
load(":rustfmt.bzl", "rustfmt_fix", "rustfmt_test")
# FTL file gathering
#######################
all_ftl_files = [
"@rslib_ftl//:files",
"@extra_ftl//:files",
] + glob(["ftl/*.ftl"])
# Build script
#######################
@ -25,7 +17,8 @@ cargo_build_script(
"BUILDINFO": "$(location //:buildinfo.txt)",
},
crate_root = "build/main.rs",
data = all_ftl_files + [
data = [
"//ftl",
"backend.proto",
"//:buildinfo.txt",
"@com_google_protobuf//:protoc",
@ -162,7 +155,9 @@ rust_binary(
genrule(
name = "fluent_proto",
srcs = all_ftl_files + [
srcs = [
"//ftl",
"//ftl:BUILD.bazel",
"//cargo:fluent_syntax",
"@rslib_ftl//:l10n.toml",
"@extra_ftl//:l10n.toml",
@ -171,7 +166,7 @@ genrule(
cmd = """\
RSLIB_FTL_ROOT="$(location @rslib_ftl//:l10n.toml)" \
EXTRA_FTL_ROOT="$(location @extra_ftl//:l10n.toml)" \
FTL_SRC="$(location ftl/database-check.ftl)" \
FTL_SRC="$(location //ftl:BUILD.bazel)" \
$(location :write_fluent_proto) $(location fluent.proto)""",
tools = [
":write_fluent_proto",

View File

@ -124,6 +124,10 @@ fn get_ftl_data() -> FTLData {
for entry in fs::read_dir(&outer_entry.path()).unwrap() {
let entry = entry.unwrap();
if entry.file_name().to_str().unwrap() == "templates" {
if include_local_qt_templates() {
// ignore source ftl files, as we've already extracted them from the source tree
continue;
}
data.add_template_folder(&entry.path());
} else {
data.add_language_folder(&entry.path());
@ -136,18 +140,27 @@ fn get_ftl_data() -> FTLData {
data
}
/// In a standard build, the ftl/qt folder is used as the source
/// of truth for @extra_ftl, making it easier to add new strings.
/// If the Qt templates are not desired, the NO_QT_TEMPLATES env
/// var can be set to skip them.
fn include_local_qt_templates() -> bool {
env::var("NO_QT_TEMPLATES").is_err()
}
/// Extracts English text from ftl folder in source tree.
fn get_ftl_data_from_source_tree() -> FTLData {
let mut templates: Vec<String> = vec![];
let dir = if let Ok(srcfile) = env::var("FTL_SRC") {
let ftl_base = if let Ok(srcfile) = env::var("FTL_SRC") {
let mut path = PathBuf::from(srcfile);
path.pop();
path
} else {
PathBuf::from("ftl")
PathBuf::from("../ftl")
};
let dir = ftl_base.join("core");
for entry in fs::read_dir(dir).unwrap() {
let entry = entry.unwrap();
let fname = entry.file_name().into_string().unwrap();
@ -156,6 +169,17 @@ fn get_ftl_data_from_source_tree() -> FTLData {
}
}
if include_local_qt_templates() {
let dir = ftl_base.join("qt");
for entry in fs::read_dir(dir).unwrap() {
let entry = entry.unwrap();
let fname = entry.file_name().into_string().unwrap();
if fname.ends_with(".ftl") {
templates.push(fs::read_to_string(entry.path()).unwrap());
}
}
}
FTLData {
templates,
translations: Default::default(),

View File

@ -35,12 +35,12 @@ modules = [
Module(
name="core",
repo="git@github.com:ankitects/anki-core-i18n",
ftl=("rslib/ftl", "core/templates"),
ftl=("ftl/core", "core/templates"),
),
Module(
name="qtftl",
repo="git@github.com:ankitects/anki-desktop-ftl",
ftl=("qt/ftl", "desktop/templates"),
ftl=("ftl/qt", "desktop/templates"),
),
]
@ -122,7 +122,15 @@ def update_ftl_templates():
(source, dest) = ftl
dest = os.path.join(module.folder(), dest)
subprocess.run(
["rsync", "-ai", "--delete", "--no-perms", source + "/", dest + "/"],
[
"rsync",
"-ai",
"--delete",
"--no-perms",
"--no-times",
source + "/",
dest + "/",
],
check=True,
)
commit_if_changed(module.folder())