Skip to content

Commit 22550a2

Browse files
author
xlings-ci
committed
probe: O6 code page and O7 workspace profiles
1 parent b01c94f commit 22550a2

3 files changed

Lines changed: 198 additions & 0 deletions

File tree

‎.github/probe/codepage.sh‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
# TEMPORARY PROBE (do not merge): why Glob.EscapedSpellingIsUtf8WhateverTheName
3+
# fails on some Windows machines. Prints; asserts nothing.
4+
set -u
5+
M="${MCPP_BUILT:?}"
6+
section() { echo; echo "### $1"; }
7+
REPO="$PWD"
8+
9+
section "the runner's code pages"
10+
powershell -NoProfile -Command "[System.Text.Encoding]::Default.CodePage; (Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\Nls\CodePage).ACP"
11+
12+
section "the unit test as CI runs it"
13+
"$M" test test_modgraph 2>&1 | grep -E "EscapedSpelling|PASSED|FAILED|passed|failed|error" | head -20
14+
echo "-- does the test binary embed the UTF-8 activeCodePage manifest? (mcpp.exe for comparison)"
15+
for exe in $(find target -name 'test_modgraph*.exe' | head -1) $(find target -name 'mcpp.exe' -path '*/bin/*' | head -1); do
16+
printf '%s: ' "$exe"; grep -a -c "activeCodePage" "$exe" || true
17+
done
18+
19+
section "the same narrow-to-path conversion under each code page"
20+
W="$RUNNER_TEMP/codepage"; rm -rf "$W"; mkdir -p "$W"
21+
for v in legacy utf8; do
22+
mkdir -p "$W/$v/src"; cd "$W/$v"
23+
{ printf '[package]\nname = "cp_%s"\nversion = "0.1.0"\n\n[toolchain]\nwindows = "msvc@system"\n\n[targets.cp_%s]\nkind = "bin"\nmain = "src/main.cpp"\n' "$v" "$v"
24+
[ "$v" = utf8 ] && printf 'windows_code_page = "utf-8"\n'; } > mcpp.toml
25+
cat > src/main.cpp <<'EOF'
26+
#include <windows.h>
27+
#include <cstdio>
28+
#include <exception>
29+
#include <filesystem>
30+
static void conv(unsigned cp) {
31+
const int n = MultiByteToWideChar(cp, MB_ERR_INVALID_CHARS, "caf\xE9", -1, nullptr, 0);
32+
std::printf(" MultiByteToWideChar(cp=%u, \"caf\\xE9\") -> %s\n", cp, n ? "ok" : "fails (no mapping)");
33+
}
34+
int main() {
35+
std::printf("GetACP() = %u\n", GetACP());
36+
try {
37+
std::filesystem::path p("caf\xE9");
38+
std::printf(" std::filesystem::path(\"caf\\xE9\") ok, %zu UTF-16 units\n", p.native().size());
39+
} catch (const std::exception& e) {
40+
std::printf(" std::filesystem::path(\"caf\\xE9\") throws: %s\n", e.what());
41+
}
42+
for (unsigned cp : {1252u, 936u, 65001u}) conv(cp);
43+
}
44+
EOF
45+
echo "-- $v"; "$M" run 2>&1 | grep -v "^ *\(Resolved\|Target\|Inferred\|Compiling\|Finished\|Running\)" | head -12
46+
done
47+
cd "$REPO"

