Fix Buildifier warnings (#395)

* Run buildifier formatter

* Fix buildifier warnings

Ran: `buildifier --lint=fix -r .`
This commit is contained in:
Laurent Le Brun 2020-05-04 19:50:45 +02:00 committed by GitHub
parent 3515b20a24
commit c292369597
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 281 additions and 187 deletions

View File

@ -25,12 +25,13 @@ android_ndk_repository(
# TODO(jin): replace legacy gmaven_rules targets with `maven_install` from the new rules_jvm_external # TODO(jin): replace legacy gmaven_rules targets with `maven_install` from the new rules_jvm_external
RULES_JVM_EXTERNAL_TAG = "1.0" RULES_JVM_EXTERNAL_TAG = "1.0"
RULES_JVM_EXTERNAL_SHA = "48e0f1aab74fabba98feb8825459ef08dcc75618d381dff63ec9d4dd9860deaa" RULES_JVM_EXTERNAL_SHA = "48e0f1aab74fabba98feb8825459ef08dcc75618d381dff63ec9d4dd9860deaa"
http_archive( http_archive(
name = "gmaven_rules", name = "gmaven_rules",
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
sha256 = RULES_JVM_EXTERNAL_SHA, sha256 = RULES_JVM_EXTERNAL_SHA,
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG, url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
) )

View File

@ -18,20 +18,20 @@ def _cc_configure_make_impl(ctx):
outputs = [out_includes, out_lib] outputs = [out_includes, out_lib]
cpp_fragment = ctx.fragments.cpp cpp_fragment = ctx.fragments.cpp
compiler_options = [] # cpp_fragment.compiler_options(ctx.features) compiler_options = [] # cpp_fragment.compiler_options(ctx.features)
c_options = compiler_options + cpp_fragment.c_options c_options = compiler_options + cpp_fragment.c_options
cxx_options = compiler_options + cpp_fragment.cxx_options(ctx.features) cxx_options = compiler_options + cpp_fragment.cxx_options(ctx.features)
CFLAGS = "\"{}\"".format(' '.join(c_options)) CFLAGS = "\"{}\"".format(" ".join(c_options))
CXXFLAGS = "\"{}\"".format(' '.join(cxx_options)) CXXFLAGS = "\"{}\"".format(" ".join(cxx_options))
# Run ./configure && make from a temporary directory, and install into another temporary directory. # Run ./configure && make from a temporary directory, and install into another temporary directory.
# Finally, copy the results into the directory artifact declared in out_includes. # Finally, copy the results into the directory artifact declared in out_includes.
ctx.actions.run_shell( ctx.actions.run_shell(
mnemonic="ConfigureMake", mnemonic = "ConfigureMake",
inputs = ctx.attr.src.files, inputs = ctx.attr.src.files,
outputs = outputs, outputs = outputs,
command = '\n'.join([ command = "\n".join([
"set -e", "set -e",
"P=$(pwd)", "P=$(pwd)",
"tmpdir=$(mktemp -d)", "tmpdir=$(mktemp -d)",
@ -39,16 +39,25 @@ def _cc_configure_make_impl(ctx):
"trap \"{ rm -rf $tmpdir $tmpinstalldir; }\" EXIT", "trap \"{ rm -rf $tmpdir $tmpinstalldir; }\" EXIT",
"pushd $tmpdir", "pushd $tmpdir",
"CFLAGS={} CXXFLAGS={} $P/{}/configure --prefix=$tmpinstalldir {}".format( "CFLAGS={} CXXFLAGS={} $P/{}/configure --prefix=$tmpinstalldir {}".format(
CFLAGS, CXXFLAGS, ctx.attr.src.label.workspace_root, ' '.join(ctx.attr.configure_flags)), CFLAGS,
CXXFLAGS,
ctx.attr.src.label.workspace_root,
" ".join(ctx.attr.configure_flags),
),
"CFLAGS={} CXXFLAGS={} make install".format(CFLAGS, CXXFLAGS), "CFLAGS={} CXXFLAGS={} make install".format(CFLAGS, CXXFLAGS),
"popd", "popd",
"cp $tmpinstalldir/{} {}".format(ctx.attr.out_lib_path, out_lib.path), "cp $tmpinstalldir/{} {}".format(ctx.attr.out_lib_path, out_lib.path),
"cp -R $tmpinstalldir/include/ {}".format(out_includes.path)]), "cp -R $tmpinstalldir/include/ {}".format(out_includes.path),
execution_requirements = {"block-network": ""} ]),
execution_requirements = {"block-network": ""},
) )
return [DefaultInfo(files = depset(direct=outputs)), return [
OutputGroupInfo(headers = depset([out_includes]), DefaultInfo(files = depset(direct = outputs)),
libfile = depset([out_lib]))] OutputGroupInfo(
headers = depset([out_includes]),
libfile = depset([out_lib]),
),
]
_cc_configure_make_rule = rule( _cc_configure_make_rule = rule(
attrs = { attrs = {
@ -62,28 +71,28 @@ _cc_configure_make_rule = rule(
) )
def cc_configure_make(name, configure_flags, src, out_lib_path): def cc_configure_make(name, configure_flags, src, out_lib_path):
name_cmr = '_{}_cc_configure_make_rule'.format(name) name_cmr = "_{}_cc_configure_make_rule".format(name)
_cc_configure_make_rule( _cc_configure_make_rule(
name = name_cmr, name = name_cmr,
configure_flags = configure_flags, configure_flags = configure_flags,
src = src, src = src,
out_lib_path = out_lib_path out_lib_path = out_lib_path,
) )
name_libfile_fg = '_{}_libfile_fg'.format(name) name_libfile_fg = "_{}_libfile_fg".format(name)
native.filegroup( native.filegroup(
name = name_libfile_fg, name = name_libfile_fg,
srcs = [name_cmr], srcs = [name_cmr],
output_group = "libfile", output_group = "libfile",
) )
name_libfile_import = '_{}_libfile_import'.format(name) name_libfile_import = "_{}_libfile_import".format(name)
native.cc_import( native.cc_import(
name = name_libfile_import, name = name_libfile_import,
static_library = name_libfile_fg, static_library = name_libfile_fg,
) )
name_headers_fg = '_{}_headers_fg'.format(name) name_headers_fg = "_{}_headers_fg".format(name)
native.filegroup( native.filegroup(
name = name_headers_fg, name = name_headers_fg,
srcs = [name_cmr], srcs = [name_cmr],

View File

@ -3,30 +3,33 @@ load("@rules_foreign_cc//tools/build_defs:configure.bzl", "configure_make")
configure_make( configure_make(
name = "apr", name = "apr",
lib_source = "@apr//:all", lib_source = "@apr//:all",
static_libraries = ["libapr-1.a"],
shared_libraries = ["libapr-1.so"], shared_libraries = ["libapr-1.so"],
static_libraries = ["libapr-1.a"],
) )
configure_make( configure_make(
name = "apr_util", name = "apr_util",
lib_source = "@apr_util//:all",
deps = [":apr"],
configure_options = [ configure_options = [
"--with-apr=$$EXT_BUILD_DEPS$$/apr", "--with-apr=$$EXT_BUILD_DEPS$$/apr",
], ],
static_libraries = ["libaprutil-1.a"], lib_source = "@apr_util//:all",
shared_libraries = ["libaprutil-1.so"], shared_libraries = ["libaprutil-1.so"],
static_libraries = ["libaprutil-1.a"],
deps = [":apr"],
) )
configure_make( configure_make(
name = "pcre", name = "pcre",
lib_source = "@pcre//:all", lib_source = "@pcre//:all",
static_libraries = ["libpcre.a"],
shared_libraries = ["libpcre.so.1"], shared_libraries = ["libpcre.so.1"],
static_libraries = ["libpcre.a"],
) )
configure_make( configure_make(
name = "apache_httpd", name = "apache_httpd",
binaries = [
"httpd",
],
configure_options = [ configure_options = [
"--with-apr=$$EXT_BUILD_DEPS$$/apr", "--with-apr=$$EXT_BUILD_DEPS$$/apr",
"--with-apr-util=$$EXT_BUILD_DEPS$$/apr_util", "--with-apr-util=$$EXT_BUILD_DEPS$$/apr_util",
@ -34,17 +37,14 @@ configure_make(
"CFLAGS='-Dredacted=\"redacted\"'", "CFLAGS='-Dredacted=\"redacted\"'",
], ],
lib_source = "@apache_httpd//:all", lib_source = "@apache_httpd//:all",
binaries = [ visibility = [
"httpd", "//visibility:public",
], ],
deps = [ deps = [
":apr", ":apr",
":apr_util", ":apr_util",
":pcre", ":pcre",
], ],
visibility = [
"//visibility:public"
],
) )
filegroup( filegroup(
@ -52,7 +52,7 @@ filegroup(
srcs = [ srcs = [
":apache_httpd", ":apache_httpd",
], ],
output_group = "gen_dir" output_group = "gen_dir",
) )
filegroup( filegroup(
@ -60,7 +60,7 @@ filegroup(
srcs = [ srcs = [
":pcre", ":pcre",
], ],
output_group = "gen_dir" output_group = "gen_dir",
) )
filegroup( filegroup(
@ -68,7 +68,7 @@ filegroup(
srcs = [ srcs = [
":apr", ":apr",
], ],
output_group = "gen_dir" output_group = "gen_dir",
) )
filegroup( filegroup(
@ -76,7 +76,7 @@ filegroup(
srcs = [ srcs = [
":apr_util", ":apr_util",
], ],
output_group = "gen_dir" output_group = "gen_dir",
) )
sh_test( sh_test(
@ -86,9 +86,9 @@ sh_test(
], ],
args = ["$(location httpd_dir)/bin/httpd $(location pcre_dir)/lib $(location apr_dir)/lib $(location apr_util_dir)/lib"], args = ["$(location httpd_dir)/bin/httpd $(location pcre_dir)/lib $(location apr_dir)/lib $(location apr_util_dir)/lib"],
data = [ data = [
":httpd_dir",
":apr_dir", ":apr_dir",
":apr_util_dir", ":apr_util_dir",
":httpd_dir",
":pcre_dir", ":pcre_dir",
], ],
) )

View File

@ -2,10 +2,10 @@ load("@rules_foreign_cc//tools/build_defs:boost_build.bzl", "boost_build")
boost_build( boost_build(
name = "boost_regex", name = "boost_regex",
bootstrap_options = ["--with-toolchain=clang"],
lib_source = "@boost//:all", lib_source = "@boost//:all",
shared_libraries = ["libboost_regex.so.1.68.0"], shared_libraries = ["libboost_regex.so.1.68.0"],
static_libraries = ["libboost_regex.a"], static_libraries = ["libboost_regex.a"],
bootstrap_options = ["--with-toolchain=clang"],
user_options = ["--with-regex"], user_options = ["--with-regex"],
) )

View File

@ -2,13 +2,6 @@ load("@rules_foreign_cc//tools/build_defs:configure.bzl", "configure_make")
configure_make( configure_make(
name = "libevent", name = "libevent",
configure_options = [
"--enable-shared=no",
"--disable-libevent-regress",
"--disable-openssl",
],
lib_source = "@libevent//:all",
out_lib_dir = "lib",
# libevent script uses it's own libtool for linking; # libevent script uses it's own libtool for linking;
# so do not specify linker tool for it # so do not specify linker tool for it
# (otherwise, if the libtool from bazel's toolchain is supplied, # (otherwise, if the libtool from bazel's toolchain is supplied,
@ -17,6 +10,13 @@ configure_make(
configure_env_vars = { configure_env_vars = {
"AR": "", "AR": "",
}, },
configure_options = [
"--enable-shared=no",
"--disable-libevent-regress",
"--disable-openssl",
],
lib_source = "@libevent//:all",
out_lib_dir = "lib",
) )
cc_test( cc_test(

View File

@ -13,10 +13,10 @@ cc_library(
cmake_external( cmake_external(
name = "hello_cmake", name = "hello_cmake",
lib_source = "//static:srcs",
generate_crosstool_file = True, generate_crosstool_file = True,
static_libraries = ["libhello.a"], lib_source = "//static:srcs",
out_include_dir = "include/version123", out_include_dir = "include/version123",
static_libraries = ["libhello.a"],
) )
# I do not make it a test, since it is a cross-compilation example, # I do not make it a test, since it is a cross-compilation example,

View File

@ -1,6 +1,8 @@
# example code is taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib # example code is taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib
# for test only # for test only
load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cmake_external")
filegroup( filegroup(
name = "srcs", name = "srcs",
srcs = glob(["**"]), srcs = glob(["**"]),
@ -8,11 +10,9 @@ filegroup(
) )
exports_files([ exports_files([
"hello_client.c" "hello_client.c",
]) ])
load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cmake_external")
cmake_external( cmake_external(
name = "libhello", name = "libhello",
lib_source = ":srcs", lib_source = ":srcs",

View File

@ -72,7 +72,6 @@ filegroup(
cc_toolchain( cc_toolchain(
name = "cc-compiler-armeabi-v7a", name = "cc-compiler-armeabi-v7a",
toolchain_identifier = "armeabi-v7a",
all_files = ":linaro_linux_all_files", all_files = ":linaro_linux_all_files",
ar_files = "//tools/arm_compiler/linaro_linux_gcc:ar", ar_files = "//tools/arm_compiler/linaro_linux_gcc:ar",
as_files = "//tools/arm_compiler/linaro_linux_gcc:as", as_files = "//tools/arm_compiler/linaro_linux_gcc:as",
@ -85,12 +84,12 @@ cc_toolchain(
static_runtime_libs = [":empty"], static_runtime_libs = [":empty"],
strip_files = "//tools/arm_compiler/linaro_linux_gcc:strip", strip_files = "//tools/arm_compiler/linaro_linux_gcc:strip",
supports_param_files = 1, supports_param_files = 1,
toolchain_identifier = "armeabi-v7a",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
cc_toolchain( cc_toolchain(
name = "cc-compiler-k8", name = "cc-compiler-k8",
toolchain_identifier = "local",
all_files = ":empty", all_files = ":empty",
ar_files = ":empty", ar_files = ":empty",
as_files = ":empty", as_files = ":empty",
@ -103,5 +102,6 @@ cc_toolchain(
static_runtime_libs = [":empty"], static_runtime_libs = [":empty"],
strip_files = ":empty", strip_files = ":empty",
supports_param_files = 1, supports_param_files = 1,
toolchain_identifier = "local",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )

View File

@ -1,6 +1,7 @@
# example code is taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib # example code is taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib
# for test only # for test only
load("@bazel_tools//tools/build_rules:test_rules.bzl", "file_test") load("@bazel_tools//tools/build_rules:test_rules.bzl", "file_test")
load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cmake_external")
filegroup( filegroup(
name = "srcs", name = "srcs",
@ -8,8 +9,6 @@ filegroup(
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cmake_external")
cmake_external( cmake_external(
name = "libhello", name = "libhello",
binaries = select({ binaries = select({

View File

@ -1,14 +1,14 @@
# example code is taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib # example code is taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib
# for test only # for test only
load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cmake_external")
filegroup( filegroup(
name = "srcs", name = "srcs",
srcs = glob(["**"]), srcs = glob(["**"]),
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cmake_external")
cmake_external( cmake_external(
name = "libhello", name = "libhello",
# Probably this variable should be set by default. # Probably this variable should be set by default.

View File

@ -1,14 +1,14 @@
# example code is taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib # example code is taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib
# for test only # for test only
load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cmake_external")
filegroup( filegroup(
name = "srcs", name = "srcs",
srcs = glob(["**"]), srcs = glob(["**"]),
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cmake_external")
cmake_external( cmake_external(
name = "libhello", name = "libhello",
lib_source = ":srcs", lib_source = ":srcs",
@ -91,9 +91,9 @@ sh_test(
srcs = ["test_hello.sh"], srcs = ["test_hello.sh"],
args = ["$(location libhello_example)"], args = ["$(location libhello_example)"],
data = [":libhello_example"], data = [":libhello_example"],
deps = ["@bazel_tools//tools/bash/runfiles"],
tags = ["windows"], tags = ["windows"],
visibility = ["//:__pkg__"], visibility = ["//:__pkg__"],
deps = ["@bazel_tools//tools/bash/runfiles"],
) )
sh_test( sh_test(
@ -101,9 +101,9 @@ sh_test(
srcs = ["test_hello.sh"], srcs = ["test_hello.sh"],
args = ["$(location libhello_example_ninja)"], args = ["$(location libhello_example_ninja)"],
data = [":libhello_example_ninja"], data = [":libhello_example_ninja"],
deps = ["@bazel_tools//tools/bash/runfiles"],
tags = ["windows"], tags = ["windows"],
visibility = ["//:__pkg__"], visibility = ["//:__pkg__"],
deps = ["@bazel_tools//tools/bash/runfiles"],
) )
sh_test( sh_test(
@ -111,9 +111,9 @@ sh_test(
srcs = ["test_hello.sh"], srcs = ["test_hello.sh"],
args = ["$(location libhello_example_nmake)"], args = ["$(location libhello_example_nmake)"],
data = [":libhello_example_nmake"], data = [":libhello_example_nmake"],
deps = ["@bazel_tools//tools/bash/runfiles"],
tags = ["windows"], tags = ["windows"],
visibility = ["//:__pkg__"], visibility = ["//:__pkg__"],
deps = ["@bazel_tools//tools/bash/runfiles"],
) )
cmake_external( cmake_external(

View File

@ -34,19 +34,22 @@ cmake_external(
cmake_external( cmake_external(
name = "lib_with_duplicate_transitive_bazel_deps", name = "lib_with_duplicate_transitive_bazel_deps",
lib_name = "libc",
cmake_options = ["-GNinja"],
cache_entries = { cache_entries = {
"LIBA_DIR": "$$EXT_BUILD_DEPS$$", "LIBA_DIR": "$$EXT_BUILD_DEPS$$",
"LIBB_DIR": "$$EXT_BUILD_DEPS$$", "LIBB_DIR": "$$EXT_BUILD_DEPS$$",
}, },
cmake_options = ["-GNinja"],
generate_crosstool_file = generate_crosstool, generate_crosstool_file = generate_crosstool,
lib_name = "libc",
lib_source = "//cmake_synthetic/libc:c_srcs", lib_source = "//cmake_synthetic/libc:c_srcs",
make_commands = [ make_commands = [
"ninja", "ninja",
"ninja install", "ninja install",
], ],
deps = ["//cmake_synthetic/liba:lib_a_bazel", "//cmake_synthetic/libb:lib_b_bazel"], deps = [
"//cmake_synthetic/liba:lib_a_bazel",
"//cmake_synthetic/libb:lib_b_bazel",
],
) )
build_test( build_test(

View File

@ -2,7 +2,10 @@ load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cmake_external")
filegroup( filegroup(
name = "sources", name = "sources",
srcs = glob(["source_root/**"], exclude_directories = 0), srcs = glob(
["source_root/**"],
exclude_directories = 0,
),
) )
cmake_external( cmake_external(

View File

@ -82,7 +82,7 @@ def include_examples_repositories():
name = "nghttp2", name = "nghttp2",
build_file_content = all_content, build_file_content = all_content,
patch_args = ["-p1"], patch_args = ["-p1"],
patch_cmds = ["find . -name '*.sh' -exec sed -i.orig '1s|#!/usr/bin/env sh\$|/bin/sh\$|' {} +"], patch_cmds = ["find . -name '*.sh' -exec sed -i.orig '1s|#!/usr/bin/env sh\\$|/bin/sh\\$|' {} +"],
patches = ["@rules_foreign_cc_tests//:nghttp2.patch"], patches = ["@rules_foreign_cc_tests//:nghttp2.patch"],
strip_prefix = "nghttp2-e5b3f9addd49bca27e2f99c5c65a564eb5c0cf6d", strip_prefix = "nghttp2-e5b3f9addd49bca27e2f99c5c65a564eb5c0cf6d",
urls = [ urls = [

View File

@ -7,10 +7,12 @@ def _generate_install_rule_impl(rctx):
text = """workspace(name='{ws_name}') text = """workspace(name='{ws_name}')
load("{init_file}", "{init_function}") load("{init_file}", "{init_function}")
{init_expression} {init_expression}
""".format(ws_name = rctx.attr.name, """.format(
init_file = rctx.attr.init_file, ws_name = rctx.attr.name,
init_function = rctx.attr.init_function, init_file = rctx.attr.init_file,
init_expression = rctx.attr.init_expression) init_function = rctx.attr.init_function,
init_expression = rctx.attr.init_expression,
)
rctx.file("WORKSPACE", text) rctx.file("WORKSPACE", text)
rctx.file("BUILD", "") rctx.file("BUILD", "")
@ -35,5 +37,5 @@ def install_ws_dependency(repo_name, url, strip_prefix, init_file, init_function
stripPrefix = strip_prefix, stripPrefix = strip_prefix,
init_file = init_file, init_file = init_file,
init_function = init_function, init_function = init_function,
init_expression = init_expression init_expression = init_expression,
) )

View File

@ -131,10 +131,16 @@ def _move_dict_values_test(ctx):
"CMAKE_CXX_LINK_EXECUTABLE": "became", "CMAKE_CXX_LINK_EXECUTABLE": "became",
"CUSTOM": "YES", "CUSTOM": "YES",
} }
export_for_test.move_dict_values(target, source_env, export_for_test.move_dict_values(
export_for_test.CMAKE_ENV_VARS_FOR_CROSSTOOL) target,
export_for_test.move_dict_values(target, source_cache, source_env,
export_for_test.CMAKE_CACHE_ENTRIES_CROSSTOOL) export_for_test.CMAKE_ENV_VARS_FOR_CROSSTOOL,
)
export_for_test.move_dict_values(
target,
source_cache,
export_for_test.CMAKE_CACHE_ENTRIES_CROSSTOOL,
)
expected_target = { expected_target = {
"CMAKE_C_COMPILER": "sink-cc-value", "CMAKE_C_COMPILER": "sink-cc-value",
@ -164,10 +170,14 @@ def _reverse_descriptor_dict_test(ctx):
"CMAKE_C_FLAGS_INIT": struct(value = "CMAKE_C_FLAGS", replace = False), "CMAKE_C_FLAGS_INIT": struct(value = "CMAKE_C_FLAGS", replace = False),
"CMAKE_CXX_FLAGS_INIT": struct(value = "CMAKE_CXX_FLAGS", replace = False), "CMAKE_CXX_FLAGS_INIT": struct(value = "CMAKE_CXX_FLAGS", replace = False),
"CMAKE_ASM_FLAGS_INIT": struct(value = "CMAKE_ASM_FLAGS", replace = False), "CMAKE_ASM_FLAGS_INIT": struct(value = "CMAKE_ASM_FLAGS", replace = False),
"CMAKE_STATIC_LINKER_FLAGS_INIT": struct(value = "CMAKE_STATIC_LINKER_FLAGS", "CMAKE_STATIC_LINKER_FLAGS_INIT": struct(
replace = False), value = "CMAKE_STATIC_LINKER_FLAGS",
"CMAKE_SHARED_LINKER_FLAGS_INIT": struct(value = "CMAKE_SHARED_LINKER_FLAGS", replace = False,
replace = False), ),
"CMAKE_SHARED_LINKER_FLAGS_INIT": struct(
value = "CMAKE_SHARED_LINKER_FLAGS",
replace = False,
),
"CMAKE_EXE_LINKER_FLAGS_INIT": struct(value = "CMAKE_EXE_LINKER_FLAGS", replace = False), "CMAKE_EXE_LINKER_FLAGS_INIT": struct(value = "CMAKE_EXE_LINKER_FLAGS", replace = False),
} }
@ -193,8 +203,11 @@ def _merge_toolchain_and_user_values_test(ctx):
"CUSTOM": "YES", "CUSTOM": "YES",
} }
res = export_for_test.merge_toolchain_and_user_values(target, source_cache, res = export_for_test.merge_toolchain_and_user_values(
export_for_test.CMAKE_CACHE_ENTRIES_CROSSTOOL) target,
source_cache,
export_for_test.CMAKE_CACHE_ENTRIES_CROSSTOOL,
)
expected_target = { expected_target = {
"CMAKE_C_FLAGS": "-cc-flag -gcc_toolchain cc-toolchain --additional-flag", "CMAKE_C_FLAGS": "-cc-flag -gcc_toolchain cc-toolchain --additional-flag",
@ -232,8 +245,19 @@ def _merge_flag_values_no_toolchain_file_test(ctx):
"CMAKE_BUILD_TYPE": "RelWithDebInfo", "CMAKE_BUILD_TYPE": "RelWithDebInfo",
} }
script = create_cmake_script("ws", "linux", "cmake", tools, flags, "test_rule", script = create_cmake_script(
"external/test_rule", True, user_cache, user_env, []) "ws",
"linux",
"cmake",
tools,
flags,
"test_rule",
"external/test_rule",
True,
user_cache,
user_env,
[],
)
expected = """CC=\"/usr/bin/gcc\" CXX=\"/usr/bin/gcc\" CXXFLAGS=\"foo=\\\"bar\\\" -Fbat" cmake -DCMAKE_AR=\"/usr/bin/ar\" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DCMAKE_PREFIX_PATH=\"$EXT_BUILD_DEPS\" -DCMAKE_INSTALL_PREFIX=\"test_rule\" -DCMAKE_RANLIB=\"\" $EXT_BUILD_ROOT/external/test_rule""" expected = """CC=\"/usr/bin/gcc\" CXX=\"/usr/bin/gcc\" CXXFLAGS=\"foo=\\\"bar\\\" -Fbat" cmake -DCMAKE_AR=\"/usr/bin/ar\" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DCMAKE_PREFIX_PATH=\"$EXT_BUILD_DEPS\" -DCMAKE_INSTALL_PREFIX=\"test_rule\" -DCMAKE_RANLIB=\"\" $EXT_BUILD_ROOT/external/test_rule"""
asserts.equals(env, expected, script) asserts.equals(env, expected, script)
@ -262,8 +286,19 @@ def _create_min_cmake_script_no_toolchain_file_test(ctx):
"CMAKE_PREFIX_PATH": "/abc/def", "CMAKE_PREFIX_PATH": "/abc/def",
} }
script = create_cmake_script("ws", "linux", "cmake", tools, flags, "test_rule", script = create_cmake_script(
"external/test_rule", True, user_cache, user_env, ["-GNinja"]) "ws",
"linux",
"cmake",
tools,
flags,
"test_rule",
"external/test_rule",
True,
user_cache,
user_env,
["-GNinja"],
)
expected = "CC=\"/usr/bin/gcc\" CXX=\"/usr/bin/gcc\" CFLAGS=\"-U_FORTIFY_SOURCE -fstack-protector -Wall\" CXXFLAGS=\"-U_FORTIFY_SOURCE -fstack-protector -Wall\" ASMFLAGS=\"-U_FORTIFY_SOURCE -fstack-protector -Wall\" cmake -DCMAKE_AR=\"/usr/bin/ar\" -DCMAKE_SHARED_LINKER_FLAGS=\"-shared -fuse-ld=gold\" -DCMAKE_EXE_LINKER_FLAGS=\"-fuse-ld=gold -Wl -no-as-needed\" -DNOFORTRAN=\"on\" -DCMAKE_PREFIX_PATH=\"$EXT_BUILD_DEPS;/abc/def\" -DCMAKE_INSTALL_PREFIX=\"test_rule\" -DCMAKE_BUILD_TYPE=\"Debug\" -DCMAKE_RANLIB=\"\" -GNinja $EXT_BUILD_ROOT/external/test_rule" expected = "CC=\"/usr/bin/gcc\" CXX=\"/usr/bin/gcc\" CFLAGS=\"-U_FORTIFY_SOURCE -fstack-protector -Wall\" CXXFLAGS=\"-U_FORTIFY_SOURCE -fstack-protector -Wall\" ASMFLAGS=\"-U_FORTIFY_SOURCE -fstack-protector -Wall\" cmake -DCMAKE_AR=\"/usr/bin/ar\" -DCMAKE_SHARED_LINKER_FLAGS=\"-shared -fuse-ld=gold\" -DCMAKE_EXE_LINKER_FLAGS=\"-fuse-ld=gold -Wl -no-as-needed\" -DNOFORTRAN=\"on\" -DCMAKE_PREFIX_PATH=\"$EXT_BUILD_DEPS;/abc/def\" -DCMAKE_INSTALL_PREFIX=\"test_rule\" -DCMAKE_BUILD_TYPE=\"Debug\" -DCMAKE_RANLIB=\"\" -GNinja $EXT_BUILD_ROOT/external/test_rule"
asserts.equals(env, expected, script) asserts.equals(env, expected, script)
@ -295,8 +330,19 @@ def _create_min_cmake_script_wipe_toolchain_test(ctx):
"WIPE_ME_IF_PRESENT": "", "WIPE_ME_IF_PRESENT": "",
} }
script = create_cmake_script("ws", "linux", "cmake", tools, flags, "test_rule", script = create_cmake_script(
"external/test_rule", True, user_cache, user_env, ["-GNinja"]) "ws",
"linux",
"cmake",
tools,
flags,
"test_rule",
"external/test_rule",
True,
user_cache,
user_env,
["-GNinja"],
)
expected = "CC=\"/usr/bin/gcc\" CXX=\"/usr/bin/gcc\" CFLAGS=\"-U_FORTIFY_SOURCE -fstack-protector -Wall\" CXXFLAGS=\"-U_FORTIFY_SOURCE -fstack-protector -Wall\" ASMFLAGS=\"-U_FORTIFY_SOURCE -fstack-protector -Wall\" cmake -DCMAKE_AR=\"/usr/bin/ar\" -DCMAKE_EXE_LINKER_FLAGS=\"-fuse-ld=gold -Wl -no-as-needed\" -DCMAKE_PREFIX_PATH=\"$EXT_BUILD_DEPS;/abc/def\" -DCMAKE_INSTALL_PREFIX=\"test_rule\" -DCMAKE_BUILD_TYPE=\"Debug\" -DCMAKE_RANLIB=\"\" -GNinja $EXT_BUILD_ROOT/external/test_rule" expected = "CC=\"/usr/bin/gcc\" CXX=\"/usr/bin/gcc\" CFLAGS=\"-U_FORTIFY_SOURCE -fstack-protector -Wall\" CXXFLAGS=\"-U_FORTIFY_SOURCE -fstack-protector -Wall\" ASMFLAGS=\"-U_FORTIFY_SOURCE -fstack-protector -Wall\" cmake -DCMAKE_AR=\"/usr/bin/ar\" -DCMAKE_EXE_LINKER_FLAGS=\"-fuse-ld=gold -Wl -no-as-needed\" -DCMAKE_PREFIX_PATH=\"$EXT_BUILD_DEPS;/abc/def\" -DCMAKE_INSTALL_PREFIX=\"test_rule\" -DCMAKE_BUILD_TYPE=\"Debug\" -DCMAKE_RANLIB=\"\" -GNinja $EXT_BUILD_ROOT/external/test_rule"
asserts.equals(env, expected, script) asserts.equals(env, expected, script)
@ -324,8 +370,19 @@ def _create_min_cmake_script_toolchain_file_test(ctx):
"NOFORTRAN": "on", "NOFORTRAN": "on",
} }
script = create_cmake_script("ws", "linux", "cmake", tools, flags, "test_rule", script = create_cmake_script(
"external/test_rule", False, user_cache, user_env, ["-GNinja"]) "ws",
"linux",
"cmake",
tools,
flags,
"test_rule",
"external/test_rule",
False,
user_cache,
user_env,
["-GNinja"],
)
expected = """cat > crosstool_bazel.cmake <<EOF expected = """cat > crosstool_bazel.cmake <<EOF
set(CMAKE_SYSTEM_NAME "Linux") set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_C_COMPILER "/usr/bin/gcc") set(CMAKE_C_COMPILER "/usr/bin/gcc")
@ -354,8 +411,12 @@ def _create_cmake_script_no_toolchain_file_test(ctx):
) )
flags = CxxFlagsInfo( flags = CxxFlagsInfo(
cc = ["-cc-flag", "-gcc_toolchain", "cc-toolchain"], cc = ["-cc-flag", "-gcc_toolchain", "cc-toolchain"],
cxx = ["--quoted=\"abc def\"", "--sysroot=/abc/sysroot", "--gcc_toolchain", cxx = [
"cxx-toolchain"], "--quoted=\"abc def\"",
"--sysroot=/abc/sysroot",
"--gcc_toolchain",
"cxx-toolchain",
],
cxx_linker_shared = ["shared1", "shared2"], cxx_linker_shared = ["shared1", "shared2"],
cxx_linker_static = ["static"], cxx_linker_static = ["static"],
cxx_linker_executable = ["executable"], cxx_linker_executable = ["executable"],
@ -375,8 +436,19 @@ def _create_cmake_script_no_toolchain_file_test(ctx):
"CMAKE_BUILD_TYPE": "user_type", "CMAKE_BUILD_TYPE": "user_type",
} }
script = create_cmake_script("ws", "linux", "cmake", tools, flags, "test_rule", script = create_cmake_script(
"external/test_rule", True, user_cache, user_env, ["-GNinja"]) "ws",
"linux",
"cmake",
tools,
flags,
"test_rule",
"external/test_rule",
True,
user_cache,
user_env,
["-GNinja"],
)
expected = "CC=\"sink-cc-value\" CXX=\"sink-cxx-value\" CFLAGS=\"-cc-flag -gcc_toolchain cc-toolchain --from-env --additional-flag\" CXXFLAGS=\"--quoted=\\\"abc def\\\" --sysroot=/abc/sysroot --gcc_toolchain cxx-toolchain\" ASMFLAGS=\"assemble assemble-user\" CUSTOM_ENV=\"YES\" cmake -DCMAKE_AR=\"/cxx_linker_static\" -DCMAKE_CXX_LINK_EXECUTABLE=\"became\" -DCMAKE_SHARED_LINKER_FLAGS=\"shared1 shared2\" -DCMAKE_EXE_LINKER_FLAGS=\"executable\" -DCUSTOM_CACHE=\"YES\" -DCMAKE_BUILD_TYPE=\"user_type\" -DCMAKE_PREFIX_PATH=\"$EXT_BUILD_DEPS\" -DCMAKE_INSTALL_PREFIX=\"test_rule\" -DCMAKE_RANLIB=\"\" -GNinja $EXT_BUILD_ROOT/external/test_rule" expected = "CC=\"sink-cc-value\" CXX=\"sink-cxx-value\" CFLAGS=\"-cc-flag -gcc_toolchain cc-toolchain --from-env --additional-flag\" CXXFLAGS=\"--quoted=\\\"abc def\\\" --sysroot=/abc/sysroot --gcc_toolchain cxx-toolchain\" ASMFLAGS=\"assemble assemble-user\" CUSTOM_ENV=\"YES\" cmake -DCMAKE_AR=\"/cxx_linker_static\" -DCMAKE_CXX_LINK_EXECUTABLE=\"became\" -DCMAKE_SHARED_LINKER_FLAGS=\"shared1 shared2\" -DCMAKE_EXE_LINKER_FLAGS=\"executable\" -DCUSTOM_CACHE=\"YES\" -DCMAKE_BUILD_TYPE=\"user_type\" -DCMAKE_PREFIX_PATH=\"$EXT_BUILD_DEPS\" -DCMAKE_INSTALL_PREFIX=\"test_rule\" -DCMAKE_RANLIB=\"\" -GNinja $EXT_BUILD_ROOT/external/test_rule"
asserts.equals(env, expected, script) asserts.equals(env, expected, script)
@ -393,8 +465,12 @@ def _create_cmake_script_toolchain_file_test(ctx):
) )
flags = CxxFlagsInfo( flags = CxxFlagsInfo(
cc = ["-cc-flag", "-gcc_toolchain", "cc-toolchain"], cc = ["-cc-flag", "-gcc_toolchain", "cc-toolchain"],
cxx = ["--quoted=\"abc def\"", "--sysroot=/abc/sysroot", "--gcc_toolchain", cxx = [
"cxx-toolchain"], "--quoted=\"abc def\"",
"--sysroot=/abc/sysroot",
"--gcc_toolchain",
"cxx-toolchain",
],
cxx_linker_shared = ["shared1", "shared2"], cxx_linker_shared = ["shared1", "shared2"],
cxx_linker_static = ["static"], cxx_linker_static = ["static"],
cxx_linker_executable = ["executable"], cxx_linker_executable = ["executable"],
@ -413,8 +489,19 @@ def _create_cmake_script_toolchain_file_test(ctx):
"CUSTOM_CACHE": "YES", "CUSTOM_CACHE": "YES",
} }
script = create_cmake_script("ws", "osx", "cmake", tools, flags, "test_rule", script = create_cmake_script(
"external/test_rule", False, user_cache, user_env, ["-GNinja"]) "ws",
"osx",
"cmake",
tools,
flags,
"test_rule",
"external/test_rule",
False,
user_cache,
user_env,
["-GNinja"],
)
expected = """cat > crosstool_bazel.cmake <<EOF expected = """cat > crosstool_bazel.cmake <<EOF
set(CMAKE_SYSTEM_NAME "Apple") set(CMAKE_SYSTEM_NAME "Apple")
set(CMAKE_SYSROOT "/abc/sysroot") set(CMAKE_SYSROOT "/abc/sysroot")

View File

@ -5,7 +5,6 @@ load(
"//tools/build_defs:shell_script_helper.bzl", "//tools/build_defs:shell_script_helper.bzl",
"convert_shell_script_by_context", "convert_shell_script_by_context",
"do_function_call", "do_function_call",
"replace_exports",
"replace_var_ref", "replace_var_ref",
"split_arguments", "split_arguments",
) )

View File

@ -2,7 +2,7 @@ workspace(name = "standard_cxx_flags_test")
local_repository( local_repository(
name = "rules_foreign_cc", name = "rules_foreign_cc",
path = "../.." path = "../..",
) )
load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies") load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies")

View File

@ -1,6 +1,6 @@
""" TODO """ """ TODO """
load("@rules_foreign_cc//tools/build_defs:cc_toolchain_util.bzl", "CxxFlagsInfo", "get_flags_info") load("@rules_foreign_cc//tools/build_defs:cc_toolchain_util.bzl", "get_flags_info")
def _impl(ctx): def _impl(ctx):
flags = get_flags_info(ctx) flags = get_flags_info(ctx)

View File

@ -6,9 +6,9 @@ load("//tools/build_defs:framework.bzl", "uniq_list_keep_order")
def _uniq_list_keep_order_test(ctx): def _uniq_list_keep_order_test(ctx):
env = unittest.begin(ctx) env = unittest.begin(ctx)
list = [1,2,3,1,4,1,2,3,5,1,2,4,7,5] list = [1, 2, 3, 1, 4, 1, 2, 3, 5, 1, 2, 4, 7, 5]
filtered = uniq_list_keep_order(list) filtered = uniq_list_keep_order(list)
asserts.equals(env, [1,2,3,4,5,7], filtered) asserts.equals(env, [1, 2, 3, 4, 5, 7], filtered)
filteredEmpty = uniq_list_keep_order([]) filteredEmpty = uniq_list_keep_order([])
asserts.equals(env, [], filteredEmpty) asserts.equals(env, [], filteredEmpty)
@ -20,5 +20,5 @@ uniq_list_keep_order_test = unittest.make(_uniq_list_keep_order_test)
def utils_test_suite(): def utils_test_suite():
unittest.suite( unittest.suite(
"utils_test_suite", "utils_test_suite",
uniq_list_keep_order_test uniq_list_keep_order_test,
) )

View File

@ -46,18 +46,16 @@ fi
def define_function(name, text): def define_function(name, text):
lines = [] lines = []
lines += ["function " + name + "() {"] lines.append("function " + name + "() {")
for line_ in text.splitlines(): for line_ in text.splitlines():
lines += [" " + line_] lines.append(" " + line_)
lines += ["}"] lines.append("}")
return "\n".join(lines) return "\n".join(lines)
def replace_in_files(dir, from_, to_): def replace_in_files(dir, from_, to_):
return FunctionAndCall( return FunctionAndCall(
text = """if [ -d "$1" ]; then text = """if [ -d "$1" ]; then
find -L $1 -print -type f \ find -L $1 -print -type f \\( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.cmake" \\) -exec sed -i 's@'"$2"'@'"$3"'@g' {} ';'
\( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.cmake" \) \
-exec sed -i 's@'"$2"'@'"$3"'@g' {} ';'
fi fi
""", """,
) )

View File

@ -91,7 +91,7 @@ def _create_libraries_to_link(ctx, files):
) )
for name_ in names: for name_ in names:
libs += [cc_common.create_library_to_link( libs.append(cc_common.create_library_to_link(
actions = ctx.actions, actions = ctx.actions,
feature_configuration = feature_configuration, feature_configuration = feature_configuration,
cc_toolchain = cc_toolchain, cc_toolchain = cc_toolchain,
@ -100,7 +100,7 @@ def _create_libraries_to_link(ctx, files):
dynamic_library = shared_map.get(name_), dynamic_library = shared_map.get(name_),
interface_library = interface_map.get(name_), interface_library = interface_map.get(name_),
alwayslink = ctx.attr.alwayslink, alwayslink = ctx.attr.alwayslink,
)] ))
return libs return libs
@ -112,7 +112,7 @@ def _filter(list_, predicate, inverse):
for elem in list_: for elem in list_:
check = predicate(elem) check = predicate(elem)
if not inverse and check or inverse and not check: if not inverse and check or inverse and not check:
result += [elem] result.append(elem)
return result return result
def _files_map(files_list): def _files_map(files_list):
@ -366,7 +366,7 @@ def _add_if_needed(arr, add_arr):
if existing == to_add: if existing == to_add:
found = True found = True
if not found: if not found:
filtered += [to_add] filtered.append(to_add)
return arr + filtered return arr + filtered
def absolutize_path_in_str(workspace_name, root_str, text, force = False): def absolutize_path_in_str(workspace_name, root_str, text, force = False):
@ -385,6 +385,7 @@ def absolutize_path_in_str(workspace_name, root_str, text, force = False):
new_text = _prefix(text, "external/", root_str) new_text = _prefix(text, "external/", root_str)
if new_text == text: if new_text == text:
new_text = _prefix(text, workspace_name + "/", root_str) new_text = _prefix(text, workspace_name + "/", root_str)
# absolutize relative by adding our working directory # absolutize relative by adding our working directory
# this works because we ru on windows under msys now # this works because we ru on windows under msys now
if force and new_text == text and not text.startswith("/"): if force and new_text == text and not text.startswith("/"):

View File

@ -18,7 +18,6 @@ load(
"is_debug_mode", "is_debug_mode",
) )
load(":cmake_script.bzl", "create_cmake_script") load(":cmake_script.bzl", "create_cmake_script")
load("//tools/build_defs/shell_toolchain/toolchains:access.bzl", "create_context")
load("//tools/build_defs/native_tools:tool_access.bzl", "get_cmake_data", "get_ninja_data") load("//tools/build_defs/native_tools:tool_access.bzl", "get_cmake_data", "get_ninja_data")
load("@rules_foreign_cc//tools/build_defs:shell_script_helper.bzl", "os_name") load("@rules_foreign_cc//tools/build_defs:shell_script_helper.bzl", "os_name")
@ -62,6 +61,7 @@ def _create_configure_script(configureParameters):
root = root + "/" + ctx.attr.working_directory root = root + "/" + ctx.attr.working_directory
tools = get_tools_info(ctx) tools = get_tools_info(ctx)
# CMake will replace <TARGET> with the actual output file # CMake will replace <TARGET> with the actual output file
flags = get_flags_info(ctx, "<TARGET>") flags = get_flags_info(ctx, "<TARGET>")
no_toolchain_file = ctx.attr.cache_entries.get("CMAKE_TOOLCHAIN_FILE") or not ctx.attr.generate_crosstool_file no_toolchain_file = ctx.attr.cache_entries.get("CMAKE_TOOLCHAIN_FILE") or not ctx.attr.generate_crosstool_file

View File

@ -124,9 +124,9 @@ def _create_crosstool_file_text(toolchain_dict, user_cache, user_env):
lines = [] lines = []
for key in toolchain_dict: for key in toolchain_dict:
if ("CMAKE_AR" == key): if ("CMAKE_AR" == key):
lines += ["set({} \"{}\" {})".format(key, toolchain_dict[key], "CACHE FILEPATH \"Archiver\"")] lines.append("set({} \"{}\" {})".format(key, toolchain_dict[key], "CACHE FILEPATH \"Archiver\""))
continue continue
lines += ["set({} \"{}\")".format(key, toolchain_dict[key])] lines.append("set({} \"{}\")".format(key, toolchain_dict[key]))
cache_entries.update({ cache_entries.update({
"CMAKE_TOOLCHAIN_FILE": "crosstool_bazel.cmake", "CMAKE_TOOLCHAIN_FILE": "crosstool_bazel.cmake",
@ -237,9 +237,9 @@ def _fill_crossfile_from_toolchain(workspace_name, target_os, tools, flags):
dict["CMAKE_AR"] = _absolutize(workspace_name, tools.cxx_linker_static, True) dict["CMAKE_AR"] = _absolutize(workspace_name, tools.cxx_linker_static, True)
if tools.cxx_linker_static.endswith("/libtool"): if tools.cxx_linker_static.endswith("/libtool"):
dict["CMAKE_C_ARCHIVE_CREATE"] = "<CMAKE_AR> %s <OBJECTS>" % \ dict["CMAKE_C_ARCHIVE_CREATE"] = "<CMAKE_AR> %s <OBJECTS>" % \
" ".join(flags.cxx_linker_static) " ".join(flags.cxx_linker_static)
dict["CMAKE_CXX_ARCHIVE_CREATE"] = "<CMAKE_AR> %s <OBJECTS>" % \ dict["CMAKE_CXX_ARCHIVE_CREATE"] = "<CMAKE_AR> %s <OBJECTS>" % \
" ".join(flags.cxx_linker_static) " ".join(flags.cxx_linker_static)
if tools.cxx_linker_executable and tools.cxx_linker_executable != tools.cxx: if tools.cxx_linker_executable and tools.cxx_linker_executable != tools.cxx:
normalized_path = _absolutize(workspace_name, tools.cxx_linker_executable) normalized_path = _absolutize(workspace_name, tools.cxx_linker_executable)

View File

@ -1,5 +1,5 @@
load(":cc_toolchain_util.bzl", "absolutize_path_in_str") load(":cc_toolchain_util.bzl", "absolutize_path_in_str")
load(":framework.bzl", "ForeignCcDeps", "get_foreign_cc_dep") load(":framework.bzl", "get_foreign_cc_dep")
def create_configure_script( def create_configure_script(
workspace_name, workspace_name,
@ -18,23 +18,23 @@ def create_configure_script(
script = [] script = []
for ext_dir in inputs.ext_build_dirs: for ext_dir in inputs.ext_build_dirs:
script += ["##increment_pkg_config_path## $$EXT_BUILD_ROOT$$/" + ext_dir.path] script.append("##increment_pkg_config_path## $$EXT_BUILD_ROOT$$/" + ext_dir.path)
script += ["echo \"PKG_CONFIG_PATH=$$PKG_CONFIG_PATH$$\""] script.append("echo \"PKG_CONFIG_PATH=$$PKG_CONFIG_PATH$$\"")
configure_path = "$$EXT_BUILD_ROOT$$/{root}/{configure}".format( configure_path = "$$EXT_BUILD_ROOT$$/{root}/{configure}".format(
root = root, root = root,
configure = configure_command, configure = configure_command,
) )
if (configure_in_place): if (configure_in_place):
script += ["##symlink_contents_to_dir## $$EXT_BUILD_ROOT$$/{} $$BUILD_TMPDIR$$".format(root)] script.append("##symlink_contents_to_dir## $$EXT_BUILD_ROOT$$/{} $$BUILD_TMPDIR$$".format(root))
configure_path = "$$BUILD_TMPDIR$$/{}".format(configure_command) configure_path = "$$BUILD_TMPDIR$$/{}".format(configure_command)
script += ["{env_vars} \"{configure}\" --prefix=$$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$ {user_options}".format( script.append("{env_vars} \"{configure}\" --prefix=$$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$ {user_options}".format(
env_vars = env_vars_string, env_vars = env_vars_string,
configure = configure_path, configure = configure_path,
user_options = " ".join(user_options), user_options = " ".join(user_options),
)] ))
return "\n".join(script) return "\n".join(script)
def create_make_script( def create_make_script(
@ -50,12 +50,12 @@ def create_make_script(
env_vars_string = get_env_vars(workspace_name, tools, flags, user_vars, deps, inputs) env_vars_string = get_env_vars(workspace_name, tools, flags, user_vars, deps, inputs)
script = [] script = []
for ext_dir in inputs.ext_build_dirs: for ext_dir in inputs.ext_build_dirs:
script += ["##increment_pkg_config_path## $$EXT_BUILD_ROOT$$/" + ext_dir.path] script.append("##increment_pkg_config_path## $$EXT_BUILD_ROOT$$/" + ext_dir.path)
script += ["echo \"PKG_CONFIG_PATH=$$PKG_CONFIG_PATH$$\""] script.append("echo \"PKG_CONFIG_PATH=$$PKG_CONFIG_PATH$$\"")
script += ["##symlink_contents_to_dir## $$EXT_BUILD_ROOT$$/{} $$BUILD_TMPDIR$$".format(root)] script.append("##symlink_contents_to_dir## $$EXT_BUILD_ROOT$$/{} $$BUILD_TMPDIR$$".format(root))
script += ["" + " && ".join(make_commands)] script.append("" + " && ".join(make_commands))
return "\n".join(script) return "\n".join(script)
def get_env_vars( def get_env_vars(
@ -87,7 +87,7 @@ def _define_deps_flags(deps, inputs):
dir_ = lib.dirname dir_ = lib.dirname
if not gen_dirs_set.get(dir_): if not gen_dirs_set.get(dir_):
gen_dirs_set[dir_] = 1 gen_dirs_set[dir_] = 1
lib_dirs += ["-L$$EXT_BUILD_ROOT$$/" + dir_] lib_dirs.append("-L$$EXT_BUILD_ROOT$$/" + dir_)
include_dirs_set = {} include_dirs_set = {}
for include_dir in inputs.include_dirs: for include_dir in inputs.include_dirs:
@ -113,8 +113,8 @@ def _define_deps_flags(deps, inputs):
gen_dirs_set[artifact.gen_dir] = 1 gen_dirs_set[artifact.gen_dir] = 1
dir_name = artifact.gen_dir.basename dir_name = artifact.gen_dir.basename
include_dirs += ["-I$$EXT_BUILD_DEPS$$/{}/{}".format(dir_name, artifact.include_dir_name)] include_dirs.append("-I$$EXT_BUILD_DEPS$$/{}/{}".format(dir_name, artifact.include_dir_name))
lib_dirs += ["-L$$EXT_BUILD_DEPS$$/{}/{}".format(dir_name, artifact.lib_dir_name)] lib_dirs.append("-L$$EXT_BUILD_DEPS$$/{}/{}".format(dir_name, artifact.lib_dir_name))
return struct( return struct(
libs = lib_dirs, libs = lib_dirs,

View File

@ -391,7 +391,7 @@ def _get_transitive_artifacts(deps):
for dep in deps: for dep in deps:
foreign_dep = get_foreign_cc_dep(dep) foreign_dep = get_foreign_cc_dep(dep)
if foreign_dep: if foreign_dep:
artifacts += [foreign_dep.artifacts] artifacts.append(foreign_dep.artifacts)
return artifacts return artifacts
def _print_env(): def _print_env():
@ -432,10 +432,10 @@ def _copy_deps_and_tools(files):
lines.append("##symlink_to_dir## $$EXT_BUILD_ROOT$$/{} $$EXT_BUILD_DEPS$$/bin/".format(tool)) lines.append("##symlink_to_dir## $$EXT_BUILD_ROOT$$/{} $$EXT_BUILD_DEPS$$/bin/".format(tool))
for ext_dir in files.ext_build_dirs: for ext_dir in files.ext_build_dirs:
lines += ["##symlink_to_dir## $$EXT_BUILD_ROOT$$/{} $$EXT_BUILD_DEPS$$".format(_file_path(ext_dir))] lines.append("##symlink_to_dir## $$EXT_BUILD_ROOT$$/{} $$EXT_BUILD_DEPS$$".format(_file_path(ext_dir)))
lines += ["##children_to_path## $$EXT_BUILD_DEPS$$/bin"] lines.append("##children_to_path## $$EXT_BUILD_DEPS$$/bin")
lines += ["##path## $$EXT_BUILD_DEPS$$/bin"] lines.append("##path## $$EXT_BUILD_DEPS$$/bin")
return lines return lines
@ -448,10 +448,10 @@ def _symlink_contents_to_dir(dir_name, files_list):
lines = ["##mkdirs## $$EXT_BUILD_DEPS$$/" + dir_name] lines = ["##mkdirs## $$EXT_BUILD_DEPS$$/" + dir_name]
for file in files_list: for file in files_list:
path = _file_path(file).strip() path = _file_path(file).strip()
if path: if path:
lines += ["##symlink_contents_to_dir## \ lines.append("##symlink_contents_to_dir## \
$$EXT_BUILD_ROOT$$/{} $$EXT_BUILD_DEPS$$/{}".format(path, dir_name)] $$EXT_BUILD_ROOT$$/{} $$EXT_BUILD_DEPS$$/{}".format(path, dir_name))
return lines return lines
@ -549,7 +549,7 @@ def _define_inputs(attrs):
for dep in attrs.deps: for dep in attrs.deps:
external_deps = get_foreign_cc_dep(dep) external_deps = get_foreign_cc_dep(dep)
cc_infos += [dep[CcInfo]] cc_infos.append(dep[CcInfo])
if external_deps: if external_deps:
ext_build_dirs += [artifact.gen_dir for artifact in external_deps.artifacts.to_list()] ext_build_dirs += [artifact.gen_dir for artifact in external_deps.artifacts.to_list()]
@ -568,7 +568,7 @@ def _define_inputs(attrs):
tools_files = [] tools_files = []
for tool in attrs.tools_deps: for tool in attrs.tools_deps:
tool_root = detect_root(tool) tool_root = detect_root(tool)
tools_roots += [tool_root] tools_roots.append(tool_root)
for file_list in tool.files.to_list(): for file_list in tool.files.to_list():
tools_files += _list(file_list) tools_files += _list(file_list)
@ -588,12 +588,12 @@ def _define_inputs(attrs):
deps_compilation_info = cc_info_merged.compilation_context, deps_compilation_info = cc_info_merged.compilation_context,
deps_linking_info = cc_info_merged.linking_context, deps_linking_info = cc_info_merged.linking_context,
ext_build_dirs = ext_build_dirs, ext_build_dirs = ext_build_dirs,
declared_inputs = filter_containing_dirs_from_inputs(attrs.lib_source.files.to_list()) declared_inputs = filter_containing_dirs_from_inputs(attrs.lib_source.files.to_list()) +
+ bazel_libs bazel_libs +
+ tools_files tools_files +
+ attrs.additional_inputs attrs.additional_inputs +
+ cc_info_merged.compilation_context.headers.to_list() cc_info_merged.compilation_context.headers.to_list() +
+ ext_build_dirs, ext_build_dirs,
) )
"""When the directories are also passed in the filegroup with the sources, """When the directories are also passed in the filegroup with the sources,
@ -601,6 +601,7 @@ we get into a situation when we have containing in the sources list,
which is not allowed by Bazel (execroot creation code fails). which is not allowed by Bazel (execroot creation code fails).
The parent directories will be created for us in the execroot anyway, The parent directories will be created for us in the execroot anyway,
so we filter them out.""" so we filter them out."""
def filter_containing_dirs_from_inputs(input_files_list): def filter_containing_dirs_from_inputs(input_files_list):
# This puts directories in front of their children in list # This puts directories in front of their children in list
sorted_list = sorted(input_files_list) sorted_list = sorted(input_files_list)
@ -628,7 +629,8 @@ def get_foreign_cc_dep(dep):
# consider optimization here to do not iterate both collections # consider optimization here to do not iterate both collections
def _get_headers(compilation_info): def _get_headers(compilation_info):
include_dirs = compilation_info.system_includes.to_list() + \ include_dirs = compilation_info.system_includes.to_list() + \
compilation_info.includes.to_list() compilation_info.includes.to_list()
# do not use quote includes, currently they do not contain # do not use quote includes, currently they do not contain
# library-specific information # library-specific information
include_dirs = collections.uniq(include_dirs) include_dirs = collections.uniq(include_dirs)
@ -641,7 +643,7 @@ def _get_headers(compilation_info):
included = True included = True
break break
if not included: if not included:
headers += [header] headers.append(header)
return struct( return struct(
headers = headers, headers = headers,
include_dirs = include_dirs, include_dirs = include_dirs,

View File

@ -1,4 +1,4 @@
load(":native_tools_toolchain.bzl", "ToolInfo", "access_tool") load(":native_tools_toolchain.bzl", "access_tool")
def get_cmake_data(ctx): def get_cmake_data(ctx):
return _access_and_expect_label_copied("@rules_foreign_cc//tools/build_defs:cmake_toolchain", ctx, "cmake") return _access_and_expect_label_copied("@rules_foreign_cc//tools/build_defs:cmake_toolchain", ctx, "cmake")

View File

@ -20,7 +20,7 @@ def get(file_name):
def _mapping_text(ids): def _mapping_text(ids):
data_ = [] data_ = []
for id in ids: for id in ids:
data_ += ["{id} = wrapper_{id}".format(id = id)] data_.append("{id} = wrapper_{id}".format(id = id))
return "_MAPPING = dict(\n{data}\n)".format(data = ",\n".join(data_)) return "_MAPPING = dict(\n{data}\n)".format(data = ",\n".join(data_))
def _load_and_wrapper_text(id, file_path, symbols): def _load_and_wrapper_text(id, file_path, symbols):
@ -30,8 +30,8 @@ def _load_and_wrapper_text(id, file_path, symbols):
wrapper_statement = "wrapper_{id} = dict({data})".format(id = id, data = data) wrapper_statement = "wrapper_{id} = dict({data})".format(id = id, data = data)
return struct( return struct(
load_ = load_statement, load_ = load_statement,
wrapper = wrapper_statement wrapper = wrapper_statement,
) )
def id_from_file(file_name): def id_from_file(file_name):
(before, middle, after) = file_name.partition(".") (before, middle, after) = file_name.partition(".")
@ -55,16 +55,16 @@ def _generate_overloads(rctx):
wrappers = [] wrappers = []
for file_ in rctx.attr.files: for file_ in rctx.attr.files:
id = id_from_file(file_.name) id = id_from_file(file_.name)
ids += [id] ids.append(id)
copy = _copy_file(rctx, file_) copy = _copy_file(rctx, file_)
load_and_wrapper = _load_and_wrapper_text(id, copy, symbols) load_and_wrapper = _load_and_wrapper_text(id, copy, symbols)
loads += [load_and_wrapper.load_] loads.append(load_and_wrapper.load_)
wrappers += [load_and_wrapper.wrapper] wrappers.append(load_and_wrapper.wrapper)
lines += loads lines += loads
lines += wrappers lines += wrappers
lines += [_mapping_text(ids)] lines.append(_mapping_text(ids))
lines += [_provider_text(symbols)] lines.append(_provider_text(symbols))
lines += [_getter_text()] lines.append(_getter_text())
rctx.file("toolchain_data_defs.bzl", "\n".join(lines)) rctx.file("toolchain_data_defs.bzl", "\n".join(lines))
rctx.file("BUILD", "") rctx.file("BUILD", "")

View File

@ -1,4 +1,3 @@
load("@bazel_skylib//lib:types.bzl", "types")
load("//tools/build_defs/shell_toolchain/toolchains:commands.bzl", "PLATFORM_COMMANDS") load("//tools/build_defs/shell_toolchain/toolchains:commands.bzl", "PLATFORM_COMMANDS")
load(":function_and_call.bzl", "FunctionAndCall") load(":function_and_call.bzl", "FunctionAndCall")

View File

@ -1,6 +1,6 @@
load("@rules_foreign_cc//tools/build_defs/shell_toolchain/toolchains:function_and_call.bzl", "FunctionAndCall") load("@rules_foreign_cc//tools/build_defs/shell_toolchain/toolchains:function_and_call.bzl", "FunctionAndCall")
_REPLACE_VALUE = "\${EXT_BUILD_DEPS}" _REPLACE_VALUE = "\\${EXT_BUILD_DEPS}"
def os_name(): def os_name():
return "linux" return "linux"
@ -46,18 +46,16 @@ fi
def define_function(name, text): def define_function(name, text):
lines = [] lines = []
lines += ["function " + name + "() {"] lines.append("function " + name + "() {")
for line_ in text.splitlines(): for line_ in text.splitlines():
lines += [" " + line_] lines.append(" " + line_)
lines += ["}"] lines.append("}")
return "\n".join(lines) return "\n".join(lines)
def replace_in_files(dir, from_, to_): def replace_in_files(dir, from_, to_):
return FunctionAndCall( return FunctionAndCall(
text = """if [ -d "$1" ]; then text = """if [ -d "$1" ]; then
find -L $1 -type f \ find -L $1 -type f \\( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.cmake" \\) -exec sed -i 's@'"$2"'@'"$3"'@g' {} ';'
\( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.cmake" \) \
-exec sed -i 's@'"$2"'@'"$3"'@g' {} ';'
fi fi
""", """,
) )

View File

@ -1,6 +1,6 @@
load("@rules_foreign_cc//tools/build_defs/shell_toolchain/toolchains:function_and_call.bzl", "FunctionAndCall") load("@rules_foreign_cc//tools/build_defs/shell_toolchain/toolchains:function_and_call.bzl", "FunctionAndCall")
_REPLACE_VALUE = "\${EXT_BUILD_DEPS}" _REPLACE_VALUE = "\\${EXT_BUILD_DEPS}"
def os_name(): def os_name():
return "linux" return "linux"
@ -46,18 +46,16 @@ fi
def define_function(name, text): def define_function(name, text):
lines = [] lines = []
lines += ["function " + name + "() {"] lines.append("function " + name + "() {")
for line_ in text.splitlines(): for line_ in text.splitlines():
lines += [" " + line_] lines.append(" " + line_)
lines += ["}"] lines.append("}")
return "\n".join(lines) return "\n".join(lines)
def replace_in_files(dir, from_, to_): def replace_in_files(dir, from_, to_):
return FunctionAndCall( return FunctionAndCall(
text = """if [ -d "$1" ]; then text = """if [ -d "$1" ]; then
find -L $1 -type f \ find -L $1 -type f \\( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.cmake" \\) -exec sed -i 's@'"$2"'@'"$3"'@g' {} ';'
\( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.cmake" \) \
-exec sed -i 's@'"$2"'@'"$3"'@g' {} ';'
fi fi
""", """,
) )

View File

@ -1,6 +1,6 @@
load("@rules_foreign_cc//tools/build_defs/shell_toolchain/toolchains:function_and_call.bzl", "FunctionAndCall") load("@rules_foreign_cc//tools/build_defs/shell_toolchain/toolchains:function_and_call.bzl", "FunctionAndCall")
_REPLACE_VALUE = "\${EXT_BUILD_DEPS}" _REPLACE_VALUE = "\\${EXT_BUILD_DEPS}"
def os_name(): def os_name():
return "osx" return "osx"
@ -46,17 +46,16 @@ fi
def define_function(name, text): def define_function(name, text):
lines = [] lines = []
lines += ["function " + name + "() {"] lines.append("function " + name + "() {")
for line_ in text.splitlines(): for line_ in text.splitlines():
lines += [" " + line_] lines.append(" " + line_)
lines += ["}"] lines.append("}")
return "\n".join(lines) return "\n".join(lines)
def replace_in_files(dir, from_, to_): def replace_in_files(dir, from_, to_):
return FunctionAndCall( return FunctionAndCall(
text = """if [ -d "$1" ]; then text = """if [ -d "$1" ]; then
find -L -f $1 \( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.cmake" \) \ find -L -f $1 \\( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.cmake" \\) -exec sed -i -e 's@'"$2"'@'"$3"'@g' {} ';'
-exec sed -i -e 's@'"$2"'@'"$3"'@g' {} ';'
fi fi
""", """,
) )

View File

@ -1,6 +1,6 @@
load("@rules_foreign_cc//tools/build_defs/shell_toolchain/toolchains:function_and_call.bzl", "FunctionAndCall") load("@rules_foreign_cc//tools/build_defs/shell_toolchain/toolchains:function_and_call.bzl", "FunctionAndCall")
_REPLACE_VALUE = "\${EXT_BUILD_DEPS}" _REPLACE_VALUE = "\\${EXT_BUILD_DEPS}"
def os_name(): def os_name():
return "windows" return "windows"
@ -46,18 +46,16 @@ fi
def define_function(name, text): def define_function(name, text):
lines = [] lines = []
lines += ["function " + name + "() {"] lines.append("function " + name + "() {")
for line_ in text.splitlines(): for line_ in text.splitlines():
lines += [" " + line_] lines.append(" " + line_)
lines += ["}"] lines.append("}")
return "\n".join(lines) return "\n".join(lines)
def replace_in_files(dir, from_, to_): def replace_in_files(dir, from_, to_):
return FunctionAndCall( return FunctionAndCall(
text = """if [ -d "$1" ]; then text = """if [ -d "$1" ]; then
$REAL_FIND -L $1 -type f \ $REAL_FIND -L $1 -type f \\( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.cmake" \\) -exec sed -i 's@'"$2"'@'"$3"'@g' {} ';'
\( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.cmake" \) \
-exec sed -i 's@'"$2"'@'"$3"'@g' {} ';'
fi fi
""", """,
) )

View File

@ -1,4 +1,3 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//for_workspace:repositories.bzl", "repositories") load("//for_workspace:repositories.bzl", "repositories")
load( load(
"//tools/build_defs/shell_toolchain/toolchains:ws_defs.bzl", "//tools/build_defs/shell_toolchain/toolchains:ws_defs.bzl",
@ -58,8 +57,7 @@ def rules_foreign_cc_dependencies(
native_tools_toolchains = [], native_tools_toolchains = [],
register_default_tools = True, register_default_tools = True,
additonal_shell_toolchain_mappings = [], additonal_shell_toolchain_mappings = [],
additonal_shell_toolchain_package = None, additonal_shell_toolchain_package = None):
):
""" Call this function from the WORKSPACE file to initialize rules_foreign_cc """ Call this function from the WORKSPACE file to initialize rules_foreign_cc
dependencies and let neccesary code generation happen dependencies and let neccesary code generation happen
(Code generation is needed to support different variants of the C++ Starlark API.). (Code generation is needed to support different variants of the C++ Starlark API.).
@ -88,7 +86,7 @@ def rules_foreign_cc_dependencies(
""" """
repositories() repositories()
_read_build_options(name = "foreign_cc_platform_utils") _read_build_options(name = "foreign_cc_platform_utils")
bazel_version(name="rules_foreign_cc_bazel_version") bazel_version(name = "rules_foreign_cc_bazel_version")
shell_toolchain_workspace_initalization( shell_toolchain_workspace_initalization(
additonal_shell_toolchain_mappings, additonal_shell_toolchain_mappings,