Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial example of generating ts_project #4

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ts_gazelle/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
common --symlink_prefix=/
13 changes: 13 additions & 0 deletions ts_gazelle/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
load("@bazel_gazelle//:def.bzl", "gazelle")

gazelle(
name = "gazelle",
data = [],
gazelle = "@aspect_rules_ts_gazelle//:gazelle_js_binary",
)

ts_project(
name = "ts_gazelle",
srcs = ["lib/foo.ts"],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbedard I confirmed that from userland we get the same behavior as the gazelle_generation_test: we don't ever create new BUILD files

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems to be the case. As I understand it gazelle invokes the GenerateRules method based on which BUILDs already exist.

See the sub-directories logic which I essentially copied from python:
https://github.com/bazelbuild/rules_python/blob/0.8.1/gazelle/generate.go#L105
https://github.com/aspect-build/rules_ts/blob/2ae033f0e4ea0ec1081de67231f7c07347797d96/gazelle/generate.go#L192

)
55 changes: 55 additions & 0 deletions ts_gazelle/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "io_bazel_rules_go",
sha256 = "f2dcd210c7095febe54b804bb1cd3a58fe8435a909db2ec04e31542631cf715c",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.31.0/rules_go-v0.31.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.31.0/rules_go-v0.31.0.zip",
],
)

http_archive(
name = "bazel_gazelle",
sha256 = "31453a0f1200bc2cd6ecba2314e1942bac7f7da99729eb4f1dcdbd9791e3f989",
strip_prefix = "bazel-gazelle-b458bec82e613d1bac59afbb5b8b3d5846771b01",
urls = [
"https://github.com/bazelbuild/bazel-gazelle/archive/b458bec82e613d1bac59afbb5b8b3d5846771b01.tar.gz",
],
)

[
http_archive(
name = "_".join(["aspect_rules_ts"] + r),
sha256 = "1b0d296ae22ecc194be7010f8de00dac37f8d20825641660ea7f617c7eea462a",
strip_prefix = "/".join(["rules_ts-2ae033f0e4ea0ec1081de67231f7c07347797d96"] + r),
urls = ["https://github.com/aspect-build/rules_ts/archive/2ae033f0e4ea0ec1081de67231f7c07347797d96.zip"],
)
# The gazelle plugin is in a nested workspace in rules_ts
for r in [[], ["gazelle"]]
]

load("@aspect_rules_ts_gazelle//:deps.bzl", "gazelle_deps")

gazelle_deps()

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

go_rules_dependencies()

go_register_toolchains(version = "1.18.1")

# gazelle:repository_macro deps.bzl%gazelle_deps
gazelle_dependencies()

load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")

rules_ts_dependencies()

load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

nodejs_register_toolchains(
name = "node",
node_version = DEFAULT_NODE_VERSION,
)
280 changes: 280 additions & 0 deletions ts_gazelle/deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
"This file managed by `bazel run //:update_go_deps`"

load(
"@bazel_gazelle//:deps.bzl",
_go_repository = "go_repository",
)

def go_repository(name, **kwargs):
if name not in native.existing_rules():
_go_repository(name = name, **kwargs)

def gazelle_deps():
"Fetch go dependencies"
go_repository(
name = "co_honnef_go_tools",
importpath = "honnef.co/go/tools",
sum = "h1:/hemPrYIhOhy8zYrNj+069zDB68us2sMGsfkFJO0iZs=",
version = "v0.0.0-20190523083050-ea95bdfd59fc",
)

