Skip to content

Commit a711595

Browse files
authored
Update gen_ag_template (#144)
1 parent 7231b47 commit a711595

31 files changed

+93
-122
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ DerivedData/
88
.netrc
99
coverage.txt
1010
TODO.md
11-
template.swiftinterface
11+
.ag_template/

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ if swiftToolchainSupported {
107107
// MARK: - [env] OPENGRAPH_TARGET_RELEASE
108108

109109
let releaseVersion = Context.environment["OPENGRAPH_TARGET_RELEASE"].flatMap { Int($0) } ?? 2024
110-
sharedCSettings.append(.define("OPENGRAPH_RELEASE", to: "\(releaseVersion)"))
110+
//sharedCSettings.append(.define("OPENGRAPH_RELEASE", to: "\(releaseVersion)"))
111111
sharedSwiftSettings.append(.define("OPENGRAPH_RELEASE_\(releaseVersion)"))
112112
if releaseVersion >= 2021 {
113113
for year in 2021 ... releaseVersion {

Scripts/gen_ag_interface_template.sh

Lines changed: 0 additions & 23 deletions
This file was deleted.

Scripts/gen_ag_template.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/zsh
2+
3+
# A `realpath` alternative using the default C implementation.
4+
filepath() {
5+
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
6+
}
7+
8+
gen_interface() {
9+
swift build -c release -Xswiftc -emit-module-interface -Xswiftc -enable-library-evolution -Xswiftc -no-verify-emitted-module-interface -Xswiftc -package-name -Xswiftc OpenGraph -Xswiftc -Osize
10+
11+
mkdir -p .ag_template
12+
cp .build/release/Modules/OpenGraph.swiftinterface .ag_template/template.swiftinterface
13+
14+
sed -i '' '1,4d' .ag_template/template.swiftinterface
15+
sed -i '' 's/@_exported public import OpenGraphCxx/@_exported public import AttributeGraph/g' .ag_template/template.swiftinterface
16+
sed -i '' 's/OpenGraphCxx\.//g' .ag_template/template.swiftinterface
17+
sed -i '' 's/OpenGraph/AttributeGraph/g' .ag_template/template.swiftinterface
18+
sed -i '' 's/OPENGRAPH/ATTRIBUTEGRAPH/g' .ag_template/template.swiftinterface
19+
sed -i '' 's/OG/AG/g' .ag_template/template.swiftinterface
20+
21+
echo "Generated template.swiftinterface successfully"
22+
}
23+
24+
gen_header() {
25+
mkdir -p .ag_template/Headers
26+
27+
cp -r Sources/OpenGraphCxx/include/OpenGraph/* .ag_template/Headers/
28+
29+
# Rename files from OGxx to AGxx and OpenGraphxx to AttributeGraphxx
30+
find .ag_template/Headers -name "OG*" -type f | while read file; do
31+
new_name=$(echo "$file" | sed 's/OG/AG/g')
32+
mv "$file" "$new_name"
33+
done
34+
35+
find .ag_template/Headers -name "OpenGraph*" -type f | while read file; do
36+
new_name=$(echo "$file" | sed 's/OpenGraph/AttributeGraph/g')
37+
mv "$file" "$new_name"
38+
done
39+
40+
# Update content in all header files
41+
find .ag_template/Headers -name "*.h" -type f | while read file; do
42+
sed -i '' 's/OpenGraphCxx/AttributeGraph/g' "$file"
43+
sed -i '' 's/OpenGraph/AttributeGraph/g' "$file"
44+
sed -i '' 's/OPENGRAPH/ATTRIBUTEGRAPH/g' "$file"
45+
sed -i '' 's/OG/AG/g' "$file"
46+
done
47+
48+
echo "Generated template headers successfully"
49+
}
50+
51+
OPENGRAPH_ROOT="$(dirname $(dirname $(filepath $0)))"
52+
53+
cd $OPENGRAPH_ROOT
54+
55+
gen_interface
56+
gen_header

Sources/OpenGraph/Export.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
@_exported public import OpenGraphCxx
1+
//
2+
// Export.swift
3+
// OpenGraph
24

3-
// Align the constant define behavior
4-
#if OPENGRAPH_RELEASE_2024
5-
public let OPENGRAPH_RELEASE: Int32 = 2024
6-
#elseif OPENGRAPH_RELEASE_2021
7-
public let OPENGRAPH_RELEASE: Int32 = 2021
8-
#endif
5+
@_exported public import OpenGraphCxx
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
//
22
// OGAttributeType.cpp
3-
//
4-
//
5-
// Created by Kyle on 2024/2/17.
6-
//
3+
// OpenGraphCxx
74

85
#include <OpenGraph/OGAttributeType.h>

Sources/OpenGraphCxx/Attribute/OGAttribute.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
//
22
// OGAttribute.cpp
3-
//
4-
//
5-
// Created by Kyle on 2024/2/16.
6-
//
3+
// OpenGraphCxx
74

85
#include <OpenGraph/OGAttribute.h>
96
#include <OpenGraphCxx/Attribute/AttributeID.hpp>

Sources/OpenGraphCxx/Attribute/OGWeakAttribute.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
//
22
// OGWeakAttribute.cpp
3-
//
4-
//
5-
// Created by Kyle on 2024/2/27.
6-
//
3+
// OpenGraphCxx
74

85
#include <OpenGraph/OGWeakAttribute.h>
96

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
//
22
// ClosureFunction.cpp
3-
//
4-
//
5-
// Created by Kyle on 2024/3/6.
6-
//
3+
// OpenGraphCxx
74

85
#include <OpenGraphCxx/Data/ClosureFunction.hpp>

0 commit comments

Comments
 (0)