From 5c3a425654cabe432258d66fe1179cd5c3b7a2b4 Mon Sep 17 00:00:00 2001 From: Austin Seipp Date: Sun, 6 Aug 2023 17:50:00 -0500 Subject: [PATCH] cli: add BUILD files The `grammar` macro from `pest_derive` doesn't actually interpret the given file as relative in our case, so we have to give it the fully qualified relative path which exists in the `buck-out/` dir. Signed-off-by: Austin Seipp --- cli/BUILD | 38 ++++++++++++++++++++++++++ cli/BUILD.deps.bzl | 55 ++++++++++++++++++++++++++++++++++++++ cli/PACKAGE | 4 +++ cli/examples/BUILD | 23 ++++++++++++++++ cli/src/template_parser.rs | 6 +++++ 5 files changed, 126 insertions(+) create mode 100644 cli/BUILD create mode 100644 cli/BUILD.deps.bzl create mode 100644 cli/PACKAGE create mode 100644 cli/examples/BUILD diff --git a/cli/BUILD b/cli/BUILD new file mode 100644 index 0000000000..a00c89bcf9 --- /dev/null +++ b/cli/BUILD @@ -0,0 +1,38 @@ + +load("//buck/shims/jj.bzl", "jj") +load("//cli/BUILD.deps.bzl", "JJ_CLI_DEPS") + +alias( + # NOTE: default target for this package + name = 'cli', + actual = ':jj', +) + +jj.rust_library( + name = "jj-cli", + srcs = glob([ + "src/**/*.rs", + "src/**/*.toml", + "src/**/*.json", + "src/**/*.pest", + ], exclude = [ + "**/main.rs" + ]), + + features = [ + "watchman", + "git", + ], + + deps = JJ_CLI_DEPS, +) + +jj.rust_binary( + name = 'jj', + srcs = ['src/main.rs'], + features = [ + "watchman", + "git", + ], + deps = [ ":jj-cli" ] + JJ_CLI_DEPS, +) diff --git a/cli/BUILD.deps.bzl b/cli/BUILD.deps.bzl new file mode 100644 index 0000000000..f95804303f --- /dev/null +++ b/cli/BUILD.deps.bzl @@ -0,0 +1,55 @@ + +JJ_CLI_DEPS = [ + # CARGO-SYNC-START: dependencies + '//lib:jj-lib', + 'third-party//rust:bstr', + 'third-party//rust:chrono', + 'third-party//rust:clap', + 'third-party//rust:clap-markdown', + 'third-party//rust:clap_complete', + 'third-party//rust:clap_complete_nushell', + 'third-party//rust:clap_mangen', + 'third-party//rust:config', + 'third-party//rust:criterion', + 'third-party//rust:crossterm', + 'third-party//rust:dirs', + 'third-party//rust:dunce', + 'third-party//rust:esl01-renderdag', + 'third-party//rust:futures', + 'third-party//rust:git2', + 'third-party//rust:gix', + 'third-party//rust:hex', + 'third-party//rust:indexmap', + 'third-party//rust:indoc', + 'third-party//rust:itertools', + 'third-party//rust:maplit', + 'third-party//rust:minus', + 'third-party//rust:once_cell', + 'third-party//rust:pest', + 'third-party//rust:pest_derive', + 'third-party//rust:pollster', + 'third-party//rust:rayon', + 'third-party//rust:regex', + 'third-party//rust:rpassword', + 'third-party//rust:scm-record', + 'third-party//rust:serde', + 'third-party//rust:slab', + 'third-party//rust:strsim', + 'third-party//rust:tempfile', + 'third-party//rust:textwrap', + 'third-party//rust:thiserror', + 'third-party//rust:timeago', + 'third-party//rust:toml_edit', + 'third-party//rust:tracing', + 'third-party//rust:tracing-chrome', + 'third-party//rust:tracing-subscriber', + 'third-party//rust:unicode-width', + # CARGO-SYNC-END +] + select({ + "config//os:windows": [], + "DEFAULT": [ + # CARGO-SYNC-START: dependencies@cfg(unix) + 'third-party//rust:libc', + # CARGO-SYNC-END + ], +}) diff --git a/cli/PACKAGE b/cli/PACKAGE new file mode 100644 index 0000000000..5019e6766b --- /dev/null +++ b/cli/PACKAGE @@ -0,0 +1,4 @@ + +package( + visibility = [ 'PUBLIC' ], +) diff --git a/cli/examples/BUILD b/cli/examples/BUILD new file mode 100644 index 0000000000..437e77f085 --- /dev/null +++ b/cli/examples/BUILD @@ -0,0 +1,23 @@ + +load("//buck/shims/jj.bzl", "jj") +load("//cli/BUILD.deps.bzl", "JJ_CLI_DEPS") + +EXAMPLES = [ + 'custom-backend', + 'custom-command', + 'custom-commit-templater', + 'custom-global-flag', + 'custom-operation-templater', + 'custom-working-copy', +] + +[ + jj.rust_binary( + name = name, + srcs = glob(["{}/**/*.rs".format(name)]), + deps = [ + "//cli:jj-cli", + "third-party//rust:async-trait", + ] + JJ_CLI_DEPS, + ) for name in EXAMPLES +] diff --git a/cli/src/template_parser.rs b/cli/src/template_parser.rs index 99f418b0e8..5756485ca1 100644 --- a/cli/src/template_parser.rs +++ b/cli/src/template_parser.rs @@ -28,6 +28,12 @@ use pest::Parser; use pest_derive::Parser; use thiserror::Error; +#[cfg(buck_build)] +#[derive(Parser)] +#[grammar = "cli/src/template.pest"] +struct TemplateParser; + +#[cfg(not(buck_build))] #[derive(Parser)] #[grammar = "template.pest"] struct TemplateParser;