Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
mcpp/src/modgraph/validate.cppm at example/graphics-stack · mcpp-community/mcpp · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
mcpp-community
/
mcpp
Public
Notifications
You must be signed in to change notification settings
Fork
14
Star
131
Code
Issues
35
Pull requests
3
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
example/graphics-stack
Breadcrumbs
mcpp
/
src
/
modgraph
/
validate.cppm
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
212 lines (189 loc) · 8.49 KB
example/graphics-stack
Breadcrumbs
mcpp
/
src
/
modgraph
/
validate.cppm
Copy path
Top
File metadata and controls
Code
Blame
212 lines (189 loc) · 8.49 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//
mcpp.modgraph.validate — naming/lint + topology checks.
export
module
mcpp.modgraph.validate;
import
std;
import
mcpp.manifest;
import
mcpp.modgraph.graph;
import
mcpp.modgraph.scanner;
export
namespace
mcpp
::modgraph {
struct
ValidateError
{
std::filesystem::path path;
//
optional
std::string message;
};
struct
ValidateReport
{
std::vector<ValidateError> errors;
std::vector<ValidateError> warnings;
std::vector<std::
size_t
> topoOrder;
//
valid only if errors empty
bool
ok
()
const
{
return
errors.
empty
(); }
};
ValidateReport
validate
(
const
Graph& g,
const
mcpp::manifest::Manifest& manifest);
//
Same as `validate` plus a project-root path used to verify that the
//
lib-root convention file actually exists on disk. Pass an empty path
//
to disable the on-disk check (used by unit tests that build a Graph
//
in memory without writing source files).
ValidateReport
validate
(
const
Graph& g,
const
mcpp::manifest::Manifest& manifest,
const
std::filesystem::path& projectRoot);
bool
is_public_package_name
(std::string_view name);
bool
is_forbidden_top_module
(std::string_view name);
}
//
namespace mcpp::modgraph
namespace
mcpp
::modgraph {
bool
is_public_package_name
(std::string_view name) {
return
name.
find
(
'
.
'
) != std::string_view::npos;
}
bool
is_forbidden_top_module
(std::string_view name) {
static
constexpr
std::string_view blacklist[] = {
"
core
"
,
"
util
"
,
"
common
"
,
"
std
"
,
"
detail
"
,
"
internal
"
,
"
base
"
};
//
top = before first '.'
auto
p = name.
find
(
'
.
'
);
auto
top = (p == std::string_view::npos) ? name : name.
substr
(
0
, p);
for
(
auto
b : blacklist)
if
(top == b)
return
true
;
return
false
;
}
ValidateReport
validate
(
const
Graph& g,
const
mcpp::manifest::Manifest& manifest)
{
return
validate
(g, manifest,
/*
projectRoot=
*/
{});
}
ValidateReport
validate
(
const
Graph& g,
const
mcpp::manifest::Manifest& manifest,
const
std::filesystem::path& projectRoot)
{
ValidateReport r;
//
1. Naming: public packages' exported modules must be prefixed by package name,
//
and the top-level segment must not be in the forbidden list (for public pkgs).
//
//
Each SourceUnit carries its OWN package name (set by the scanner) so this
//
works transparently for multi-package builds (path deps): each unit is
//
validated against its own manifest's package name, not the primary's.
//
0.0.10+: module naming is the library author's choice. The build tool
//
no longer enforces that module names must be prefixed by the package
//
name. Only the forbidden-top-level-name check is retained to avoid
//
collisions with well-known module names (std, core, etc.).
for
(
auto
& u : g.
units
) {
if
(!u.
provides
)
continue
;
const
auto
& m = u.
provides
->
logicalName
;
auto
base = m.
substr
(
0
, m.
find
(
'
:
'
));
//
strip partition suffix
if
(
is_forbidden_top_module
(base)) {
r.
errors
.
push_back
({u.
path
,
std::format
(
"
module '{}' uses a forbidden top-level name (core/util/common/...)
"
, m)});
}
}
//
2. modules.exports vs scanner result.
//
Only checks the primary manifest's package — dep packages have their
//
own [modules].exports validated by their own builds.
if
(!manifest.
modules
.
exports_
.
empty
()) {
std::set<std::string>
declared
(manifest.
modules
.
exports_
.
begin
(),
manifest.
modules
.
exports_
.
end
());
std::set<std::string> actual;
for
(
auto
& u : g.
units
) {
if
(u.
provides
&& u.
packageName
== manifest.
package
.
name
) {
auto
base = u.
provides
->
logicalName
.
substr
(
0
, u.
provides
->
logicalName
.
find
(
'
:
'
));
actual.
insert
(base);
}
}
//
Any actual module that isn't in declared is a violation.
for
(
auto
& m : actual) {
if
(!declared.
contains
(m)) {
r.
errors
.
push_back
({{},
std::format
(
"
module '{}' is exported by code but not listed in [modules].exports
"
, m)});
}
}
if
(manifest.
modules
.
strict
) {
for
(
auto
& m : declared) {
if
(!actual.
contains
(m)) {
r.
errors
.
push_back
({{},
std::format
(
"
module '{}' declared in [modules].exports but never exported (strict)
"
, m)});
}
}
}
}
//
2.5 Lib-root convention (M5.x+).
//
//
For projects that ship a `kind = "lib"` target, check that the
//
lib-root file exists. The lib root is either `[lib].path` (explicit
//
override) or `src/<package-tail>.cppm` (default convention).
//
//
0.0.10+: the module name exported by the lib root is NOT required
//
to match [package].namespace + name. The library author decides
//
the module name; the build tool auto-detects it via the scanner.
//
Only structural correctness is enforced (file exists, no partition).
//
//
Pure-binary projects (mcpp itself, scaffolded `mcpp new`) skip this
//
check — they have no lib-root concept.
if
(
mcpp::manifest::has_lib_target
(manifest)) {
//
PROBING when there is a tree to probe: the convention offers one
//
candidate per declared module extension, and checking only the
//
`.cppm` one warns that an `.ixx` project's lib root is missing when
//
it is right there.
auto
lib_root_rel = projectRoot.
empty
()
?
mcpp::manifest::resolve_lib_root_path
(manifest)
:
mcpp::manifest::resolve_lib_root_path
(manifest, projectRoot);
const
bool
was_explicit = !manifest.
lib
.
path
.
empty
();
//
On-disk existence check (skipped when projectRoot is empty —
//
unit tests can build Graphs in memory without writing files).
if
(!projectRoot.
empty
()) {
auto
lib_root_abs = lib_root_rel.
is_absolute
()
? lib_root_rel
: (projectRoot / lib_root_rel);
std::error_code ec;
const
bool
exists =
std::filesystem::exists
(lib_root_abs, ec);
if
(!exists) {
if
(was_explicit) {
r.
errors
.
push_back
({lib_root_rel,
std::format
(
"
[lib].path '{}' does not exist
"
, lib_root_rel.
string
())});
}
else
{
r.
warnings
.
push_back
({lib_root_rel,
std::format
(
"
lib target without conventional lib root '{}'
"
"
(create the file or set [lib].path)
"
,
lib_root_rel.
string
())});
}
}
}
//
If the lib-root file is in the graph, verify it exports a
//
primary module (not a partition). The actual module name is
//
the library author's choice — no name-matching enforced.
const
mcpp::modgraph::SourceUnit* lib_unit =
nullptr
;
for
(
auto
& u : g.
units
) {
auto
u_rel = u.
path
.
is_absolute
() && !projectRoot.
empty
()
?
std::filesystem::relative
(u.
path
, projectRoot)
: u.
path
;
if
(u_rel == lib_root_rel || u.
path
== lib_root_rel) {
lib_unit = &u;
break
;
}
}
if
(lib_unit) {
if
(!lib_unit->
provides
) {
r.
errors
.
push_back
({lib_unit->
path
,
std::format
(
"
lib root '{}' must declare `export module <name>;`
"
,
lib_root_rel.
string
())});
}
else
{
const
auto
& m = lib_unit->
provides
->
logicalName
;
if
(m.
find
(
'
:
'
) != std::string::npos) {
r.
errors
.
push_back
({lib_unit->
path
,
std::format
(
"
lib root '{}' exports a partition '{}' —
"
"
must be a primary module (no `:partition` suffix)
"
,
lib_root_rel.
string
(), m)});
}
}
}
}
//
3. Topology
auto
topo =
topo_sort
(g);
if
(!topo) {
std::string names;
for
(
auto
i : topo.
error
().
cycle
) {
if
(i < g.
units
.
size
()) {
names += g.
units
[i].
path
.
string
() +
"
"
;
}
}
r.
errors
.
push_back
({{},
std::format
(
"
circular module dependency among: {}
"
, names)});
}
else
{
r.
topoOrder
=
std::move
(*topo);
}
return
r;
}
}
//
namespace mcpp::modgraph
You can’t perform that action at this time.