go_repository(
name = "com_github_bazelbuild_bazel_gazelle",
importpath = "github.com/bazelbuild/bazel-gazelle",
sum = "h1:umlCZxzCEr8BHdesfY2sv5T8NTv9+JiPL8f/Vk83Aag=",
version = "v0.25.0",
)
go_repository(
name = "com_github_bazelbuild_buildtools",
build_naming_convention = "go_default_library",
importpath = "github.com/bazelbuild/buildtools",
sum = "h1:ox8T5nCkvLflRgKZ6uzzdvLDN3gbNZBgLBqA5Xgn7QA=",
version = "v0.0.0-20220323134444-a9f46b2bb3de",
)
go_repository(
name = "com_github_bazelbuild_rules_go",
importpath = "github.com/bazelbuild/rules_go",
sum = "h1:8/MDe6zCE7nYKXhlbamM1izUgJjw2ce7M5kd4QKF/3Y=",
version = "v0.31.0",
)
go_repository(
name = "com_github_bmatcuk_doublestar",
importpath = "github.com/bmatcuk/doublestar",
sum = "h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0=",
version = "v1.3.4",
)
go_repository(
name = "com_github_bmatcuk_doublestar_v4",
importpath = "github.com/bmatcuk/doublestar/v4",
sum = "h1:X0krlUVAVmtr2cRoTqR8aDMrDqnB36ht8wpWTiQ3jsA=",
version = "v4.0.2",
)

go_repository(
name = "com_github_burntsushi_toml",
importpath = "github.com/BurntSushi/toml",
sum = "h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=",
version = "v0.3.1",
)
go_repository(
name = "com_github_census_instrumentation_opencensus_proto",
importpath = "github.com/census-instrumentation/opencensus-proto",
sum = "h1:glEXhBS5PSLLv4IXzLA5yPRVX4bilULVyxxbrfOtDAk=",
version = "v0.2.1",
)
go_repository(
name = "com_github_chzyer_logex",
importpath = "github.com/chzyer/logex",
sum = "h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=",
version = "v1.1.10",
)
go_repository(
name = "com_github_chzyer_readline",
importpath = "github.com/chzyer/readline",
sum = "h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=",
version = "v0.0.0-20180603132655-2972be24d48e",
)
go_repository(
name = "com_github_chzyer_test",
importpath = "github.com/chzyer/test",
sum = "h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=",
version = "v0.0.0-20180213035817-a1ea475d72b1",
)
go_repository(
name = "com_github_client9_misspell",
importpath = "github.com/client9/misspell",
sum = "h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=",
version = "v0.3.4",
)

go_repository(
name = "com_github_emirpasic_gods",
importpath = "github.com/emirpasic/gods",
sum = "h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=",
version = "v1.12.0",
)
go_repository(
name = "com_github_envoyproxy_go_control_plane",
importpath = "github.com/envoyproxy/go-control-plane",
sum = "h1:4cmBvAEBNJaGARUEs3/suWRyfyBfhf7I60WBZq+bv2w=",
version = "v0.9.1-0.20191026205805-5f8ba28d4473",
)
go_repository(
name = "com_github_envoyproxy_protoc_gen_validate",
importpath = "github.com/envoyproxy/protoc-gen-validate",
sum = "h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A=",
version = "v0.1.0",
)
go_repository(
name = "com_github_evanw_esbuild",
importpath = "github.com/evanw/esbuild",
sum = "h1:wxnnt00/s35zO1tPy41rAJF5U+bR8oPRbyvC0zU0tBE=",
version = "v0.14.29",
)

go_repository(
name = "com_github_fsnotify_fsnotify",
importpath = "github.com/fsnotify/fsnotify",
sum = "h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI=",
version = "v1.5.1",
)

go_repository(
name = "com_github_golang_glog",
importpath = "github.com/golang/glog",
sum = "h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=",
version = "v0.0.0-20160126235308-23def4e6c14b",
)
go_repository(
name = "com_github_golang_mock",
importpath = "github.com/golang/mock",
sum = "h1:G5FRp8JnTd7RQH5kemVNlMeyXQAztQ3mOWV95KxsXH8=",
version = "v1.1.1",
)
go_repository(
name = "com_github_golang_protobuf",
importpath = "github.com/golang/protobuf",
sum = "h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=",
version = "v1.4.3",
)

go_repository(
name = "com_github_google_go_cmp",
importpath = "github.com/google/go-cmp",
sum = "h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=",
version = "v0.5.7",
)