‎.github/probe/ws_profile.sh‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env bash
2+
# TEMPORARY PROBE (do not merge): where [profile.*], [workspace.build] and a
3+
# rooted workspace's own [build] reach, per member and per selection.
4+
# Prints the markers each ninja edge carries; asserts nothing.
5+
set -u
6+
M="${MCPP_BUILT:?}"
7+
W="$RUNNER_TEMP/ws-profile"; rm -rf "$W"; mkdir -p "$W"
8+
section() { echo; echo "### $1"; }
9+
markers() { # every compile/link edge and the markers it (or the file-level default) carries
10+
local found=0
11+
for n in $(find target -name build.ninja | sort); do found=1
12+
echo " [graph $(basename "$(dirname "$n")")]"
13+
python3 - "$n" <<'PY'
14+
import re, sys
15+
glob, edges, cur = {}, {}, None
16+
for line in open(sys.argv[1], encoding="utf-8", errors="replace"):
17+
line = line.rstrip("\n")
18+
if line.startswith("build "):
19+
cur = line.split(" : ")[0][6:].strip()
20+
rule = line.split(" : ", 1)[1].split()[0] if " : " in line else "?"
21+
edges[cur] = {"_rule": rule}; continue
22+
if line.startswith(" ") and cur:
23+
k, _, v = line.strip().partition(" = "); edges[cur][k] = v; continue
24+
cur = None
25+
m = re.match(r"^(\w+)\s*=\s*(.*)$", line)
26+
if m: glob[m.group(1)] = m.group(2)
27+
pat = re.compile(r"MARK_[A-Z_]+|-O[0-3s]\b")
28+
for e, v in sorted(edges.items()):
29+
r = v["_rule"]
30+
if r in ("cxx_object", "cxx_module", "c_object"):
31+
text = " ".join([glob.get("cxxflags", ""), v.get("unit_cxxflags", ""), v.get("cxxflags", ""), v.get("package_cxxflags", "")] + [x for k, x in v.items() if "flags" in k])
32+
elif r in ("cxx_link", "cxx_shared", "c_link"):
33+
text = v.get("ldflags", glob.get("ldflags", "")) + " " + v.get("unit_ldflags", "")
34+
else:
35+
continue
36+
found = sorted(set(pat.findall(text)))
37+
print(f" {r:11s} {e}: {' '.join(found) or '-'}")
38+
PY
39+
done
40+
[ $found = 1 ] || echo "(no build.ninja)"
41+
}
42+
build() { echo "\$ mcpp $*"; rm -rf target; "$M" "$@" 2>&1 | grep -E "warning|error|note|Finished" | head -8; markers; }
43+
44+
prof() { # a [profile.release] table whose markers name its file
45+
cat <<EOF
46+
[profile.release]
47+
opt = 3
48+
cxxflags = ["-DMARK_PROFILE_$1"]
49+
ldflags = ["-Wl,-rpath,/MARK_PROFILE_$1"]
50+
EOF
51+
}
52+
member() { # member <dir> <name> <kind> [extra toml]
53+
mkdir -p "$1/src"
54+
{ printf '[package]\nname = "%s"\nversion = "0.1.0"\n\n' "$2"
55+
printf '[build]\ncxxflags = ["-DMARK_OWN_%s"]\nldflags = ["-Wl,-rpath,/MARK_OWN_%s"]\n\n' "${2^^}" "${2^^}"
56+
[ "$3" = shared ] && printf '[targets.%s]\nkind = "shared"\n' "$2"
57+
[ "$3" = bin ] && printf '[dependencies]\nlib = { path = "%s" }\n\n[targets.%s]\nkind = "bin"\nmain = "src/main.cpp"\n' "${DEP_PATH:-../lib}" "$2"
58+
printf '%s\n' "${4:-}"; } > "$1/mcpp.toml"
59+
if [ "$3" = shared ]; then printf 'export module ws_lib;\nexport int lv() { return 1; }\n' > "$1/src/lib.cppm"
60+
else printf 'import ws_lib;\nint main() { return lv() == 1 ? 0 : 1; }\n' > "$1/src/main.cpp"; fi
61+
}
62+
63+
section "W1 virtual root: [profile.release] + [workspace.build] at the root; members declare no profile"
64+
mkdir -p "$W/w1" && cd "$W/w1"
65+
{ printf '[workspace]\nmembers = ["app", "lib"]\n\n[workspace.build]\ncxxflags = ["-DMARK_WS_BUILD"]\nldflags = ["-Wl,-rpath,/MARK_WS_BUILD"]\n\n'; prof WSROOT; } > mcpp.toml
66+
member lib lib shared; member app app bin
67+
build build --release
68+
build build --release -p app
69+
70+
section "W2 virtual root with a profile, and member app declares its own [profile.release]"
71+
mkdir -p "$W/w2" && cd "$W/w2"
72+
{ printf '[workspace]\nmembers = ["app", "lib"]\n\n'; prof WSROOT; } > mcpp.toml
73+
member lib lib shared; member app app bin "$(prof APP)"
74+
build build --release
75+
build build --release -p app
76+
build build --release -p lib
77+
78+
section "W3 rooted workspace: the root file is [package] app + [workspace] + [profile.release] + its own [build]"
79+
mkdir -p "$W/w3" && cd "$W/w3"
80+
DEP_PATH=lib member . app bin "$(printf '[workspace]\nmembers = ["lib"]\n\n[workspace.build]\ncxxflags = ["-DMARK_WS_BUILD"]\n\n'; prof ROOTFILE)"
81+
member lib lib shared
82+
build build --release
83+
build build --release --workspace
84+
build build --release -p lib
85+
86+
section "W4 a plain project (no workspace), for comparison"
87+
mkdir -p "$W/w4" && cd "$W/w4"
88+
member lib lib shared
89+
mkdir -p app && member app app bin "$(prof APP)"
90+
cd app && build build --release

