From c34ceab74eb24e79858dd08331f16cc4f509eac8 Mon Sep 17 00:00:00 2001 From: Cody Schroeder Date: Thu, 18 Oct 2018 10:34:39 -0700 Subject: [PATCH] build: satisfy Bazel 0.18.0 `--all_incompatible_changes` (#3159) This requires a bump to our Bazel minimum version. See: https://github.com/bazelbuild/bazel/issues/6383 --- WORKSPACE | 2 +- kythe/proto/go.bzl | 2 +- third_party/libzip.BUILD | 176 ++++++++++-------- tools/build_rules/expand_template.bzl | 3 +- tools/build_rules/shims.bzl | 3 +- .../verifier_test/cc_indexer_test.bzl | 31 +-- .../verifier_test/verifier_test.bzl | 51 ++--- tools/cpp/clang_configure.bzl | 8 +- 8 files changed, 150 insertions(+), 126 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 6dbce683376..7d22917b6a5 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -6,7 +6,7 @@ load("//:version.bzl", "check_version") # Check that the user has a version between our minimum supported version of # Bazel and our maximum supported version of Bazel. -check_version("0.16", "0.18") +check_version("0.18", "0.18") load("//:setup.bzl", "kythe_rule_repositories") diff --git a/kythe/proto/go.bzl b/kythe/proto/go.bzl index 0c2e2ec3272..b56b40a0098 100644 --- a/kythe/proto/go.bzl +++ b/kythe/proto/go.bzl @@ -9,7 +9,7 @@ KYTHE_IMPORT_BASE = "kythe.io/kythe/proto" def _go_proto_src_impl(ctx): """Copy the generated source of a go_proto_library.""" lib = ctx.attr.library - for src in lib.actions[0].outputs: + for src in lib.actions[0].outputs.to_list(): out = ctx.outputs.generated ctx.actions.run_shell( outputs = [out], diff --git a/third_party/libzip.BUILD b/third_party/libzip.BUILD index cacea2a0857..57574433802 100644 --- a/third_party/libzip.BUILD +++ b/third_party/libzip.BUILD @@ -29,7 +29,9 @@ _CMAKE_VARIABLES = { "__INT16_LIBZIP": None, "__INT32_LIBZIP": None, "__INT64_LIBZIP": None, -} + dict([ +} + +_CMAKE_VARIABLES.update(dict([ ( "ZIP_{sign}INT{size}_T".format( sign = sign.upper(), @@ -42,73 +44,104 @@ _CMAKE_VARIABLES = { ) for sign in ("U", "") for size in (8, 16, 32, 64) -]) +])) + +_SUBSTITUTIONS = { + "@PACKAGE@": "libzip", + "@VERSION@": "1.5.1", # Keep in sync with actual package! +} + +_DEFINES = { + "HAVE_CLONEFILE": False, + "HAVE_COMMONCRYPTO": False, + "HAVE_CRYPTO": False, + "HAVE_DIRENT_H": False, + "HAVE_FICLONERANGE": False, + "HAVE_FILENO": True, + "HAVE_FSEEK": True, + "HAVE_FSEEKO": True, + "HAVE_FTELLO": True, + "HAVE_FTS_H": True, + "HAVE_GETPROGNAME": False, + "HAVE_GNUTLS": False, + "HAVE_LIBBZ2": False, + "HAVE_MKSTEMP": True, + "HAVE_NDIR_H": False, + "HAVE_OPEN": True, + "HAVE_OPENSSL": False, + "HAVE_SETMODE": False, + "HAVE_SHARED": True, + "HAVE_SNPRINTF": True, + "HAVE_SSIZE_T_LIBZIP": True, + "HAVE_STDBOOL_H": True, + "HAVE_STRCASECMP": True, + "HAVE_STRDUP": True, + "HAVE_STRICMP": False, + "HAVE_STRINGS_H": True, + "HAVE_STRTOLL": True, + "HAVE_STRTOULL": True, + "HAVE_STRUCT_TM_TM_ZONE": False, + "HAVE_SYS_DIR_H": False, + "HAVE_SYS_NDIR_H": False, + "HAVE_UNISTD_H": True, + "HAVE__CHMOD": False, + "HAVE__CLOSE": False, + "HAVE__DUP": False, + "HAVE__FDOPEN": False, + "HAVE__FILENO": False, + "HAVE__OPEN": False, + "HAVE__SETMODE": False, + "HAVE__SNPRINTF": False, + "HAVE__STRDUP": False, + "HAVE__STRICMP": False, + "HAVE__STRTOI64": False, + "HAVE__STRTOUI64": False, + "HAVE__UMASK": False, + "HAVE__UNLINK": False, + "HAVE___PROGNAME": False, + "WORDS_BIGENDIAN": False, +} + +_DEFINES.update(dict([( + key, + value != None, +) for key, value in _CMAKE_VARIABLES.items()])) + +_SUBSTITUTIONS.update(cmake_substitutions( + defines = _DEFINES, + vars = _CMAKE_VARIABLES, +)) expand_template( name = "config_h", out = "config.h", - substitutions = { - "@PACKAGE@": "libzip", - "@VERSION@": "1.5.1", # Keep in sync with actual package! - } + cmake_substitutions( - defines = { - "HAVE_CLONEFILE": False, - "HAVE_COMMONCRYPTO": False, - "HAVE_CRYPTO": False, - "HAVE_DIRENT_H": False, - "HAVE_FICLONERANGE": False, - "HAVE_FILENO": True, - "HAVE_FSEEK": True, - "HAVE_FSEEKO": True, - "HAVE_FTELLO": True, - "HAVE_FTS_H": True, - "HAVE_GETPROGNAME": False, - "HAVE_GNUTLS": False, - "HAVE_LIBBZ2": False, - "HAVE_MKSTEMP": True, - "HAVE_NDIR_H": False, - "HAVE_OPEN": True, - "HAVE_OPENSSL": False, - "HAVE_SETMODE": False, - "HAVE_SHARED": True, - "HAVE_SNPRINTF": True, - "HAVE_SSIZE_T_LIBZIP": True, - "HAVE_STDBOOL_H": True, - "HAVE_STRCASECMP": True, - "HAVE_STRDUP": True, - "HAVE_STRICMP": False, - "HAVE_STRINGS_H": True, - "HAVE_STRTOLL": True, - "HAVE_STRTOULL": True, - "HAVE_STRUCT_TM_TM_ZONE": False, - "HAVE_SYS_DIR_H": False, - "HAVE_SYS_NDIR_H": False, - "HAVE_UNISTD_H": True, - "HAVE__CHMOD": False, - "HAVE__CLOSE": False, - "HAVE__DUP": False, - "HAVE__FDOPEN": False, - "HAVE__FILENO": False, - "HAVE__OPEN": False, - "HAVE__SETMODE": False, - "HAVE__SNPRINTF": False, - "HAVE__STRDUP": False, - "HAVE__STRICMP": False, - "HAVE__STRTOI64": False, - "HAVE__STRTOUI64": False, - "HAVE__UMASK": False, - "HAVE__UNLINK": False, - "HAVE___PROGNAME": False, - "WORDS_BIGENDIAN": False, - } + dict([( - key, - value != None, - ) for key, value in _CMAKE_VARIABLES.items()]), - vars = _CMAKE_VARIABLES, - ), + substitutions = _SUBSTITUTIONS, template = "cmake-config.h.in", ) +_VARS = { + "LIBZIP_TYPES_INCLUDE": "#include ", + "PACKAGE_VERSION": "1.5.1", + "PACKAGE_VERSION_MAJOR": "1", + "PACKAGE_VERSION_MINOR": "5", + "PACKAGE_VERSION_MICRO": "1", +} + +_VARS.update(dict([ + ( + "ZIP_{sign}INT{size}_T".format( + sign = sign.upper(), + size = size, + ), + "{sign}int{size}_t".format( + sign = sign.lower(), + size = size, + ), + ) + for sign in ("U", "") + for size in (8, 16, 32, 64) +])) + expand_template( name = "zipconf_h", out = "lib/zipconf.h", @@ -120,26 +153,7 @@ expand_template( "LIBZIP_VERSION_MICRO": True, "ZIP_STATIC": False, }, - vars = { - "LIBZIP_TYPES_INCLUDE": "#include ", - "PACKAGE_VERSION": "1.5.1", - "PACKAGE_VERSION_MAJOR": "1", - "PACKAGE_VERSION_MINOR": "5", - "PACKAGE_VERSION_MICRO": "1", - } + dict([ - ( - "ZIP_{sign}INT{size}_T".format( - sign = sign.upper(), - size = size, - ), - "{sign}int{size}_t".format( - sign = sign.lower(), - size = size, - ), - ) - for sign in ("U", "") - for size in (8, 16, 32, 64) - ]), + vars = _VARS, ), template = "cmake-zipconf.h.in", ) diff --git a/tools/build_rules/expand_template.bzl b/tools/build_rules/expand_template.bzl index 887732fa6b3..ec70eafc941 100644 --- a/tools/build_rules/expand_template.bzl +++ b/tools/build_rules/expand_template.bzl @@ -9,8 +9,7 @@ expand_template = rule( attrs = { "template": attr.label( mandatory = True, - allow_files = True, - single_file = True, + allow_single_file = True, ), "substitutions": attr.string_dict(mandatory = True), "out": attr.output(mandatory = True), diff --git a/tools/build_rules/shims.bzl b/tools/build_rules/shims.bzl index b2b3fdc1fb5..eaa3bf49eac 100644 --- a/tools/build_rules/shims.bzl +++ b/tools/build_rules/shims.bzl @@ -1,4 +1,5 @@ load("@bazel_gazelle//:deps.bzl", _git_repository = "git_repository", _go_repository = "go_repository") +load("@io_bazel_rules_go//go:def.bzl", _go_binary = "go_binary", _go_library = "go_library", _go_test = "go_test") def go_repository(name, commit, importpath, custom = None, custom_git = None, **kwargs): """Macro wrapping the Gazelle go_repository rule. Works identically, except @@ -21,8 +22,6 @@ def go_repository(name, commit, importpath, custom = None, custom_git = None, ** overlay = {"@io_kythe//third_party/go:" + custom + ".BUILD": "BUILD"}, ) -load("@io_bazel_rules_go//go:def.bzl", _go_binary = "go_binary", _go_library = "go_library", _go_test = "go_test") - # Go importpath prefix shared by all Kythe libraries go_prefix = "kythe.io/" diff --git a/tools/build_rules/verifier_test/cc_indexer_test.bzl b/tools/build_rules/verifier_test/cc_indexer_test.bzl index 7199e8fdb8c..e956a12e772 100644 --- a/tools/build_rules/verifier_test/cc_indexer_test.bzl +++ b/tools/build_rules/verifier_test/cc_indexer_test.bzl @@ -73,7 +73,7 @@ def _compiler_options(ctx, cpp, copts, includes): variables = cc_common.create_compile_variables( feature_configuration = feature_configuration, cc_toolchain = cpp, - user_compile_flags = depset(copts), + user_compile_flags = copts, system_include_directories = depset(includes), add_legacy_cxx_options = True, ) @@ -127,12 +127,12 @@ def _split_flags(kwargs): return flags def _transitive_entries(deps): - files, compressed = depset(), depset() + files, compressed = [], [] for dep in deps: if KytheEntries in dep: files += dep[KytheEntries].files compressed += dep[KytheEntries].compressed - return KytheEntries(files = files, compressed = compressed) + return KytheEntries(files = depset(transitive = files), compressed = depset(transitive = compressed)) def _cc_extract_kzip_impl(ctx): cpp = find_cpp_toolchain(ctx) @@ -241,7 +241,8 @@ cc_extract_kzip = rule( def _extract_bundle_impl(ctx): bundle = ctx.actions.declare_directory(ctx.label.name + "_unbundled") ctx.actions.run( - inputs = [ctx.executable.unbundle, ctx.file.src], + inputs = [ctx.file.src], + tools = [ctx.executable.unbundle], outputs = [bundle], mnemonic = "Unbundle", executable = ctx.executable.unbundle, @@ -249,10 +250,10 @@ def _extract_bundle_impl(ctx): ) ctx.actions.run_shell( inputs = [ - ctx.executable.extractor, ctx.file.vnames_config, bundle, ], + tools = [ctx.executable.extractor], outputs = [ctx.outputs.kzip], mnemonic = "ExtractBundle", env = { @@ -310,12 +311,12 @@ def _bazel_extract_kzip_impl(ctx): # Unlike `attr.label`, `attr.label_list` lacks an `executable` argument. # Excluding "is_source" files may be overly aggressive, but effective. scripts = [s for s in ctx.files.scripts if not s.is_source] - ctx.action( + ctx.actions.run( inputs = [ - ctx.executable.extractor, ctx.file.vnames_config, ctx.file.data, ] + scripts + ctx.files.srcs, + tools = [ctx.executable.extractor], outputs = [ctx.outputs.kzip], mnemonic = "BazelExtractKZip", executable = ctx.executable.extractor, @@ -326,7 +327,7 @@ def _bazel_extract_kzip_impl(ctx): ] + [script.path for script in scripts], ) return [ - KytheVerifierSources(files = ctx.files.srcs), + KytheVerifierSources(files = depset(ctx.files.srcs)), CxxCompilationUnits(files = depset([ctx.outputs.kzip])), ] @@ -369,7 +370,8 @@ def _cc_index_source(ctx, src): ctx.actions.run( mnemonic = "CcIndexSource", outputs = [entries], - inputs = [ctx.executable.indexer] + ctx.files.srcs + ctx.files.deps, + inputs = ctx.files.srcs + ctx.files.deps, + tools = [ctx.executable.indexer], executable = ctx.executable.indexer, arguments = [ctx.expand_location(o) for o in ctx.attr.opts] + [ "-i", @@ -391,7 +393,8 @@ def _cc_index_compilation(ctx, compilation): ctx.actions.run( mnemonic = "CcIndexCompilation", outputs = [entries], - inputs = [ctx.executable.indexer, compilation], + inputs = [compilation], + tools = [ctx.executable.indexer], executable = ctx.executable.indexer, arguments = [ctx.expand_location(o) for o in ctx.attr.opts] + [ "-o", @@ -432,15 +435,15 @@ def _cc_index_impl(ctx): inputs = entries, command = '("${@:1:${#@}-1}" || rm -f "${@:${#@}}") | gzip -c > "${@:${#@}}"', mnemonic = "CompressEntries", - arguments = ["cat"] + [i.path for i in entries] + [ctx.outputs.entries.path], + arguments = ["cat"] + [i.path for i in entries.to_list()] + [ctx.outputs.entries.path], ) - sources = depset([src for src in ctx.files.srcs if src.extension != "kzip"]) + sources = [depset([src for src in ctx.files.srcs if src.extension != "kzip"])] for dep in ctx.attr.srcs: if KytheVerifierSources in dep: - sources += dep[KytheVerifierSources].files + sources += [dep[KytheVerifierSources].files] return [ - KytheVerifierSources(files = sources), + KytheVerifierSources(files = depset(transitive = sources)), KytheEntries(files = entries, compressed = depset([ctx.outputs.entries])), ] diff --git a/tools/build_rules/verifier_test/verifier_test.bzl b/tools/build_rules/verifier_test/verifier_test.bzl index 180b154c4dc..00dd5200da8 100644 --- a/tools/build_rules/verifier_test/verifier_test.bzl +++ b/tools/build_rules/verifier_test/verifier_test.bzl @@ -150,12 +150,13 @@ def extract( "KYTHE_ROOT_DIRECTORY": ".", "KYTHE_OUTPUT_FILE": kzip.path, } - inputs = [extractor] + srcs + deps + inputs = srcs + deps if vnames_config: env["KYTHE_VNAMES"] = vnames_config.path inputs += [vnames_config] ctx.actions.run( inputs = inputs, + tools = [extractor], outputs = [kzip], mnemonic = mnemonic, executable = extractor, @@ -207,7 +208,7 @@ def _java_extract_kzip_impl(ctx): ) return [ KytheJavaJar(jar = jar), - KytheVerifierSources(files = ctx.files.srcs), + KytheVerifierSources(files = depset(ctx.files.srcs)), ] java_extract_kzip = rule( @@ -261,7 +262,7 @@ def _jvm_extract_kzip_impl(ctx): opts = ctx.attr.opts, mnemonic = "JvmExtractKZip", ) - return [KytheVerifierSources(files = [])] + return [KytheVerifierSources(files = depset())] jvm_extract_kzip = rule( attrs = { @@ -284,27 +285,28 @@ jvm_extract_kzip = rule( ) def _index_compilation_impl(ctx): - sources = depset() + sources = [] intermediates = [] for dep in ctx.attr.deps: if KytheVerifierSources in dep: - sources += dep[KytheVerifierSources].files - for input in dep.files: - entries = ctx.new_file( - ctx.outputs.entries, + sources += [dep[KytheVerifierSources].files] + for input in dep.files.to_list(): + entries = ctx.actions.declare_file( ctx.label.name + input.basename + ".entries", + sibling = ctx.outputs.entries, ) intermediates += [entries] - ctx.action( + ctx.actions.run_shell( outputs = [entries], - inputs = [ctx.executable.indexer, input] + ctx.files.tools, + inputs = [input], + tools = [ctx.executable.indexer] + ctx.files.tools, arguments = ([ctx.executable.indexer.path] + [ctx.expand_location(o) for o in ctx.attr.opts] + [input.path, entries.path]), command = '("${@:1:${#@}-1}" || rm -f "${@:${#@}}") > "${@:${#@}}"', mnemonic = "IndexCompilation", ) - ctx.action( + ctx.actions.run_shell( outputs = [ctx.outputs.entries], inputs = intermediates, command = '("${@:1:${#@}-1}" || rm -f "${@:${#@}}") | gzip -c > "${@:${#@}}"', @@ -312,8 +314,8 @@ def _index_compilation_impl(ctx): arguments = ["cat"] + [i.path for i in intermediates] + [ctx.outputs.entries.path], ) return [ - KytheVerifierSources(files = sources), - KytheEntries(files = intermediates, compressed = depset([ctx.outputs.entries])), + KytheVerifierSources(files = depset(transitive = sources)), + KytheEntries(files = depset(intermediates), compressed = depset([ctx.outputs.entries])), ] index_compilation = rule( @@ -341,26 +343,31 @@ index_compilation = rule( ) def _verifier_test_impl(ctx): - entries = depset() - entries_gz = depset() - sources = depset() + entries = [] + entries_gz = [] + sources = [] for src in ctx.attr.srcs: if KytheVerifierSources in src: - sources += src[KytheVerifierSources].files + sources += [src[KytheVerifierSources].files] if KytheEntries in src: if src[KytheEntries].files: - entries += src[KytheEntries].files + entries += [src[KytheEntries].files] else: - entries_gz += src[KytheEntries].compressed + entries_gz += [src[KytheEntries].compressed] else: - sources += src.files + sources += [depset(src.files)] for dep in ctx.attr.deps: # TODO(shahms): Allow specifying .entries files directly. if dep[KytheEntries].files: - entries += dep[KytheEntries].files + entries += [dep[KytheEntries].files] else: - entries_gz += dep[KytheEntries].compressed + entries_gz += [dep[KytheEntries].compressed] + + # Flatten input lists + entries = depset(transitive = entries).to_list() + entries_gz = depset(transitive = entries_gz).to_list() + sources = depset(transitive = sources).to_list() if not (entries or entries_gz): fail("Missing required entry stream input (check your deps!)") diff --git a/tools/cpp/clang_configure.bzl b/tools/cpp/clang_configure.bzl index 5e534e920e6..15dfc733654 100644 --- a/tools/cpp/clang_configure.bzl +++ b/tools/cpp/clang_configure.bzl @@ -117,7 +117,7 @@ def _execute( def _get_tool_paths(repository_ctx, darwin, cc): """Compute the path to the various tools.""" - return { + paths = { k: _which(repository_ctx, k, "/usr/bin/" + k) for k in [ "ld", @@ -129,10 +129,12 @@ def _get_tool_paths(repository_ctx, darwin, cc): "objdump", "strip", ] - } + { + } + paths.update({ "gcc": cc, "ar": "/usr/bin/libtool" if darwin else _which(repository_ctx, "ar", "/usr/bin/ar"), - } + }) + return paths def _cplus_include_paths(repository_ctx): """Use ${CPLUS_INCLUDE_PATH} to compute the list of flags for cxxflag."""