go_repository(
name = "com_github_pelletier_go_toml",
importpath = "github.com/pelletier/go-toml",
sum = "h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM=",
version = "v1.9.4",
)
go_repository(
name = "com_github_pmezard_go_difflib",
importpath = "github.com/pmezard/go-difflib",
sum = "h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=",
version = "v1.0.0",
)
go_repository(
name = "com_github_prometheus_client_model",
importpath = "github.com/prometheus/client_model",
sum = "h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM=",
version = "v0.0.0-20190812154241-14fe0d1b01d4",
)
go_repository(
name = "com_github_yuin_goldmark",
importpath = "github.com/yuin/goldmark",
sum = "h1:/vn0k+RBvwlxEmP5E7SZMqNxPhfMVFEJiykr15/0XKM=",
version = "v1.4.1",
)
go_repository(
name = "com_google_cloud_go",
importpath = "cloud.google.com/go",
sum = "h1:e0WKqKTd5BnrG8aKH3J3h+QvEIQtSUcf2n5UZ5ZgLtQ=",
version = "v0.26.0",
)

go_repository(
name = "net_starlark_go",
importpath = "go.starlark.net",
sum = "h1:xwwDQW5We85NaTk2APgoN9202w/l0DVGp+GZMfsrh7s=",
version = "v0.0.0-20210223155950-e043a3d3c984",
)
go_repository(
name = "org_golang_google_appengine",
importpath = "google.golang.org/appengine",
sum = "h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=",
version = "v1.4.0",
)
go_repository(
name = "org_golang_google_genproto",
importpath = "google.golang.org/genproto",
sum = "h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=",
version = "v0.0.0-20200526211855-cb27e3aa2013",
)
go_repository(
name = "org_golang_google_grpc",
importpath = "google.golang.org/grpc",
sum = "h1:rRYRFMVgRv6E0D70Skyfsr28tDXIuuPZyWGMPdMcnXg=",
version = "v1.27.0",
)
go_repository(
name = "org_golang_google_protobuf",
importpath = "google.golang.org/protobuf",
sum = "h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=",
version = "v1.25.0",
)

go_repository(
name = "org_golang_x_crypto",
importpath = "golang.org/x/crypto",
sum = "h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=",
version = "v0.0.0-20190308221718-c2843e01d9a2",
)
go_repository(
name = "org_golang_x_exp",
importpath = "golang.org/x/exp",
sum = "h1:c2HOrn5iMezYjSlGPncknSEr/8x5LELb/ilJbXi9DEA=",
version = "v0.0.0-20190121172915-509febef88a4",
)
go_repository(
name = "org_golang_x_lint",
importpath = "golang.org/x/lint",
sum = "h1:XQyxROzUlZH+WIQwySDgnISgOivlhjIEwaQaJEJrrN0=",
version = "v0.0.0-20190313153728-d0100b6bd8b3",
)

go_repository(
name = "org_golang_x_mod",
importpath = "golang.org/x/mod",
sum = "h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=",
version = "v0.6.0-dev.0.20220106191415-9b9b3d81d5e3",
)
go_repository(
name = "org_golang_x_net",
importpath = "golang.org/x/net",
sum = "h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY=",
version = "v0.0.0-20211015210444-4f30a5c0130f",
)
go_repository(
name = "org_golang_x_oauth2",
importpath = "golang.org/x/oauth2",
sum = "h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs=",
version = "v0.0.0-20180821212333-d2e6202438be",
)

go_repository(
name = "org_golang_x_sync",
importpath = "golang.org/x/sync",
sum = "h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=",
version = "v0.0.0-20210220032951-036812b2e83c",
)
go_repository(
name = "org_golang_x_sys",
importpath = "golang.org/x/sys",
sum = "h1:rlezHXNlxYWvBCzNses9Dlc7nGFaNMJeqLolcmQSSZY=",
version = "v0.0.0-20220330033206-e17cdc41300f",
)
go_repository(
name = "org_golang_x_text",
importpath = "golang.org/x/text",
sum = "h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=",
version = "v0.3.7",
)
go_repository(
name = "org_golang_x_tools",
build_directives = [
"gazelle:exclude **/testdata/**/*",
],
importpath = "golang.org/x/tools",
sum = "h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20=",
version = "v0.1.10",
)
go_repository(
name = "org_golang_x_xerrors",
importpath = "golang.org/x/xerrors",
sum = "h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=",
version = "v0.0.0-20200804184101-5ec99f83aff1",
)
1 change: 1 addition & 0 deletions ts_gazelle/lib/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const a:string = ''
1 change: 1 addition & 0 deletions ts_gazelle/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}