multi-lang-build 0.2.5__py3-none-any.whl → 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- multi_lang_build/__init__.py +4 -4
- multi_lang_build/cli.py +5 -2
- multi_lang_build/compiler/__init__.py +1 -1
- multi_lang_build/compiler/go_compiler.py +403 -0
- multi_lang_build/compiler/go_support/__init__.py +19 -0
- multi_lang_build/compiler/go_support/binary.py +119 -0
- multi_lang_build/compiler/go_support/builder.py +228 -0
- multi_lang_build/compiler/go_support/cleaner.py +40 -0
- multi_lang_build/compiler/go_support/env.py +41 -0
- multi_lang_build/compiler/go_support/mirror.py +111 -0
- multi_lang_build/compiler/go_support/module.py +80 -0
- multi_lang_build/compiler/go_support/tester.py +200 -0
- multi_lang_build/compiler/pnpm.py +61 -209
- multi_lang_build/compiler/pnpm_support/__init__.py +6 -0
- multi_lang_build/compiler/pnpm_support/executor.py +148 -0
- multi_lang_build/compiler/pnpm_support/project.py +53 -0
- multi_lang_build/compiler/python.py +65 -222
- multi_lang_build/compiler/python_support/__init__.py +13 -0
- multi_lang_build/compiler/python_support/cleaner.py +56 -0
- multi_lang_build/compiler/python_support/cli.py +46 -0
- multi_lang_build/compiler/python_support/detector.py +64 -0
- multi_lang_build/compiler/python_support/installer.py +162 -0
- multi_lang_build/compiler/python_support/venv.py +63 -0
- multi_lang_build/ide_register.py +97 -0
- multi_lang_build/mirror/config.py +19 -0
- multi_lang_build/register/support/__init__.py +13 -0
- multi_lang_build/register/support/claude.py +94 -0
- multi_lang_build/register/support/codebuddy.py +100 -0
- multi_lang_build/register/support/opencode.py +62 -0
- multi_lang_build/register/support/trae.py +72 -0
- {multi_lang_build-0.2.5.dist-info → multi_lang_build-0.3.0.dist-info}/METADATA +41 -5
- multi_lang_build-0.3.0.dist-info/RECORD +40 -0
- multi_lang_build/compiler/go.py +0 -468
- multi_lang_build/register.py +0 -412
- multi_lang_build-0.2.5.dist-info/RECORD +0 -18
- {multi_lang_build-0.2.5.dist-info → multi_lang_build-0.3.0.dist-info}/WHEEL +0 -0
- {multi_lang_build-0.2.5.dist-info → multi_lang_build-0.3.0.dist-info}/entry_points.txt +0 -0
- {multi_lang_build-0.2.5.dist-info → multi_lang_build-0.3.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: multi-lang-build
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Multi-language automated build tool with domestic mirror acceleration support
|
|
5
5
|
Project-URL: Homepage, https://github.com/example/multi-lang-build
|
|
6
6
|
Project-URL: Repository, https://github.com/example/multi-lang-build
|
|
@@ -98,6 +98,9 @@ Description-Content-Type: text/markdown
|
|
|
98
98
|
```bash
|
|
99
99
|
pip install multi-lang-build
|
|
100
100
|
|
|
101
|
+
# 升级到最新版本
|
|
102
|
+
pip install --upgrade multi-lang-build
|
|
103
|
+
|
|
101
104
|
# 配置国内镜像(可选)
|
|
102
105
|
multi-lang-build mirror set pip # pip 使用清华镜像
|
|
103
106
|
multi-lang-build mirror set go # Go 使用 goproxy.cn
|
|
@@ -250,16 +253,19 @@ pip install multi-lang-build[dev]
|
|
|
250
253
|
|
|
251
254
|
```bash
|
|
252
255
|
# Go 项目构建(默认实时输出日志)
|
|
253
|
-
|
|
256
|
+
multi-lang-build go ./myproject --output ./bin/app --mirror
|
|
257
|
+
|
|
258
|
+
# 指定入口文件编译(cmd 结构)
|
|
259
|
+
multi-lang-build go ./myproject --output ./bin/server --target ./cmd/server
|
|
254
260
|
|
|
255
261
|
# 禁用实时输出
|
|
256
|
-
|
|
262
|
+
multi-lang-build go ./myproject --output ./bin/app --no-stream
|
|
257
263
|
|
|
258
264
|
# Python 项目构建
|
|
259
|
-
|
|
265
|
+
multi-lang-build python ./myproject --output ./dist --mirror
|
|
260
266
|
|
|
261
267
|
# PNPM 项目构建
|
|
262
|
-
|
|
268
|
+
multi-lang-build pnpm ./myproject --output ./dist --mirror
|
|
263
269
|
|
|
264
270
|
# 注册到 IDE(默认 Claude Code)
|
|
265
271
|
multi-lang-build register
|
|
@@ -397,6 +403,36 @@ for pkg in ["ui", "utils", "app"]:
|
|
|
397
403
|
|
|
398
404
|
---
|
|
399
405
|
|
|
406
|
+
## 📋 更新日志
|
|
407
|
+
|
|
408
|
+
### v0.3.0 (2026-02-03)
|
|
409
|
+
|
|
410
|
+
**✨ 新功能**
|
|
411
|
+
- 添加 `--target` CLI 参数,支持指定入口文件编译
|
|
412
|
+
- 构建时自动打印完整构建命令,方便排查问题
|
|
413
|
+
- 下载依赖时显示当前镜像配置信息
|
|
414
|
+
- `go mod tidy` 命令日志输出
|
|
415
|
+
|
|
416
|
+
**🔧 优化**
|
|
417
|
+
- 镜像故障转移机制改进
|
|
418
|
+
- 日志输出更加清晰
|
|
419
|
+
|
|
420
|
+
### v0.2.9 (2026-01-XX)
|
|
421
|
+
|
|
422
|
+
**✨ 新功能**
|
|
423
|
+
- Go 镜像自动故障转移(goproxy.io → goproxy.cn → goproxy.vip.cn)
|
|
424
|
+
- Go 编译器模块化重构
|
|
425
|
+
- 添加进度日志
|
|
426
|
+
|
|
427
|
+
### v0.2.0 (2025-09-XX)
|
|
428
|
+
|
|
429
|
+
**✨ 首次发布**
|
|
430
|
+
- 支持 Go、Python、PNPM 多语言构建
|
|
431
|
+
- 镜像加速功能
|
|
432
|
+
- IDE 集成注册
|
|
433
|
+
|
|
434
|
+
---
|
|
435
|
+
|
|
400
436
|
<p align="center">
|
|
401
437
|
用 ❤️ 构建 | 让多语言开发更简单
|
|
402
438
|
</p>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
multi_lang_build/__init__.py,sha256=_3D4R7_1Y452wsSbtcqKetK3pUFVJvW3JWSH-CNZCFc,1794
|
|
2
|
+
multi_lang_build/cli.py,sha256=v1xn2qfpj47n7rZQMg-Xiz8Tnu9aUEz--u9x4chH5vs,13246
|
|
3
|
+
multi_lang_build/ide_register.py,sha256=lz345IOs9S6-neh7t_6txJhz7XLypEiNzwvSl3ouVo8,3028
|
|
4
|
+
multi_lang_build/py.typed,sha256=c8jtFarMovqA5DdwhEzKPH4WrX85xaoiWilIlvuc6KU,84
|
|
5
|
+
multi_lang_build/types.py,sha256=iCyz_6KmEBU4xwpCtfJnpzXoiSsmOcOKOhzHJVx8Z4Q,1043
|
|
6
|
+
multi_lang_build/compiler/__init__.py,sha256=7cfE3n7ATXZ8JabON_Qg0npxd7EY2jEU4tC6FxDupIs,493
|
|
7
|
+
multi_lang_build/compiler/base.py,sha256=crtDW9bthfV-FSpp96O2Hi0DrViNqcIt4TjAVK2lPXE,9391
|
|
8
|
+
multi_lang_build/compiler/go_compiler.py,sha256=3KrHEz8HtE0Gnck-8gtFMAIrUP5FOO15K7LqG0GyFCc,13830
|
|
9
|
+
multi_lang_build/compiler/pnpm.py,sha256=0dwcf5LoPdzqlpkjEBVy8YNZNjd6CnUTOxIdonckwjo,10463
|
|
10
|
+
multi_lang_build/compiler/python.py,sha256=P-4ydqoUerMFkupVISu7j_KGSJVsZfmxeAZzCy36WWo,11797
|
|
11
|
+
multi_lang_build/compiler/go_support/__init__.py,sha256=UGsWdG_RdbjgLGYtvbftjzLjPwHF9tmb-pmezKvEWMQ,675
|
|
12
|
+
multi_lang_build/compiler/go_support/binary.py,sha256=bG452wvisoWlQDroBDNNXrR1SIHEMO1e0IQHsa-mF9I,3824
|
|
13
|
+
multi_lang_build/compiler/go_support/builder.py,sha256=NtavFLgEtZ5zFvygvudzylJ5AMo2wuRxCMJCDxHTmQA,6531
|
|
14
|
+
multi_lang_build/compiler/go_support/cleaner.py,sha256=UW5YQhzJtgypBpG0BQusmguxl7C8T3TLxlt58Krgvmg,1046
|
|
15
|
+
multi_lang_build/compiler/go_support/env.py,sha256=GPXFkePQb2QHaiiJuLXXVnSE9VtHjjPiZx82oYuVx3k,1270
|
|
16
|
+
multi_lang_build/compiler/go_support/mirror.py,sha256=BWT8mhLEshSVCFZa2D0amIvR366ZSXJCvP8djAqP11Q,3786
|
|
17
|
+
multi_lang_build/compiler/go_support/module.py,sha256=T-Jf_UebLR0MQ13yRZo7dugd_8bhk3QUBUPAWq39B4w,2352
|
|
18
|
+
multi_lang_build/compiler/go_support/tester.py,sha256=QHZzBe2zEN57MOO7G62wfuUhzLPeA8D0Fbquub8hQpk,5488
|
|
19
|
+
multi_lang_build/compiler/pnpm_support/__init__.py,sha256=_bPoy8XWGykiijpC8xwGMfJK3H4iBzIOYlcZUStwb9A,225
|
|
20
|
+
multi_lang_build/compiler/pnpm_support/executor.py,sha256=w52GN4fCGqbt90yEPq_LyaaWcGhoRbhudI_RJ38OkZY,4352
|
|
21
|
+
multi_lang_build/compiler/pnpm_support/project.py,sha256=JPHAxK0z1FOtNsAgJUUlp70wPGP4bq5pSB5o0FK44Co,1531
|
|
22
|
+
multi_lang_build/compiler/python_support/__init__.py,sha256=YjLyDtSvFy9VnhD9f0Mr9saMk98FnsKOe5O1L5pOAVc,459
|
|
23
|
+
multi_lang_build/compiler/python_support/cleaner.py,sha256=AT1KdRRX5vTGdtVLAgml2SuAUNEz0MzeuEgaHzBrAJo,1526
|
|
24
|
+
multi_lang_build/compiler/python_support/cli.py,sha256=q3guZAST1Rs2gy79BOb9GAWvShy7LBcdl1R1p8nfNXY,1642
|
|
25
|
+
multi_lang_build/compiler/python_support/detector.py,sha256=eMHSLsU--a_LbyeXlgFuqwN_CHM8MeSbE8rNX8fe35E,1804
|
|
26
|
+
multi_lang_build/compiler/python_support/installer.py,sha256=1gDqQPZRhYB6DIVlCxdRuIwJ_i5WpO4B5j2cG-VWVHI,4575
|
|
27
|
+
multi_lang_build/compiler/python_support/venv.py,sha256=It6tppc7BFToJBzFxR9hPfpYeteVpNIw-mHjF3pwdr4,1957
|
|
28
|
+
multi_lang_build/mirror/__init__.py,sha256=RrZOQ83bxImAR275zeAUKyyCgwqdGt5xH8tF_-UShJo,489
|
|
29
|
+
multi_lang_build/mirror/cli.py,sha256=qv6RI6izxUIsfMCIDOtTK3avcNSJpAaUF3NPiK1W49A,9820
|
|
30
|
+
multi_lang_build/mirror/config.py,sha256=ZQo9upkE29vw0QFuBT6sYw85DhOhHQg59RSYu-OcdQg,9067
|
|
31
|
+
multi_lang_build/register/support/__init__.py,sha256=Hg5oKJn5KhJ-qikzpDtFf0CO9WVnMvJVhExf20-PC10,443
|
|
32
|
+
multi_lang_build/register/support/claude.py,sha256=YgXdU0--1wr6QIDL6rojY_zLKnlb-nu6fDqvpKywzd4,3370
|
|
33
|
+
multi_lang_build/register/support/codebuddy.py,sha256=6ZPj0bs6erkSvok5lHueLbqxjIOCqml98zJoVTuBKj4,3356
|
|
34
|
+
multi_lang_build/register/support/opencode.py,sha256=zGrTREyCNUX8RZgTbv9p2KV0ZcQjB68jZQqIClFbD1k,2394
|
|
35
|
+
multi_lang_build/register/support/trae.py,sha256=nkiQRCWp8in3cI3BLuWHMMLzQwiQQv3crxAU06sXOuk,2527
|
|
36
|
+
multi_lang_build-0.3.0.dist-info/METADATA,sha256=9TkZPohwKmu_KV2vxzKjXJqMY2vfm-P7nkXi1chwrzQ,10882
|
|
37
|
+
multi_lang_build-0.3.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
38
|
+
multi_lang_build-0.3.0.dist-info/entry_points.txt,sha256=0vd5maQH5aZoqnpbr2Yr_IWB_-ncWX1rO3jGBCW3pHY,319
|
|
39
|
+
multi_lang_build-0.3.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
40
|
+
multi_lang_build-0.3.0.dist-info/RECORD,,
|
multi_lang_build/compiler/go.py
DELETED
|
@@ -1,468 +0,0 @@
|
|
|
1
|
-
"""Go compiler with mirror acceleration support."""
|
|
2
|
-
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
from typing import Final, Literal
|
|
5
|
-
import shutil
|
|
6
|
-
import subprocess
|
|
7
|
-
import os
|
|
8
|
-
import tempfile
|
|
9
|
-
|
|
10
|
-
from multi_lang_build.compiler.base import CompilerBase, BuildResult, CompilerInfo
|
|
11
|
-
from multi_lang_build.mirror.config import (
|
|
12
|
-
get_mirror_config,
|
|
13
|
-
apply_mirror_environment,
|
|
14
|
-
GO_PROXY_GOPROXY_CN,
|
|
15
|
-
GO_PROXY_GOPROXY_IO,
|
|
16
|
-
GO_PROXY_GOVIP_CN,
|
|
17
|
-
DEFAULT_GO_MIRROR,
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class GoCompiler(CompilerBase):
|
|
22
|
-
"""Compiler for Go projects with module support."""
|
|
23
|
-
|
|
24
|
-
NAME: Final[str] = "go"
|
|
25
|
-
DEFAULT_MIRROR: Final[str] = DEFAULT_GO_MIRROR
|
|
26
|
-
|
|
27
|
-
def __init__(
|
|
28
|
-
self,
|
|
29
|
-
go_path: str | None = None,
|
|
30
|
-
mirror: str | None = None,
|
|
31
|
-
) -> None:
|
|
32
|
-
"""Initialize the Go compiler.
|
|
33
|
-
|
|
34
|
-
Args:
|
|
35
|
-
go_path: Optional path to go executable. If None, uses system PATH.
|
|
36
|
-
mirror: Mirror configuration name (e.g., "go", "go_qiniu", "go_vip").
|
|
37
|
-
Defaults to DEFAULT_GO_MIRROR (goproxy.cn).
|
|
38
|
-
"""
|
|
39
|
-
self._go_path = go_path
|
|
40
|
-
self._mirror = mirror
|
|
41
|
-
self._version_cache: str | None = None
|
|
42
|
-
|
|
43
|
-
@property
|
|
44
|
-
def name(self) -> str:
|
|
45
|
-
"""Get the compiler name."""
|
|
46
|
-
return self.NAME
|
|
47
|
-
|
|
48
|
-
@property
|
|
49
|
-
def version(self) -> str:
|
|
50
|
-
"""Get the Go version."""
|
|
51
|
-
if self._version_cache:
|
|
52
|
-
return self._version_cache
|
|
53
|
-
|
|
54
|
-
go_executable = self._get_executable_path()
|
|
55
|
-
|
|
56
|
-
try:
|
|
57
|
-
result = subprocess.run(
|
|
58
|
-
[go_executable, "version"],
|
|
59
|
-
capture_output=True,
|
|
60
|
-
text=True,
|
|
61
|
-
timeout=10,
|
|
62
|
-
)
|
|
63
|
-
output = result.stdout.strip()
|
|
64
|
-
if output:
|
|
65
|
-
parts = output.split()
|
|
66
|
-
if len(parts) >= 3:
|
|
67
|
-
self._version_cache = parts[2]
|
|
68
|
-
else:
|
|
69
|
-
self._version_cache = output
|
|
70
|
-
else:
|
|
71
|
-
self._version_cache = "unknown"
|
|
72
|
-
except Exception:
|
|
73
|
-
self._version_cache = "unknown"
|
|
74
|
-
|
|
75
|
-
return self._version_cache
|
|
76
|
-
|
|
77
|
-
@property
|
|
78
|
-
def supported_mirrors(self) -> list[str]:
|
|
79
|
-
"""Get list of supported mirror configurations."""
|
|
80
|
-
return ["go", "go_qiniu", "go_vip"]
|
|
81
|
-
|
|
82
|
-
@property
|
|
83
|
-
def current_mirror(self) -> str:
|
|
84
|
-
"""Get the current mirror configuration name."""
|
|
85
|
-
return self._mirror or "go"
|
|
86
|
-
|
|
87
|
-
def get_info(self) -> CompilerInfo:
|
|
88
|
-
"""Get compiler information."""
|
|
89
|
-
return {
|
|
90
|
-
"name": self.name,
|
|
91
|
-
"version": self.version,
|
|
92
|
-
"supported_mirrors": self.supported_mirrors,
|
|
93
|
-
"default_mirror": self.DEFAULT_MIRROR,
|
|
94
|
-
"executable": self._get_executable_path(),
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
def set_mirror(self, mirror: str) -> None:
|
|
98
|
-
"""Set the mirror configuration.
|
|
99
|
-
|
|
100
|
-
Args:
|
|
101
|
-
mirror: Mirror configuration name (e.g., "go", "go_qiniu", "go_vip")
|
|
102
|
-
"""
|
|
103
|
-
self._mirror = mirror
|
|
104
|
-
|
|
105
|
-
def build(
|
|
106
|
-
self,
|
|
107
|
-
source_dir: Path,
|
|
108
|
-
output_dir: Path,
|
|
109
|
-
*,
|
|
110
|
-
environment: dict[str, str] | None = None,
|
|
111
|
-
mirror_enabled: bool = True,
|
|
112
|
-
extra_args: list[str] | None = None,
|
|
113
|
-
stream_output: bool = True,
|
|
114
|
-
) -> BuildResult:
|
|
115
|
-
"""Execute the Go build process.
|
|
116
|
-
|
|
117
|
-
Args:
|
|
118
|
-
source_dir: Source code directory
|
|
119
|
-
output_dir: Build output directory (for binary)
|
|
120
|
-
environment: Additional environment variables
|
|
121
|
-
mirror_enabled: Whether to use Go proxy mirror
|
|
122
|
-
extra_args: Additional arguments to pass to go build
|
|
123
|
-
stream_output: Whether to stream output in real-time (default: True)
|
|
124
|
-
|
|
125
|
-
Returns:
|
|
126
|
-
BuildResult containing success status and output information.
|
|
127
|
-
"""
|
|
128
|
-
go_executable = self._get_executable_path()
|
|
129
|
-
|
|
130
|
-
# Validate directories
|
|
131
|
-
source_dir = self._validate_directory(source_dir, create_if_not_exists=False)
|
|
132
|
-
output_dir = self._validate_directory(output_dir, create_if_not_exists=True)
|
|
133
|
-
|
|
134
|
-
# Prepare environment
|
|
135
|
-
env = environment.copy() if environment else {}
|
|
136
|
-
|
|
137
|
-
if mirror_enabled:
|
|
138
|
-
mirror_key = self._mirror or "go"
|
|
139
|
-
env = apply_mirror_environment(mirror_key, env)
|
|
140
|
-
|
|
141
|
-
# Check for go.mod
|
|
142
|
-
go_mod = source_dir / "go.mod"
|
|
143
|
-
has_go_mod = go_mod.exists()
|
|
144
|
-
|
|
145
|
-
# Download dependencies if go.mod exists
|
|
146
|
-
if has_go_mod:
|
|
147
|
-
deps_result = self._run_build(
|
|
148
|
-
[go_executable, "mod", "download"],
|
|
149
|
-
source_dir,
|
|
150
|
-
output_dir,
|
|
151
|
-
environment=env,
|
|
152
|
-
stream_output=stream_output,
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
if not deps_result["success"]:
|
|
156
|
-
return deps_result
|
|
157
|
-
|
|
158
|
-
# Build the project
|
|
159
|
-
build_args = [go_executable, "build", "-o", str(output_dir)]
|
|
160
|
-
|
|
161
|
-
if extra_args:
|
|
162
|
-
build_args.extend(extra_args)
|
|
163
|
-
|
|
164
|
-
return self._run_build(
|
|
165
|
-
build_args,
|
|
166
|
-
source_dir,
|
|
167
|
-
output_dir,
|
|
168
|
-
environment=env,
|
|
169
|
-
stream_output=stream_output,
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
def build_binary(
|
|
173
|
-
self,
|
|
174
|
-
source_dir: Path,
|
|
175
|
-
output_path: Path,
|
|
176
|
-
*,
|
|
177
|
-
target: str | Path | None = None,
|
|
178
|
-
environment: dict[str, str] | None = None,
|
|
179
|
-
mirror_enabled: bool = True,
|
|
180
|
-
ldflags: str | None = None,
|
|
181
|
-
tags: list[str] | None = None,
|
|
182
|
-
stream_output: bool = True,
|
|
183
|
-
) -> BuildResult:
|
|
184
|
-
"""Build a specific Go binary.
|
|
185
|
-
|
|
186
|
-
Args:
|
|
187
|
-
source_dir: Source code directory (working directory for build)
|
|
188
|
-
output_path: Output path for the binary
|
|
189
|
-
target: Build target - can be a .go file (e.g., "server.go", "cmd/server/main.go")
|
|
190
|
-
or a directory (e.g., "./cmd/server"). If None, builds current directory.
|
|
191
|
-
environment: Additional environment variables
|
|
192
|
-
mirror_enabled: Whether to use Go proxy mirror
|
|
193
|
-
ldflags: Linker flags to pass to the compiler
|
|
194
|
-
tags: Build tags to pass to the compiler
|
|
195
|
-
stream_output: Whether to stream output in real-time (default: True)
|
|
196
|
-
|
|
197
|
-
Returns:
|
|
198
|
-
BuildResult containing success status and output information.
|
|
199
|
-
"""
|
|
200
|
-
go_executable = self._get_executable_path()
|
|
201
|
-
|
|
202
|
-
source_dir = self._validate_directory(source_dir, create_if_not_exists=False)
|
|
203
|
-
|
|
204
|
-
# Ensure output directory exists
|
|
205
|
-
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
206
|
-
|
|
207
|
-
env = environment.copy() if environment else {}
|
|
208
|
-
|
|
209
|
-
if mirror_enabled:
|
|
210
|
-
mirror_key = self._mirror or "go"
|
|
211
|
-
env = apply_mirror_environment(mirror_key, env)
|
|
212
|
-
|
|
213
|
-
build_args = [go_executable, "build", "-o", str(output_path)]
|
|
214
|
-
|
|
215
|
-
if ldflags:
|
|
216
|
-
build_args.extend(["-ldflags", ldflags])
|
|
217
|
-
|
|
218
|
-
if tags:
|
|
219
|
-
build_args.extend(["-tags", ",".join(tags)])
|
|
220
|
-
|
|
221
|
-
# Add target if specified (target is relative to source_dir)
|
|
222
|
-
if target:
|
|
223
|
-
build_args.append(str(target))
|
|
224
|
-
|
|
225
|
-
return self._run_build(
|
|
226
|
-
build_args,
|
|
227
|
-
source_dir,
|
|
228
|
-
output_path.parent,
|
|
229
|
-
environment=env,
|
|
230
|
-
stream_output=stream_output,
|
|
231
|
-
)
|
|
232
|
-
|
|
233
|
-
def build_all(
|
|
234
|
-
self,
|
|
235
|
-
source_dir: Path,
|
|
236
|
-
output_dir: Path,
|
|
237
|
-
*,
|
|
238
|
-
environment: dict[str, str] | None = None,
|
|
239
|
-
mirror_enabled: bool = True,
|
|
240
|
-
platform: str | None = None,
|
|
241
|
-
stream_output: bool = True,
|
|
242
|
-
) -> BuildResult:
|
|
243
|
-
"""Build all binaries defined in a Makefile or build script.
|
|
244
|
-
|
|
245
|
-
Args:
|
|
246
|
-
source_dir: Source code directory
|
|
247
|
-
output_dir: Output directory for all binaries
|
|
248
|
-
environment: Additional environment variables
|
|
249
|
-
mirror_enabled: Whether to use Go proxy mirror
|
|
250
|
-
platform: Target platform (e.g., "linux/amd64", "windows/amd64")
|
|
251
|
-
stream_output: Whether to stream output in real-time (default: True)
|
|
252
|
-
|
|
253
|
-
Returns:
|
|
254
|
-
BuildResult containing success status and output information.
|
|
255
|
-
"""
|
|
256
|
-
go_executable = self._get_executable_path()
|
|
257
|
-
|
|
258
|
-
source_dir = self._validate_directory(source_dir, create_if_not_exists=False)
|
|
259
|
-
output_dir = self._validate_directory(output_dir, create_if_not_exists=True)
|
|
260
|
-
|
|
261
|
-
env = environment.copy() if environment else {}
|
|
262
|
-
|
|
263
|
-
if mirror_enabled:
|
|
264
|
-
mirror_key = self._mirror or "go"
|
|
265
|
-
env = apply_mirror_environment(mirror_key, env)
|
|
266
|
-
|
|
267
|
-
build_args = [go_executable, "build", "-o", str(output_dir), "./..."]
|
|
268
|
-
|
|
269
|
-
if platform:
|
|
270
|
-
env["GOOS"], env["GOARCH"] = platform.split("/")
|
|
271
|
-
|
|
272
|
-
return self._run_build(
|
|
273
|
-
build_args,
|
|
274
|
-
source_dir,
|
|
275
|
-
output_dir,
|
|
276
|
-
environment=env,
|
|
277
|
-
stream_output=stream_output,
|
|
278
|
-
)
|
|
279
|
-
|
|
280
|
-
def run_tests(
|
|
281
|
-
self,
|
|
282
|
-
source_dir: Path,
|
|
283
|
-
*,
|
|
284
|
-
environment: dict[str, str] | None = None,
|
|
285
|
-
mirror_enabled: bool = True,
|
|
286
|
-
verbose: bool = True,
|
|
287
|
-
race: bool = False,
|
|
288
|
-
stream_output: bool = True,
|
|
289
|
-
) -> BuildResult:
|
|
290
|
-
"""Run Go tests.
|
|
291
|
-
|
|
292
|
-
Args:
|
|
293
|
-
source_dir: Source code directory
|
|
294
|
-
environment: Additional environment variables
|
|
295
|
-
mirror_enabled: Whether to use Go proxy mirror
|
|
296
|
-
verbose: Enable verbose test output
|
|
297
|
-
race: Enable race detector
|
|
298
|
-
stream_output: Whether to stream output in real-time (default: True)
|
|
299
|
-
|
|
300
|
-
Returns:
|
|
301
|
-
BuildResult containing success status and output information.
|
|
302
|
-
"""
|
|
303
|
-
go_executable = self._get_executable_path()
|
|
304
|
-
|
|
305
|
-
source_dir = self._validate_directory(source_dir, create_if_not_exists=False)
|
|
306
|
-
|
|
307
|
-
env = environment.copy() if environment else {}
|
|
308
|
-
|
|
309
|
-
if mirror_enabled:
|
|
310
|
-
mirror_key = self._mirror or "go"
|
|
311
|
-
env = apply_mirror_environment(mirror_key, env)
|
|
312
|
-
|
|
313
|
-
test_args = [go_executable, "test"]
|
|
314
|
-
|
|
315
|
-
if verbose:
|
|
316
|
-
test_args.append("-v")
|
|
317
|
-
|
|
318
|
-
if race:
|
|
319
|
-
test_args.append("-race")
|
|
320
|
-
|
|
321
|
-
return self._run_build(
|
|
322
|
-
test_args,
|
|
323
|
-
source_dir,
|
|
324
|
-
source_dir,
|
|
325
|
-
environment=env,
|
|
326
|
-
stream_output=stream_output,
|
|
327
|
-
)
|
|
328
|
-
|
|
329
|
-
def tidy_modules(
|
|
330
|
-
self,
|
|
331
|
-
source_dir: Path,
|
|
332
|
-
*,
|
|
333
|
-
environment: dict[str, str] | None = None,
|
|
334
|
-
mirror_enabled: bool = True,
|
|
335
|
-
stream_output: bool = True,
|
|
336
|
-
) -> BuildResult:
|
|
337
|
-
"""Run go mod tidy to clean up dependencies.
|
|
338
|
-
|
|
339
|
-
Args:
|
|
340
|
-
source_dir: Source code directory
|
|
341
|
-
environment: Additional environment variables
|
|
342
|
-
mirror_enabled: Whether to use Go proxy mirror
|
|
343
|
-
stream_output: Whether to stream output in real-time (default: True)
|
|
344
|
-
|
|
345
|
-
Returns:
|
|
346
|
-
BuildResult containing success status and output information.
|
|
347
|
-
"""
|
|
348
|
-
go_executable = self._get_executable_path()
|
|
349
|
-
|
|
350
|
-
source_dir = self._validate_directory(source_dir, create_if_not_exists=False)
|
|
351
|
-
|
|
352
|
-
env = environment.copy() if environment else {}
|
|
353
|
-
|
|
354
|
-
if mirror_enabled:
|
|
355
|
-
mirror_key = self._mirror or "go"
|
|
356
|
-
env = apply_mirror_environment(mirror_key, env)
|
|
357
|
-
|
|
358
|
-
return self._run_build(
|
|
359
|
-
[go_executable, "mod", "tidy"],
|
|
360
|
-
source_dir,
|
|
361
|
-
source_dir,
|
|
362
|
-
environment=env,
|
|
363
|
-
stream_output=stream_output,
|
|
364
|
-
)
|
|
365
|
-
|
|
366
|
-
def clean(self, directory: Path) -> bool:
|
|
367
|
-
"""Clean Go build artifacts in the specified directory.
|
|
368
|
-
|
|
369
|
-
Args:
|
|
370
|
-
directory: Directory to clean
|
|
371
|
-
|
|
372
|
-
Returns:
|
|
373
|
-
True if successful, False otherwise.
|
|
374
|
-
"""
|
|
375
|
-
import shutil
|
|
376
|
-
|
|
377
|
-
try:
|
|
378
|
-
directory = self._validate_directory(directory, create_if_not_exists=False)
|
|
379
|
-
|
|
380
|
-
# Remove go.sum
|
|
381
|
-
go_sum = directory / "go.sum"
|
|
382
|
-
if go_sum.exists():
|
|
383
|
-
go_sum.unlink()
|
|
384
|
-
|
|
385
|
-
# Remove vendor directory
|
|
386
|
-
vendor = directory / "vendor"
|
|
387
|
-
if vendor.exists():
|
|
388
|
-
shutil.rmtree(vendor)
|
|
389
|
-
|
|
390
|
-
# Remove bin directory
|
|
391
|
-
bin_dir = directory / "bin"
|
|
392
|
-
if bin_dir.exists():
|
|
393
|
-
shutil.rmtree(bin_dir)
|
|
394
|
-
|
|
395
|
-
return True
|
|
396
|
-
|
|
397
|
-
except Exception:
|
|
398
|
-
return False
|
|
399
|
-
|
|
400
|
-
def _get_executable_path(self) -> str:
|
|
401
|
-
"""Get the go executable path."""
|
|
402
|
-
if self._go_path:
|
|
403
|
-
return self._go_path
|
|
404
|
-
|
|
405
|
-
go_path = shutil.which("go")
|
|
406
|
-
if go_path is None:
|
|
407
|
-
raise RuntimeError("go not found in PATH. Please install Go or provide go_path.")
|
|
408
|
-
|
|
409
|
-
return go_path
|
|
410
|
-
|
|
411
|
-
@staticmethod
|
|
412
|
-
def create(source_dir: Path, *, mirror_enabled: bool = True) -> "GoCompiler":
|
|
413
|
-
"""Factory method to create a GoCompiler instance.
|
|
414
|
-
|
|
415
|
-
Args:
|
|
416
|
-
source_dir: Source directory for the project
|
|
417
|
-
mirror_enabled: Whether to enable mirror acceleration by default
|
|
418
|
-
|
|
419
|
-
Returns:
|
|
420
|
-
Configured GoCompiler instance
|
|
421
|
-
"""
|
|
422
|
-
compiler = GoCompiler()
|
|
423
|
-
return compiler
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
def main() -> None:
|
|
427
|
-
"""Go compiler CLI entry point."""
|
|
428
|
-
import argparse
|
|
429
|
-
import sys
|
|
430
|
-
|
|
431
|
-
parser = argparse.ArgumentParser(description="Go Build Compiler")
|
|
432
|
-
parser.add_argument("source_dir", type=Path, help="Source directory (working directory)")
|
|
433
|
-
parser.add_argument("-o", "--output", type=Path, required=True, help="Output binary path")
|
|
434
|
-
parser.add_argument("-t", "--target", type=str, help="Build target: .go file (e.g., server.go, cmd/main.go) or directory (e.g., ./cmd/server)")
|
|
435
|
-
parser.add_argument("--mirror", action="store_true", default=True, help="Enable Go proxy mirror")
|
|
436
|
-
parser.add_argument("--no-mirror", dest="mirror", action="store_false", help="Disable Go proxy mirror")
|
|
437
|
-
parser.add_argument("--ldflags", type=str, help="Linker flags")
|
|
438
|
-
parser.add_argument("--tags", type=str, help="Build tags (comma-separated)")
|
|
439
|
-
parser.add_argument("--test", action="store_true", help="Run tests instead of building")
|
|
440
|
-
parser.add_argument("--tidy", action="store_true", help="Run go mod tidy")
|
|
441
|
-
parser.add_argument("--all", action="store_true", help="Build all packages")
|
|
442
|
-
|
|
443
|
-
args = parser.parse_args()
|
|
444
|
-
|
|
445
|
-
compiler = GoCompiler()
|
|
446
|
-
|
|
447
|
-
if args.test:
|
|
448
|
-
result = compiler.run_tests(args.source_dir, mirror_enabled=args.mirror)
|
|
449
|
-
elif args.tidy:
|
|
450
|
-
result = compiler.tidy_modules(args.source_dir, mirror_enabled=args.mirror)
|
|
451
|
-
elif args.all:
|
|
452
|
-
result = compiler.build_all(
|
|
453
|
-
args.source_dir,
|
|
454
|
-
args.output,
|
|
455
|
-
mirror_enabled=args.mirror,
|
|
456
|
-
)
|
|
457
|
-
else:
|
|
458
|
-
tags = args.tags.split(",") if args.tags else None
|
|
459
|
-
result = compiler.build_binary(
|
|
460
|
-
args.source_dir,
|
|
461
|
-
args.output,
|
|
462
|
-
target=args.target,
|
|
463
|
-
mirror_enabled=args.mirror,
|
|
464
|
-
ldflags=args.ldflags,
|
|
465
|
-
tags=tags,
|
|
466
|
-
)
|
|
467
|
-
|
|
468
|
-
sys.exit(0 if result["success"] else 1)
|