Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cc/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bzl_library(
srcs = glob(["*.bzl"]),
visibility = ["//visibility:public"],
deps = [
"//cc/private:paths_bzl",
"//cc/private/rules_impl:native_bzl",
],
)
Expand All @@ -29,6 +30,7 @@ bzl_library(
visibility = ["//visibility:public"],
deps = [
":visibility_bzl",
"//cc/private:paths_bzl",
"//cc/private/rules_impl:objc_common",
],
)
Expand Down
3 changes: 2 additions & 1 deletion cc/common/cc_helper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""Utility functions for C++ rules."""

load("//cc:find_cc_toolchain.bzl", "CC_TOOLCHAIN_TYPE")
load("//cc/private:paths.bzl", "is_path_absolute")
load("//cc/private/rules_impl:objc_common.bzl", "objc_common")
load(":cc_common.bzl", "cc_common")
load(
Expand Down Expand Up @@ -807,7 +808,7 @@ def _include_dirs(ctx, additional_make_variable_substitutions):
package_source_root = _package_source_root(ctx.label.workspace_name, package, sibling_repository_layout)
for include in ctx.attr.includes:
includes_attr = _expand(ctx, include, additional_make_variable_substitutions)
if includes_attr.startswith("/"):
if is_path_absolute(includes_attr):
continue
includes_path = get_relative_path(package_exec_path, includes_attr)
if not sibling_repository_layout and path_contains_up_level_references(includes_path):
Expand Down
3 changes: 2 additions & 1 deletion cc/common/cc_helper_internal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Only use those within C++ implementation. The others need to go through cc_commo
"""

load("@bazel_skylib//lib:paths.bzl", "paths")
load("//cc/private:paths.bzl", "is_path_absolute")

# LINT.IfChange(forked_exports)

Expand Down Expand Up @@ -198,7 +199,7 @@ def repository_exec_path(repository, sibling_repository_layout):
# LINT.ThenChange(https://github.com/bazelbuild/bazel/blob/master/src/main/starlark/builtins_bzl/common/cc/cc_helper_internal.bzl:forked_exports)

def get_relative_path(path_a, path_b):
if paths.is_absolute(path_b):
if is_path_absolute(path_b):
return path_b
return paths.normalize(paths.join(path_a, path_b))

Expand Down
9 changes: 9 additions & 0 deletions cc/private/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

filegroup(
name = "srcs",
srcs = glob([
"**/BUILD",
"*.bzl",
]) + [
"//cc/private/rules_impl:srcs",
"//cc/private/toolchain:srcs",
],
visibility = ["//visibility:public"],
)

bzl_library(
name = "paths_bzl",
srcs = ["paths.bzl"],
visibility = ["//cc:__subpackages__"],
)
40 changes: 40 additions & 0 deletions cc/private/paths.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2025 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Paths utility functions."""

def is_path_absolute(path):
"""Checks whether a path is absolute or not.

Note that is does not take the execution platform into account.

This was implemented to replace skylib's paths.is_absolute, which
only checks for the presence of a colon character in the second position
of the paths

Args:
path: A path (as a string).

Returns:
`True` if `path` is an absolute path.
"""

if path.startswith("/"):
return True

# Check for DOS-style absolute paths for Windows
return len(path) >= 3 and \
path[0].isalpha() and \
path[1] == ":" and \
path[2] in ("/", "\\")
1 change: 1 addition & 0 deletions cc/toolchains/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ bzl_library(
"//cc:action_names_bzl",
"//cc:cc_toolchain_config_lib_bzl",
"//cc:find_cc_toolchain_bzl",
"//cc/private:paths_bzl",
"//cc/private/rules_impl:cc_flags_supplier_lib_bzl",
"//cc/private/rules_impl:native_bzl",
"//cc/toolchains/impl:toolchain_impl_rules",
Expand Down
3 changes: 2 additions & 1 deletion cc/toolchains/args.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""All providers for rule-based bazel toolchain config."""

load("@bazel_skylib//rules/directory:providers.bzl", "DirectoryInfo")
load("//cc/private:paths.bzl", "is_path_absolute")
load("//cc/toolchains/impl:args_utils.bzl", "validate_env_variables", "validate_nested_args")
load(
"//cc/toolchains/impl:collect.bzl",
Expand Down Expand Up @@ -50,7 +51,7 @@ def _cc_args_impl(ctx):
)

for path in ctx.attr.allowlist_absolute_include_directories:
if not path.startswith("/"):
if not is_path_absolute(path):
fail("`{}` is not an absolute paths".format(path))

nested = None
Expand Down