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"]) exports_files(["l10n.toml"])
""" """
# native.new_local_repository(
# name = "rslib_ftl",
# path = "../anki-i18n/core",
# build_file_content = i18n_build_content,
# )
new_git_repository( new_git_repository(
name = "rslib_ftl", name = "rslib_ftl",
build_file_content = i18n_build_content, build_file_content = i18n_build_content,
@ -150,12 +144,6 @@ exports_files(["l10n.toml"])
) )
if not native.existing_rule("extra_ftl"): 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( new_git_repository(
name = "extra_ftl", name = "extra_ftl",
build_file_content = i18n_build_content, 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("@io_bazel_rules_rust//cargo:cargo_build_script.bzl", "cargo_build_script")
load(":rustfmt.bzl", "rustfmt_fix", "rustfmt_test") load(":rustfmt.bzl", "rustfmt_fix", "rustfmt_test")
# FTL file gathering
#######################
all_ftl_files = [
"@rslib_ftl//:files",
"@extra_ftl//:files",
] + glob(["ftl/*.ftl"])
# Build script # Build script
####################### #######################
@ -25,7 +17,8 @@ cargo_build_script(
"BUILDINFO": "$(location //:buildinfo.txt)", "BUILDINFO": "$(location //:buildinfo.txt)",
}, },
crate_root = "build/main.rs", crate_root = "build/main.rs",
data = all_ftl_files + [ data = [
"//ftl",
"backend.proto", "backend.proto",
"//:buildinfo.txt", "//:buildinfo.txt",
"@com_google_protobuf//:protoc", "@com_google_protobuf//:protoc",
@ -162,7 +155,9 @@ rust_binary(
genrule( genrule(
name = "fluent_proto", name = "fluent_proto",
srcs = all_ftl_files + [ srcs = [
"//ftl",
"//ftl:BUILD.bazel",
"//cargo:fluent_syntax", "//cargo:fluent_syntax",
"@rslib_ftl//:l10n.toml", "@rslib_ftl//:l10n.toml",
"@extra_ftl//:l10n.toml", "@extra_ftl//:l10n.toml",
@ -171,7 +166,7 @@ genrule(
cmd = """\ cmd = """\
RSLIB_FTL_ROOT="$(location @rslib_ftl//:l10n.toml)" \ RSLIB_FTL_ROOT="$(location @rslib_ftl//:l10n.toml)" \
EXTRA_FTL_ROOT="$(location @extra_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)""", $(location :write_fluent_proto) $(location fluent.proto)""",
tools = [ tools = [
":write_fluent_proto", ":write_fluent_proto",

View file

@ -124,6 +124,10 @@ fn get_ftl_data() -> FTLData {
for entry in fs::read_dir(&outer_entry.path()).unwrap() { for entry in fs::read_dir(&outer_entry.path()).unwrap() {
let entry = entry.unwrap(); let entry = entry.unwrap();
if entry.file_name().to_str().unwrap() == "templates" { 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()); data.add_template_folder(&entry.path());
} else { } else {
data.add_language_folder(&entry.path()); data.add_language_folder(&entry.path());
@ -136,18 +140,27 @@ fn get_ftl_data() -> FTLData {
data 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. /// Extracts English text from ftl folder in source tree.
fn get_ftl_data_from_source_tree() -> FTLData { fn get_ftl_data_from_source_tree() -> FTLData {
let mut templates: Vec<String> = vec![]; 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); let mut path = PathBuf::from(srcfile);
path.pop(); path.pop();
path path
} else { } else {
PathBuf::from("ftl") PathBuf::from("../ftl")
}; };
let dir = ftl_base.join("core");
for entry in fs::read_dir(dir).unwrap() { for entry in fs::read_dir(dir).unwrap() {
let entry = entry.unwrap(); let entry = entry.unwrap();
let fname = entry.file_name().into_string().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 { FTLData {
templates, templates,
translations: Default::default(), translations: Default::default(),

View file

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