Skip to content

Commit a1e993b

Browse files
committed
Add C++ Plus package infomation.
新文件: CPPPPKG 修改: ChangeLog 新文件: FILELIST 修改: README.md 新文件: cpppdist.py
1 parent 54a2028 commit a1e993b

File tree

5 files changed

+245
-20
lines changed

5 files changed

+245
-20
lines changed

CPPPPKG

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name" : "cppp-platform",
3+
"version" : "1.3.0",
4+
"list_file_path": "FILELIST",
5+
"description": "Portable platform check library for C++ Plus.",
6+
"authors": [
7+
"The C++ Plus Project",
8+
"ChenPi11"
9+
],
10+
"webpage": "https://github.com/cppp-project/cppp-platform",
11+
"subpackages": {
12+
"build-aux": { "path": "build-aux", "ignore": true }
13+
},
14+
"license": [
15+
"Unlicense"
16+
]
17+
}

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2023-08-09 ChenPi11 <wushengwuxi-msctinoulk@outlook.com>
2+
3+
Add C++ Plus package infomation.
4+
15
2023-08-08 ChenPi11 <wushengwuxi-msctinoulk@outlook.com>
26

37
Add CMake buildsystem support.

FILELIST

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
README.md
2+
cpppdist.py
3+
doc/compilers.md
4+
doc/architectures.md
5+
doc/languagestandards.md
6+
doc/doc.md
7+
doc/platforms.md
8+
FILELIST
9+
include/cppp/cppp-platform.h.in
10+
src/platforms.h
11+
src/languagestandards.h
12+
src/architectures.h
13+
src/compilers.h
14+
CMakeLists.txt
15+
CPPPPKG
16+
lang/zh_CN.langmap
17+
lang/en_US.langmap
18+
ChangeLog
19+
COPYING

README.md

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
11
# Introduction
2-
libplatform is a portable platform check library for C++ Plus
2+
cppp-platform is a portable platform check library for C++ Plus.
33
## Build
4-
### Build with GNU Makefile
5-
#### Dependence
6-
+ GNU Make
7-
+ GNU/Linux commands: **cat, mkdir, install, rm**
8-
#### Make and Install
9-
```shell
10-
./configure
11-
make
12-
make install
13-
```
14-
The build results are in the 'build' directory.
15-
### Build with CMake
16-
#### Dependence
17-
+ CMake (version >= 3.0)
18-
#### Make
4+
5+
### Dependence
6+
+ CMake (version >= 3.12)
7+
### Make
198
```shell
209
mkdir build
2110
cd build
22-
cmake ..
11+
cmake .. -DCMAKE_INSTALL_PREFIX=[[PREFIX]]
12+
cmake --build .
13+
cmake --install .
2314
```
24-
The build results are in the 'build' directory.
2515

