Skip to content

Commit abe0d10

Browse files
committed
Use custom absolute path checking function
1 parent c71bdc4 commit abe0d10

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

cc/common/cc_helper.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# limitations under the License.
1414
"""Utility functions for C++ rules."""
1515

16-
load("@bazel_skylib//lib:paths.bzl", "paths")
1716
load("//cc:find_cc_toolchain.bzl", "CC_TOOLCHAIN_TYPE")
17+
load("//cc/private:paths.bzl", "is_path_absolute")
1818
load("//cc/private/rules_impl:objc_common.bzl", "objc_common")
1919
load(":cc_common.bzl", "cc_common")
2020
load(
@@ -790,7 +790,7 @@ def _include_dirs(ctx, additional_make_variable_substitutions):
790790
package_source_root = _package_source_root(ctx.label.workspace_name, package, sibling_repository_layout)
791791
for include in ctx.attr.includes:
792792
includes_attr = _expand(ctx, include, additional_make_variable_substitutions)
793-
if paths.is_absolute(includes_attr):
793+
if is_path_absolute(includes_attr):
794794
continue
795795
includes_path = get_relative_path(package_exec_path, includes_attr)
796796
if not sibling_repository_layout and path_contains_up_level_references(includes_path):

cc/common/cc_helper_internal.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Only use those within C++ implementation. The others need to go through cc_commo
1919
"""
2020

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

2324
# LINT.IfChange(forked_exports)
2425

@@ -196,7 +197,7 @@ def repository_exec_path(repository, sibling_repository_layout):
196197
# LINT.ThenChange(https://github.com/bazelbuild/bazel/blob/master/src/main/starlark/builtins_bzl/common/cc/cc_helper_internal.bzl:forked_exports)
197198

198199
def get_relative_path(path_a, path_b):
199-
if paths.is_absolute(path_b):
200+
if is_path_absolute(path_b):
200201
return path_b
201202
return paths.normalize(paths.join(path_a, path_b))
202203

cc/private/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ filegroup(
1616
name = "srcs",
1717
srcs = glob([
1818
"**/BUILD",
19+
"*.bzl",
1920
]) + [
2021
"//cc/private/rules_impl:srcs",
2122
"//cc/private/toolchain:srcs",

cc/private/paths.bzl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2025 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
def is_path_absolute(path):
16+
if path.startswith("/"):
17+
return True
18+
19+
# Check for DOS-style absolute paths for Windows
20+
return len(path) >= 3 and \
21+
path[0].isalpha() and \
22+
path[1] == ":" and \
23+
path[2] in ("/", "\\")

cc/toolchains/args.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# limitations under the License.
1414
"""All providers for rule-based bazel toolchain config."""
1515

16-
load("@bazel_skylib//lib:paths.bzl", "paths")
1716
load("@bazel_skylib//rules/directory:providers.bzl", "DirectoryInfo")
17+
load("//cc/private:paths.bzl", "is_path_absolute")
1818
load("//cc/toolchains/impl:args_utils.bzl", "validate_nested_args")
1919
load(
2020
"//cc/toolchains/impl:collect.bzl",
@@ -49,7 +49,7 @@ def _cc_args_impl(ctx):
4949
)
5050

5151
for path in ctx.attr.allowlist_absolute_include_directories:
52-
if not paths.is_absolute(path):
52+
if not is_path_absolute(path):
5353
fail("`{}` is not an absolute paths".format(path))
5454

5555
nested = None

0 commit comments

Comments
 (0)