Skip to content

Commit

Permalink
Merge pull request #260 from crtrott/fix_include_guard_for_single_header
Browse files Browse the repository at this point in the history
Fix single header and backward breaking change
  • Loading branch information
crtrott authored May 3, 2023
2 parents 3950fa1 + 1230fe8 commit bca0e55
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
1 change: 1 addition & 0 deletions include/experimental/mdarray
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
#define MDSPAN_IMPL_PROPOSED_NAMESPACE experimental
#endif

#include "mdspan"
#include "../mdspan/mdarray.hpp"
14 changes: 13 additions & 1 deletion include/experimental/mdspan
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,16 @@
#define MDSPAN_IMPL_PROPOSED_NAMESPACE experimental
#endif

#include "../mdspan/mdspan.hpp"
#include "../mdspan/mdspan.hpp"

// backward compatibility import into experimental
namespace MDSPAN_IMPL_STANDARD_NAMESPACE {
namespace MDSPAN_IMPL_PROPOSED_NAMESPACE {
using ::MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan;
using ::MDSPAN_IMPL_STANDARD_NAMESPACE::extents;
using ::MDSPAN_IMPL_STANDARD_NAMESPACE::layout_left;
using ::MDSPAN_IMPL_STANDARD_NAMESPACE::layout_right;
using ::MDSPAN_IMPL_STANDARD_NAMESPACE::layout_stride;
using ::MDSPAN_IMPL_STANDARD_NAMESPACE::default_accessor;
}
}
4 changes: 3 additions & 1 deletion include/mdspan/mdarray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
//
//@HEADER

#pragma once
#ifndef MDARRAY_HPP_
#define MDARRAY_HPP_

#ifndef MDSPAN_IMPL_STANDARD_NAMESPACE
#define MDSPAN_IMPL_STANDARD_NAMESPACE Kokkos
Expand All @@ -27,3 +28,4 @@
#include "mdspan.hpp"
#include "../experimental/__p1684_bits/mdarray.hpp"

#endif // MDARRAY_HPP_
5 changes: 4 additions & 1 deletion include/mdspan/mdspan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
//
//@HEADER

#pragma once
#ifndef MDSPAN_HPP_
#define MDSPAN_HPP_

#ifndef MDSPAN_IMPL_STANDARD_NAMESPACE
#define MDSPAN_IMPL_STANDARD_NAMESPACE Kokkos
Expand All @@ -36,3 +37,5 @@
#if MDSPAN_HAS_CXX_17
#include "../experimental/__p2630_bits/submdspan.hpp"
#endif

#endif // MDSPAN_HPP_
21 changes: 12 additions & 9 deletions make_single_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import os
from os.path import dirname, join as path_join, abspath, exists

from pathlib import Path

extra_paths = [path_join(dirname(abspath(__file__)), "include")]


Expand All @@ -31,19 +33,20 @@ def process_file(
if m_inc:
inc_name = m_inc.group(1)
inc_path = find_file(inc_name, file_path)
if inc_path not in processed_files:
if inc_path is not None:
processed_files += [inc_path]
if inc_path is not None:
inc_path_res = str(Path(inc_path).resolve())
if inc_path_res not in processed_files:
processed_files += [inc_path_res]
process_file(
inc_path,
inc_path_res,
out_lines,
front_matter_lines,
back_matter_lines,
processed_files,
)
else:
# assume it's a system header
out_lines += [line]
else:
# assume it's a system header
out_lines += [line]
continue
m_once = re.match(r"#pragma once\s*", line)
# ignore pragma once; we're handling it here
Expand All @@ -65,7 +68,7 @@ def process_file(
if __name__ == "__main__":
print(
process_file(
abspath(sys.argv[1]),
str(Path(sys.argv[1]).resolve()),
[],
# We use an include guard instead of `#pragma once` because Godbolt will
# cause complaints about `#pragma once` when they are used in URL includes.
Expand All @@ -74,6 +77,6 @@ def process_file(
"#define _MDSPAN_SINGLE_HEADER_INCLUDE_GUARD_\n",
],
["#endif // _MDSPAN_SINGLE_HEADER_INCLUDE_GUARD_\n"],
[abspath(sys.argv[1])],
[str(Path(sys.argv[1]).resolve())],
)
)

0 comments on commit bca0e55

Please sign in to comment.