diff -urN a/BUILD.bazel b/BUILD.bazel --- a/BUILD.bazel 2023-09-25 16:52:51.395439671 +0000 +++ b/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -load("@bazel_gazelle//:def.bzl", "gazelle") -load("//buildifier:def.bzl", "buildifier") - -exports_files([ - "LICENSE", - "launcher.js", -]) - -config_setting( - name = "windows", - values = {"cpu": "x64_windows"}, -) - -filegroup( - name = "warnings", - srcs = ["WARNINGS.md"], - visibility = ["//warn/docs:__pkg__"], -) - -test_suite( - name = "tests", - tests = [ - "//api_proto:api.gen.pb.go_checkshtest", - "//build:build_test", - "//build_proto:build.gen.pb.go_checkshtest", - "//buildifier:buildifier_integration_test", - "//deps_proto:deps.gen.pb.go_checkshtest", - "//edit:edit_test", - "//extra_actions_base_proto:extra_actions_base.gen.pb.go_checkshtest", - "//labels:labels_test", - "//lang:tables.gen.go_checkshtest", - "//tables:tables_test", - "//warn:warn_test", - "//warn/docs:docs_test", - "//wspace:wspace_test", - ], -) - -#gazelle:go_naming_convention import_alias -gazelle( - name = "gazelle", - prefix = "github.com/bazelbuild/buildtools", -) - -buildifier( - name = "buildifier", -) diff -urN a/buildifier/npm/BUILD.bazel b/buildifier/npm/BUILD.bazel --- a/buildifier/npm/BUILD.bazel 2023-09-25 16:52:51.403439550 +0000 +++ b/buildifier/npm/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000 @@ -1,61 +0,0 @@ -load("@bazel_skylib//rules:copy_file.bzl", "copy_file") -load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test", "pkg_npm") - -copy_file( - name = "copy_LICENSE", - src = "//:LICENSE", - out = "LICENSE", -) - -genrule( - name = "buildifier_launcher", - srcs = ["//:launcher.js"], - outs = ["buildifier.js"], - cmd = "sed s/_TOOL_/buildifier/ $< > $@", -) - -# npm rules live in this subdirectory to avoid a load() statement -# in the parent package leaking to users. This means we need -# to copy the output files so the pkg_npm will find them in the -# output directory for this package. -_PARENT_PACKAGE_FILES = [ - "README.md", - "buildifier-darwin_amd64", - "buildifier-darwin_arm64", - "buildifier-linux_amd64", - "buildifier-linux_arm64", - "buildifier-windows_amd64.exe", -] - -[ - copy_file( - name = "copy_%s" % s, - # go_binary doesn't give a predeclared output for - # the file in "out" so we have to construct a - # label to reference the go_binary rule itself. - src = "//buildifier:%s" % s.replace("_arm64", "-arm64").split("_amd64")[0], - out = s, - ) - for s in _PARENT_PACKAGE_FILES -] - -pkg_npm( - name = "buildifier", - package_name = "@bazel/buildifier", - srcs = [ - "package.json", - ], - substitutions = { - "0.0.0-PLACEHOLDER": "{BUILD_SCM_VERSION}", - }, - deps = [ - "LICENSE", - "buildifier.js", - ] + _PARENT_PACKAGE_FILES, -) - -nodejs_test( - name = "integration_test", - data = [":buildifier"], - entry_point = "test.js", -) diff -urN a/buildifier/npm/package.json b/buildifier/npm/package.json --- a/buildifier/npm/package.json 2023-09-25 16:52:51.403439550 +0000 +++ b/buildifier/npm/package.json 1970-01-01 00:00:00.000000000 +0000 @@ -1,19 +0,0 @@ -{ - "name": "@bazel/buildifier", - "description": "A tool for formatting bazel BUILD and .bzl files", - "version": "0.0.0-PLACEHOLDER", - "license": "Apache-2.0", - "bin": { - "buildifier": "buildifier.js" - }, - "keywords": [ - "bazel" - ], - "repository": { - "type": "git", - "url": "https://github.com/bazelbuild/buildtools.git" - }, - "bugs": { - "url": "https://github.com/bazelbuild/buildtools/issues" - } -} diff -urN a/buildifier/npm/test.js b/buildifier/npm/test.js --- a/buildifier/npm/test.js 2023-09-25 16:52:51.403439550 +0000 +++ b/buildifier/npm/test.js 1970-01-01 00:00:00.000000000 +0000 @@ -1,12 +0,0 @@ -const dir = require('path').join( - process.env['TEST_SRCDIR'], - process.env['BAZEL_WORKSPACE'], - 'buildifier/npm/buildifier'); -process.chdir(dir); -const {stdout} = require('child_process').spawnSync( - process.argv0, - ['./buildifier.js', '--help'], - {encoding: 'utf-8'}); -if (!/usage: buildifier/.test(stdout)) { - throw new Error('buildifier --help should include usage: buildifier'); -} diff -urN a/buildozer/npm/BUILD.bazel b/buildozer/npm/BUILD.bazel --- a/buildozer/npm/BUILD.bazel 2023-09-25 16:52:51.403439550 +0000 +++ b/buildozer/npm/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000 @@ -1,83 +0,0 @@ -load("@bazel_skylib//rules:copy_file.bzl", "copy_file") -load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test", "pkg_npm") -load("@buildozer_npm_deps//typescript:index.bzl", "tsc") - -copy_file( - name = "copy_LICENSE", - src = "//:LICENSE", - out = "LICENSE", -) - -tsc( - name = "compile_ts", - outs = [ - "index.d.ts", - "index.js", - ], - args = [ - "$(execpath index.ts)", - "--outDir $(RULEDIR)", - "--target es2015", - "--module commonjs", - "--declaration", - ], - data = [ - "index.ts", - "@buildozer_npm_deps//@types/node", - ], -) - -genrule( - name = "buildozer_launcher", - srcs = ["//:launcher.js"], - outs = ["buildozer.js"], - cmd = "sed s/_TOOL_/buildozer/ $< > $@", -) - -# npm rules live in this subdirectory to avoid a load() statement -# in the parent package leaking to users. This means we need -# to copy the output files so the pkg_npm will find them in the -# output directory for this package. -_PARENT_PACKAGE_FILES = [ - "README.md", - "buildozer-darwin_amd64", - "buildozer-darwin_arm64", - "buildozer-linux_amd64", - "buildozer-linux_arm64", - "buildozer-windows_amd64.exe", -] - -[ - copy_file( - name = "copy_%s" % s, - # go_binary doesn't give a predeclared output for - # the file in "out" so we have to construct a - # label to reference the go_binary rule itself. - src = "//buildozer:%s" % s.replace("_arm64", "-arm64").split("_amd64")[0], - out = s, - ) - for s in _PARENT_PACKAGE_FILES -] - -pkg_npm( - name = "buildozer", - package_name = "@bazel/buildozer", - srcs = [ - "package.json", - ], - substitutions = { - "0.0.0-PLACEHOLDER": "{BUILD_SCM_VERSION}", - }, - deps = [ - "LICENSE", - "buildozer.js", - "index.d.ts", - "index.js", - ] + _PARENT_PACKAGE_FILES, -) - -nodejs_test( - name = "integration_test", - data = [":buildozer"], - entry_point = "test.js", -) diff -urN a/buildozer/npm/.gitignore b/buildozer/npm/.gitignore --- a/buildozer/npm/.gitignore 2023-09-25 16:52:51.403439550 +0000 +++ b/buildozer/npm/.gitignore 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -node_modules \ No newline at end of file diff -urN a/buildozer/npm/index.ts b/buildozer/npm/index.ts --- a/buildozer/npm/index.ts 2023-09-25 16:52:51.403439550 +0000 +++ b/buildozer/npm/index.ts 1970-01-01 00:00:00.000000000 +0000 @@ -1,61 +0,0 @@ -/** - * @fileoverview NodeJS binding to run the buildozer command through a convenient API - */ -import {spawnSync} from 'child_process'; -// Use require() here since the file doesn't exist at design-time; -// bazel will copy the /launcher.js in this repo while building the package -const {getNativeBinary} = require('./buildozer'); - -/** - * Models the data structure of a buildozer command file. - * You should group as many commands as possible into one call to `run` for efficiency. - * https://github.com/bazelbuild/buildtools/tree/master/buildozer#do-multiple-changes-at-once - */ -export interface CommandBatch { - /** - * Each entry is a buildozer edit command like 'new cc_library foo' or a print command - * @see https://github.com/bazelbuild/buildtools/tree/master/buildozer#edit-commands - */ - commands: string[]; - /** - * Each entry is like a Bazel label - * @see https://github.com/bazelbuild/buildtools/tree/master/buildozer#targets - */ - targets: string[]; -}; - -/** - * run buildozer with a list of commands - * @see https://github.com/bazelbuild/buildtools/tree/master/buildozer#do-multiple-changes-at-once - * @returns The standard out of the buildozer command, split by lines - */ -export function run(...commands: CommandBatch[]): string[] { - return runWithOptions(commands, {}); -} - -/** - * run buildozer with a list of commands - * @param commands a list of CommandBatch to pass to buildozer - * @param options Options to pass to spawn - * @param flags any buildozer flags to pass - */ -export function runWithOptions(commands: CommandBatch[], options: {cwd?: string}, flags: string[] = []): string[] { - // From https://github.com/bazelbuild/buildtools/tree/master/buildozer#usage: - // Here, label-list is a space-separated list of Bazel labels, - // for example //path/to/pkg1:rule1 //path/to/pkg2:rule2. - // Buildozer reads commands from FILE (- for stdin - // (format: |-separated command line arguments to buildozer, excluding flags)) - const input = commands.map(c => [...c.commands, c.targets.join(',')].join('|')).join('\n'); - const {stdout, stderr, status, error} = spawnSync(getNativeBinary(), flags.concat([ - '-f', '-' /* read commands from stdin */ - ]), { - ...options, - input, - encoding: 'utf-8', - }); - // https://github.com/bazelbuild/buildtools/tree/master/buildozer#error-code - if (status == 0 || status == 3) return stdout.trim().split('\n').filter(l => !!l); - - console.error(`buildozer exited with status ${status}\n${stderr}`); - throw error; -} diff -urN a/buildozer/npm/package.json b/buildozer/npm/package.json --- a/buildozer/npm/package.json 2023-09-25 16:52:51.403439550 +0000 +++ b/buildozer/npm/package.json 1970-01-01 00:00:00.000000000 +0000 @@ -1,23 +0,0 @@ -{ - "name": "@bazel/buildozer", - "description": "A command line tool to rewrite multiple BUILD files using standard commands", - "version": "0.0.0-PLACEHOLDER", - "license": "Apache-2.0", - "bin": { - "buildozer": "buildozer.js" - }, - "keywords": [ - "bazel" - ], - "repository": { - "type": "git", - "url": "https://github.com/bazelbuild/buildtools.git" - }, - "bugs": { - "url": "https://github.com/bazelbuild/buildtools/issues" - }, - "devDependencies": { - "@types/node": "^13.9.0", - "typescript": "^3.8.3" - } -} diff -urN a/buildozer/npm/package-lock.json b/buildozer/npm/package-lock.json --- a/buildozer/npm/package-lock.json 2023-09-25 16:52:51.403439550 +0000 +++ b/buildozer/npm/package-lock.json 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ -{ - "name": "@bazel/buildozer", - "version": "0.0.0-PLACEHOLDER", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "@types/node": { - "version": "13.9.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-13.9.0.tgz", - "integrity": "sha512-0ARSQootUG1RljH2HncpsY2TJBfGQIKOOi7kxzUY6z54ePu/ZD+wJA8zI2Q6v8rol2qpG/rvqsReco8zNMPvhQ==", - "dev": true - }, - "typescript": { - "version": "3.8.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz", - "integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==", - "dev": true - } - } -} diff -urN a/buildozer/npm/test.js b/buildozer/npm/test.js --- a/buildozer/npm/test.js 2023-09-25 16:52:51.403439550 +0000 +++ b/buildozer/npm/test.js 1970-01-01 00:00:00.000000000 +0000 @@ -1,23 +0,0 @@ -const dir = require('path').join( - process.env['TEST_SRCDIR'], - process.env['BAZEL_WORKSPACE'], - 'buildozer/npm/buildozer'); -process.chdir(dir); -const {stderr} = require('child_process').spawnSync( - process.argv0, - ['./buildozer.js', '--help'], - {encoding: 'utf-8'}); -if (!/Usage of .*buildozer/.test(stderr)) { - throw new Error('buildozer --help should include usage: buildifier'); -} - -process.chdir(process.env['TEST_TMPDIR']); -const buildozer = require(dir); -const fs = require('fs'); -fs.mkdirSync('foo'); -fs.writeFileSync('foo/BUILD', ''); -buildozer.run({commands: ['new_load //:some.bzl some_rule'], targets: ['//foo:__pkg__']}); -const content = fs.readFileSync('foo/BUILD', 'utf-8'); -if (!content.includes('load("//:some.bzl", "some_rule")')) { - throw new Error('buildozer generated file should include load statement'); -} diff -urN a/WORKSPACE b/WORKSPACE --- a/WORKSPACE 2023-09-25 16:52:51.395439671 +0000 +++ b/WORKSPACE 1970-01-01 00:00:00.000000000 +0000 @@ -1,95 +0,0 @@ -workspace(name = "com_github_bazelbuild_buildtools") - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( - name = "io_bazel_rules_go", - sha256 = "6dc2da7ab4cf5d7bfc7c949776b1b7c733f05e56edc4bcd9022bb249d2e2a996", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.39.1/rules_go-v0.39.1.zip", - "https://github.com/bazelbuild/rules_go/releases/download/v0.39.1/rules_go-v0.39.1.zip", - ], -) - -load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") - -go_rules_dependencies() - -go_register_toolchains(version = "1.20.3") - -http_archive( - name = "bazel_gazelle", - sha256 = "727f3e4edd96ea20c29e8c2ca9e8d2af724d8c7778e7923a854b2c80952bc405", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.30.0/bazel-gazelle-v0.30.0.tar.gz", - "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.30.0/bazel-gazelle-v0.30.0.tar.gz", - ], -) - -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository") - -gazelle_dependencies() - -go_repository( - name = "skylark_syntax", - importpath = "go.starlark.net", - sum = "h1:Qoe+9POtDT51UBQ8XEnS9QKeHDQzEl2QRh3eok9R4aw=", - version = "v0.0.0-20200203144150-6677ee5c7211", -) - -http_archive( - name = "com_google_protobuf", - sha256 = "9b4ee22c250fe31b16f1a24d61467e40780a3fbb9b91c3b65be2a376ed913a1a", - strip_prefix = "protobuf-3.13.0", - urls = [ - "https://github.com/protocolbuffers/protobuf/archive/v3.13.0.tar.gz", - ], -) - -go_repository( - name = "com_github_google_go_cmp", - importpath = "github.com/google/go-cmp", - tag = "v0.5.9", -) - -load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") - -protobuf_deps() - -http_archive( - name = "rules_proto", - sha256 = "8e7d59a5b12b233be5652e3d29f42fba01c7cbab09f6b3a8d0a57ed6d1e9a0da", - strip_prefix = "rules_proto-7e4afce6fe62dbff0a4a03450143146f9f2d7488", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/7e4afce6fe62dbff0a4a03450143146f9f2d7488.tar.gz", - "https://github.com/bazelbuild/rules_proto/archive/7e4afce6fe62dbff0a4a03450143146f9f2d7488.tar.gz", - ], -) - -load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains") - -rules_proto_dependencies() - -rules_proto_toolchains() - -load("@com_github_bazelbuild_buildtools//buildifier:deps.bzl", "buildifier_dependencies") - -buildifier_dependencies() - -# We don't use any nodejs but this includes a rule for publishing releases to npm -http_archive( - name = "build_bazel_rules_nodejs", - sha256 = "8a7c981217239085f78acc9898a1f7ba99af887c1996ceb3b4504655383a2c3c", - urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/4.0.0/rules_nodejs-4.0.0.tar.gz"], -) - -load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "npm_install") - -node_repositories(node_version = "16.7.0") - -# Fetch third-party dependencies for building npm packages -npm_install( - name = "buildozer_npm_deps", - package_json = "//buildozer/npm:package.json", - package_lock_json = "//buildozer/npm:package-lock.json", -)