Skip to content

Commit

Permalink
Set correct version
Browse files Browse the repository at this point in the history
  • Loading branch information
Matts966 committed Apr 17, 2022
1 parent 0daff93 commit 87f1fd3
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# widely accepted by compilers. This may lead to strange behavior or compiler
# errors in earlier compilers.
build --cxxopt="-std=c++1z"
build --sandbox_debug --verbose_failures --cxxopt="-DNDEBUG"
build --workspace_status_command "tools/workspace_status.sh"
# By default, we don't suppress any warnings, to get clang-specific warning
# suppression you can invoke with --config=clang
build:clang --cxxopt=-Wno-deprecated-declarations
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Cache
uses: pat-s/[email protected]
with:
Expand Down Expand Up @@ -43,6 +44,7 @@ jobs:
uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Cache
uses: pat-s/[email protected]
with:
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
## ZetaSQL Formatter

[![release](https://github.com/Matts966/zetasql-formatter/workflows/release/badge.svg?event=create)](https://github.com/Matts966/zetasql-formatter/actions?query=event%3Acreate+workflow%3Arelease+)
[![test](https://github.com/Matts966/zetasql-formatter/workflows/test/badge.svg?branch=formatter)](https://github.com/Matts966/zetasql-formatter/actions?query=branch%main+workflow%3Atest+)
[![build](https://github.com/Matts966/zetasql-formatter/workflows/Build/badge.svg?branch=main)](https://github.com/Matts966/zetasql-formatter/actions?query=branch%main+workflow%3ABuild+)

<p align="center">
<img src="./docs/changes.png">
Expand Down
6 changes: 6 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,9 @@ load("@com_google_zetasql//bazel:zetasql_deps_step_4.bzl", "zetasql_deps_step_4"

zetasql_deps_step_4()

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(
name = "com_github_gflags_gflags",
remote = "https://github.com/gflags/gflags.git",
tag = "v2.2.2"
)
Binary file added docs/changes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package(

exports_files([
"pom-template.xml",
"workspace_status.sh",
])

bzl_library(
Expand Down
3 changes: 3 additions & 0 deletions tools/workspace_status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "STABLE_BUILD_GIT_DESCRIBE $(git describe --tags)"
21 changes: 19 additions & 2 deletions zetasql/tools/zetasql-formatter/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,31 @@ package(
default_visibility = ["//zetasql/base:zetasql_implementation"],
)

genrule(
name = "gen_version",
outs = ["version.h"],
cmd = """
TAG=$$(sed -n 's/STABLE_BUILD_GIT_DESCRIBE //p' bazel-out/stable-status.txt)
cat > $@ <<EOF
constexpr char ZSQL_FMT_VERSION_STRING[] = "$$TAG";
EOF
""",
stamp = True,
)

cc_library(
name = "version",
hdrs = ["version.h"],
)

cc_binary(
name = "format",
srcs = ["format.cc"],
deps = [
":version",
"//zetasql/public:sql_formatter",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/flags:parse",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:optional",
"@com_github_gflags_gflags//:gflags",
],
)
17 changes: 9 additions & 8 deletions zetasql/tools/zetasql-formatter/format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#include "zetasql/base/logging.h"
#include "zetasql/base/status.h"
#include "zetasql/public/sql_formatter.h"
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "absl/strings/strip.h"
#include "absl/strings/str_join.h"
#include "gflags/gflags.h"
#include "zetasql/tools/zetasql-formatter/version.h"

int format(const std::filesystem::path& file_path) {
std::string formatted;
Expand Down Expand Up @@ -38,14 +38,15 @@ int format(const std::filesystem::path& file_path) {
// format formats all sql files in specified directory and returns code 0
// if all files are formatted and 1 if error occurs or any file is formatted.
int main(int argc, char* argv[]) {
const char kUsage[] =
"Usage: format <directory paths...>\n";
std::vector<char*> args = absl::ParseCommandLine(argc, argv);
const auto kUsage = "Usage: zetasql-formatter <paths...>";
gflags::SetUsageMessage(kUsage);
gflags::SetVersionString(ZSQL_FMT_VERSION_STRING);
gflags::ParseCommandLineFlags(&argc, &argv, true);
if (argc <= 1) {
ZETASQL_LOG(QFATAL) << kUsage;
std::cerr << kUsage << std::endl;
return 1;
}
std::vector<char*> remaining_args(args.begin() + 1, args.end());

std::vector<std::string> remaining_args(argv + 1, argv + argc);
int rc = 0;
for (const auto& path : remaining_args) {
if (std::filesystem::is_regular_file(path)) {
Expand Down

0 comments on commit 87f1fd3

Please sign in to comment.