‎.github/workflows/probe-770-771.yml‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
path: facts.log
3333

3434
mcpp-probes:
35+
if: false # measured in run 37291652508; not repeated
3536
name: mcpp (built from this commit) on #771, #770, #769
3637
runs-on: windows-latest
3738
timeout-minutes: 60
@@ -76,3 +77,63 @@ jobs:
7677
with:
7778
name: mcpp-probes
7879
path: probes*.log
80+
81+
codepage:
82+
name: O6 - Glob.EscapedSpellingIsUtf8WhateverTheName and the code page (windows)
83+
runs-on: windows-latest
84+
timeout-minutes: 60
85+
env:
86+
MCPP_HOME: C:\Users\runneradmin\.mcpp
87+
steps:
88+
- uses: actions/checkout@v4
89+
- uses: ./.github/actions/bootstrap-mcpp
90+
- name: Build mcpp from source
91+
shell: bash
92+
run: |
93+
set -euo pipefail
94+
export MCPP_VENDORED_XLINGS="$XLINGS_BIN"
95+
"$XLINGS_BIN" config --mirror GLOBAL 2>/dev/null || true
96+
"$MCPP" self config --mirror GLOBAL 2>/dev/null || true
97+
"$MCPP" build
98+
built=$(find target -type f -name mcpp.exe -path '*/bin/*' | head -1)
99+
mkdir -p dist && cp "$built" dist/mcpp.exe
100+
echo "MCPP_BUILT=$PWD/dist/mcpp.exe" >> "$GITHUB_ENV"
101+
- name: probe
102+
shell: bash
103+
run: |
104+
export MCPP_VENDORED_XLINGS="$XLINGS_BIN"
105+
bash .github/probe/codepage.sh 2>&1 | tee codepage.log
106+
{ echo '## code page'; echo '```'; cat codepage.log; echo '```'; } >> "$GITHUB_STEP_SUMMARY"
107+
- uses: actions/upload-artifact@v4
108+
if: always()
109+
with:
110+
name: codepage
111+
path: codepage.log
112+
113+
ws-profile:
114+
name: O7 - profiles, [workspace.build] and the rooted root (linux)
115+
runs-on: ubuntu-latest
116+
timeout-minutes: 45
117+
steps:
118+
- uses: actions/checkout@v4
119+
- uses: ./.github/actions/bootstrap-mcpp
120+
- name: Build mcpp from source
121+
shell: bash
122+
run: |
123+
set -euo pipefail
124+
export MCPP_VENDORED_XLINGS="$XLINGS_BIN"
125+
"$MCPP" build
126+
built=$(find target -type f -name mcpp -path '*/bin/*' | grep -v '/dist/' | head -1)
127+
mkdir -p dist && cp "$built" dist/mcpp
128+
echo "MCPP_BUILT=$PWD/dist/mcpp" >> "$GITHUB_ENV"
129+
- name: probe
130+
shell: bash
131+
run: |
132+
export MCPP_VENDORED_XLINGS="$XLINGS_BIN"
133+
bash .github/probe/ws_profile.sh 2>&1 | tee ws-profile.log
134+
{ echo '## workspace profiles'; echo '```'; cat ws-profile.log; echo '```'; } >> "$GITHUB_STEP_SUMMARY"
135+
- uses: actions/upload-artifact@v4
136+
if: always()
137+
with:
138+
name: ws-profile
139+
path: ws-profile.log

0 commit comments

Comments
 (0)