2616
## Usage
27-
After install, you can use libplatform in C/C++
17+
After install, you can use cppp-platform in C/C++
2818
```c
29-
#include <cppp/libplatform.h>
19+
#include <cppp/cppp-platform.h>
3020
#include <stdio.h>
3121
int main()
3222
{

cpppdist.py

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright (C) 2023 The C++ Plus Project.
4+
# This file is part of the cppp library.
5+
#
6+
# The cppp library is free software; you can redistribute it
7+
# and/or modify it under the terms of the GNU Lesser General Public
8+
# License as published by the Free Software Foundation; either version 3
9+
# of the License, or (at your option) any later version.
10+
#
11+
# The cppp library is distributed in the hope that it will be
12+
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
# Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public
17+
# License along with the cppp library; see the file COPYING.
18+
# If not, see <https://www.gnu.org/licenses/>.
19+
20+
# C++ Plus dist utils.
21+
22+
import os
23+
import sys
24+
import json
25+
import shutil
26+
import importlib.util
27+
28+
PACKAGE_INFO = "CPPPPKG"
29+
PROGNAME = "cpppdist.py"
30+
31+
def import_file(path):
32+
"""
33+
Import a Python file from it's path
34+
35+
Args:
36+
path (str): Python file's path
37+
38+
Raises:
39+
ModuleNotFoundError: When module invalid, load error or not found.
40+
41+
Returns:
42+
ModuleType: module
43+
"""
44+
spec = importlib.util.spec_from_file_location(os.path.basename(path).replace(".py", ""), path)
45+
if(spec == None):
46+
raise ModuleNotFoundError("Invalid module or module not found: " + path)
47+
module = importlib.util.module_from_spec(spec)
48+
spec.loader.exec_module(module)
49+
return module
50+
51+
class Package:
52+
"""
53+
A dist package type
54+
"""
55+
name = ""
56+
version = ""
57+
list_file_path = ""
58+
filelist = []
59+
subpackages = {}
60+
61+
def __init__(self, pkginfo_filepath) -> None:
62+
try:
63+
os.chdir(fwd)
64+
with open(pkginfo_filepath, "r", encoding="UTF-8") as info_file:
65+
data = json.load(info_file)
66+
self.name = data["name"]
67+
self.version = data["version"]
68+
self.list_file_path = data["list_file_path"]
69+
try:
70+
_subpackages = data["subpackages"]
71+
for pkgname in _subpackages:
72+
pkgpath = _subpackages[pkgname]["path"]
73+
try:
74+
pkgmodule = import_file(os.path.join(pkgpath, PROGNAME))
75+
self.subpackages[pkgpath] = pkgmodule.package
76+
except Exception as e:
77+
if(not _subpackages[pkgname]["ignore"]):
78+
raise
79+
else:
80+
print(f"DEBUG: Ignore a subpackage '{pkgname}': {e}", file=sys.stderr)
81+
except KeyError:
82+
pass
83+
self.filelist = self.get_file_list()
84+
finally:
85+
os.chdir(cwd)
86+
87+
def get_file_list(self) -> list:
88+
"""
89+
Get file list for dist.
90+
"""
91+
try:
92+
os.chdir(fwd)
93+
file_list = []
94+
with open(self.list_file_path, "rt", encoding="UTF-8") as list_file:
95+
data = list_file.read()
96+
file_list = data.strip().split("\n")
97+
return file_list
98+
finally:
99+
os.chdir(cwd)
100+
101+
def copy_files(self, dest):
102+
"""
103+
Copy files to dist dest
104+
"""
105+
try:
106+
os.chdir(fwd)
107+
if(os.path.exists(dest)):
108+
shutil.rmtree(dest)
109+
print(f"Copy package '{self.name}' to '{dest}' ... ", file=sys.stderr)
110+
progressbar = ProgressBar(len(self.filelist))
111+
for file in self.filelist:
112+
relpath = os.path.relpath(file, fwd)
113+
filedir = os.path.abspath(os.path.join(dest, relpath, ".."))
114+
if(not os.path.exists(filedir)):
115+
os.makedirs(filedir)
116+
shutil.copy(file, os.path.join(dest, relpath))
117+
progressbar.add(1)
118+
progressbar.end()
119+
print("", end="\n", file=sys.stderr)
120+
# Copy subpackages
121+
for (pkgpath, pkg) in self.subpackages.items():
122+
pkg.copy_files(os.path.join(dest, os.path.join(dest, pkgpath)))
123+
finally:
124+
os.chdir(cwd)
125+
126+
class ProgressBar:
127+
"""
128+
Progress bar type.
129+
"""
130+
def __init__(self, total):
131+
self.total = total
132+
self.cur = 0
133+
sys.stderr.write("\n")
134+
self.update()
135+
136+
def add(self, step):
137+
"""
138+
Add current value and update.
139+
"""
140+
self.cur += step
141+
self.update()
142+
143+
def set(self, cur):
144+
"""
145+
Set current value and update.
146+
"""
147+
self.cur = cur
148+
self.update()
149+
150+
def update(self):
151+
"""
152+
Update progress bar.
153+
"""
154+
try:
155+
progress = 0.0
156+
if(self.cur):
157+
progress = self.cur / self.total
158+
term_width = os.get_terminal_size(sys.stderr.fileno()).columns
159+
part_width = term_width - len("[]100.0%")
160+
if(part_width <= 0):
161+
# Terminal is too small, ignore.
162+
return
163+
sys.stderr.write("\r")
164+
# Part1 is '#'
165+
part1 = int(part_width * progress) * '#'
166+
# Part2 is ' '
167+
part2 = int(part_width - len(part1)) * ' '
168+
# Part3 is 'xxx.x%'
169+
part3 = str(int(progress * 1000) / 10) + "%"
170+
sys.stderr.write(f"[{part1}{part2}]{part3}")
171+
sys.stderr.flush()
172+
except:
173+
return
174+
175+
def end(self):
176+
"""
177+
End this progress bar
178+
"""
179+
self.set(self.total)
180+
sys.stderr.write("\n")
181+
sys.stderr.flush()
182+
183+
cwd = os.path.abspath(os.curdir)
184+
fwd = os.path.abspath(os.path.join(__file__, ".."))
185+
186+
package = None
187+
try:
188+
package = Package(PACKAGE_INFO)
189+
except Exception as exc:
190+
print("Getting packge infomation error:", exc, file=sys.stderr)
191+
raise exc
192+
193+
if __name__ == "__main__":
194+
distdir = f"{package.name}-v{package.version}"
195+
package.copy_files(os.path.abspath(distdir))

0 commit comments

Comments
 (0)