Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

16
build/linter/BUILD Normal file
View File

@@ -0,0 +1,16 @@
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//build/linter/internal:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

76
build/linter/deps.bzl Normal file
View File

@@ -0,0 +1,76 @@
# ****************************************************************
# List of external dependencies
# ****************************************************************
# These deps are derived empirically, starting from the grpc tag and
# then updating other dependents to the master commit.
DEPS = {
"com_github_alecthomas_gometalinter": {
"rule": "go_repository",
"importpath": "github.com/alecthomas/gometalinter",
"tag": "v2.0.5",
},
"com_github_tsenart_deadcode": {
"rule": "go_repository",
"importpath": "github.com/tsenart/deadcode",
},
"com_github_mdempsky_maligned": {
"rule": "go_repository",
"importpath": "github.com/mdempsky/maligned",
},
"com_github_mibk_dupl": {
"rule": "go_repository",
"importpath": "github.com/mibk/dupl",
},
"com_github_kisielk_errcheck": {
"rule": "go_repository",
"importpath": "github.com/kisielk/errcheck",
},
"com_github_goastscanner_gas": {
"rule": "go_repository",
"importpath": "github.com/GoASTScanner/gas",
},
"com_github_jgautheron_goconst": {
"rule": "go_repository",
"importpath": "github.com/jgautheron/goconst/cmd/goconst",
},
"com_github_alecthomas_gocyclo": {
"rule": "go_repository",
"importpath": "github.com/alecthomas/gocyclo",
},
"org_golang_x_goimports": {
"rule": "go_repository",
"importpath": "golang.org/x/tools/cmd/goimports",
},
"com_github_golang_lint": {
"rule": "go_repository",
"importpath": "github.com/golang/lint/golint",
},
"co_honnef_tools_gosimple": {
"rule": "go_repository",
"importpath": "honnef.co/go/tools/cmd/gosimple",
},
"org_golang_x_gotype": {
"rule": "go_repository",
"importpath": "golang.org/x/tools/cmd/gotype",
},
"com_github_gordonklaus_ineffassign": {
"rule": "go_repository",
"importpath": "github.com/gordonklaus/ineffassign",
},
}

View File

@@ -0,0 +1,13 @@
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,17 @@
load("//build/linter:internal/require.bzl", "require")
load("//build/linter:deps.bzl", "DEPS")
def linter_repositories(excludes = [],
lang_deps = {},
lang_requires = [],
overrides = {},
strict = False,
verbose = 0):
return require(
keys = lang_requires,
deps = lang_deps,
excludes = excludes,
overrides = overrides,
verbose = verbose,
strict = strict,
)

View File

@@ -0,0 +1,89 @@
def _needs_install(name, dep, hkeys=["sha256", "sha1", "tag"], verbose=0, strict=False):
# Does it already exist?
existing_rule = native.existing_rule(name)
if not existing_rule:
return True
# If it has already been defined and our dependency lists a
# hash, do these match? If a hash mismatch is encountered, has
# the user specifically granted permission to continue?
for hkey in hkeys:
expected = dep.get(hkey)
actual = existing_rule.get(hkey)
if expected:
# By guarding the check of expected vs actual with a
# pre-check for actual=None (or empty string), we're
# basically saying "If the user did not bother to set a
# sha256 or sha1 hash for the rule, they probably don't
# care about overriding a dependency either, so don't
# complain about it." In particular, rules_go does not a
# set a sha256 for their com_google_protobuf http_archive
# rule, so this gives us a convenient loophole to prevent
# collisions on this dependency. The "strict" flag can be
# used as as master switch to disable blowing up the
# loading phase due to dependency collisions.
if actual and expected != actual and strict:
msg = """
An existing {0} rule '{1}' was already loaded with a {2} value of '{3}'. Refusing to overwrite this with the requested value ('{4}').
Either remove the pre-existing rule from your WORKSPACE or exclude it from loading by rules_protobuf (strict={5}.
""".format(existing_rule["kind"], name, hkey, actual, expected, strict)
fail(msg)
else:
if verbose > 1: print("Skip reload %s: %s = %s" % (name, hkey, actual))
return False
# No kheys for this rule - in this case no reload; first one loaded wins.
if verbose > 1: print("Skipping reload of existing target %s" % name)
return False
def _install(deps, verbose, strict):
"""Install a list if dependencies for matching native rules.
Return:
list of deps that have no matching native rule.
"""
todo = []
for d in deps:
name = d.get("name")
rule = d.pop("rule", None)
if not rule:
fail("Missing attribute 'rule': %s" % name)
if hasattr(native, rule):
rule = getattr(native, rule)
if verbose: print("Loading %s)" % name)
rule(**d)
else:
d["rule"] = rule
todo.append(d)
return todo
def require(keys,
deps = {},
overrides = {},
excludes = [],
verbose = 0,
strict = False):
#
# Make a list of non-excluded required deps with merged data.
#
required = []
for key in keys:
dep = deps.get(key)
if not dep:
fail("Unknown workspace dependency: %s" % key)
d = dict(**dep) # copy the 'frozen' object.
if not key in excludes:
over = overrides.get(key)
data = d + over if over else d
if _needs_install(key, data, verbose=verbose, strict=strict):
data["name"] = key
required.append(data)
return _install(required, verbose, strict)

33
build/linter/rules.bzl Normal file
View File

@@ -0,0 +1,33 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_repository")
load("//build/linter:deps.bzl", "DEPS")
load("//build/linter:internal/linter_repositories.bzl", "linter_repositories")
def go_lint_repositories(
lang_deps = DEPS,
lang_requires = [
"com_github_alecthomas_gometalinter",
"com_github_tsenart_deadcode",
"com_github_mdempsky_maligned",
"com_github_mibk_dupl",
"com_github_kisielk_errcheck",
"com_github_goastscanner_gas",
"com_github_jgautheron_goconst",
"com_github_alecthomas_gocyclo",
"org_golang_x_goimports",
"com_github_golang_lint",
"co_honnef_tools_gosimple",
"org_golang_x_gotype",
"com_github_gordonklaus_ineffassign",
], **kwargs):
rem = linter_repositories(lang_deps = lang_deps,
lang_requires = lang_requires,
**kwargs)
# Load remaining (special) deps
for dep in rem:
rule = dep.pop("rule")
if "go_repository" == rule:
go_repository(**dep)
else:
fail("Unknown loading rule %s for %s" % (rule, dep))