multi-lang-build 0.2.7__py3-none-any.whl → 0.2.10__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.
Files changed (38) hide show
  1. multi_lang_build/__init__.py +4 -4
  2. multi_lang_build/cli.py +3 -2
  3. multi_lang_build/compiler/__init__.py +1 -1
  4. multi_lang_build/compiler/go_compiler.py +388 -0
  5. multi_lang_build/compiler/go_support/__init__.py +19 -0
  6. multi_lang_build/compiler/go_support/binary.py +117 -0
  7. multi_lang_build/compiler/go_support/builder.py +228 -0
  8. multi_lang_build/compiler/go_support/cleaner.py +40 -0
  9. multi_lang_build/compiler/go_support/env.py +41 -0
  10. multi_lang_build/compiler/go_support/mirror.py +111 -0
  11. multi_lang_build/compiler/go_support/module.py +77 -0
  12. multi_lang_build/compiler/go_support/tester.py +199 -0
  13. multi_lang_build/compiler/pnpm.py +61 -209
  14. multi_lang_build/compiler/pnpm_support/__init__.py +6 -0
  15. multi_lang_build/compiler/pnpm_support/executor.py +148 -0
  16. multi_lang_build/compiler/pnpm_support/project.py +53 -0
  17. multi_lang_build/compiler/python.py +65 -222
  18. multi_lang_build/compiler/python_support/__init__.py +13 -0
  19. multi_lang_build/compiler/python_support/cleaner.py +56 -0
  20. multi_lang_build/compiler/python_support/cli.py +46 -0
  21. multi_lang_build/compiler/python_support/detector.py +64 -0
  22. multi_lang_build/compiler/python_support/installer.py +162 -0
  23. multi_lang_build/compiler/python_support/venv.py +63 -0
  24. multi_lang_build/ide_register.py +97 -0
  25. multi_lang_build/mirror/config.py +19 -0
  26. multi_lang_build/register/support/__init__.py +13 -0
  27. multi_lang_build/register/support/claude.py +94 -0
  28. multi_lang_build/register/support/codebuddy.py +100 -0
  29. multi_lang_build/register/support/opencode.py +62 -0
  30. multi_lang_build/register/support/trae.py +72 -0
  31. {multi_lang_build-0.2.7.dist-info → multi_lang_build-0.2.10.dist-info}/METADATA +1 -1
  32. multi_lang_build-0.2.10.dist-info/RECORD +40 -0
  33. multi_lang_build/compiler/go.py +0 -532
  34. multi_lang_build/register.py +0 -412
  35. multi_lang_build-0.2.7.dist-info/RECORD +0 -18
  36. {multi_lang_build-0.2.7.dist-info → multi_lang_build-0.2.10.dist-info}/WHEEL +0 -0
  37. {multi_lang_build-0.2.7.dist-info → multi_lang_build-0.2.10.dist-info}/entry_points.txt +0 -0
  38. {multi_lang_build-0.2.7.dist-info → multi_lang_build-0.2.10.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.2.7
3
+ Version: 0.2.10
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
@@ -0,0 +1,40 @@
1
+ multi_lang_build/__init__.py,sha256=HFLjChxI1v6o36HTscv8X8p0WQMEuwXHVt9FzYZE4x8,1795
2
+ multi_lang_build/cli.py,sha256=SSj7f_auQ0qmjiY65aU0xEIW56w0xgA-8PgI9ICj04I,13100
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=HPNp6UQD_umjlV5ewqsYmRET3rfegqFaHOtOWy_cCIM,13234
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=XGt9jzRaCl2tykaHy8iqF1KrLHa3eW4hiolDozMMtaI,3698
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=5ubgiMJu0P8UeiutV3tIIifO30IBhbktDfJB4orWgvk,2204
18
+ multi_lang_build/compiler/go_support/tester.py,sha256=r6DVL4EtNUYQB_Jm84MGmZ1sDl9QsV6JqanZwHj-XyM,5428
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.2.10.dist-info/METADATA,sha256=1UZ3bhhQbW4AXA8fR-M6nF6ZU29gl18OIRuFEa_EucA,10074
37
+ multi_lang_build-0.2.10.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
38
+ multi_lang_build-0.2.10.dist-info/entry_points.txt,sha256=0vd5maQH5aZoqnpbr2Yr_IWB_-ncWX1rO3jGBCW3pHY,319
39
+ multi_lang_build-0.2.10.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
40
+ multi_lang_build-0.2.10.dist-info/RECORD,,
@@ -1,532 +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
- from loguru import logger
129
-
130
- go_executable = self._get_executable_path()
131
-
132
- # Validate directories
133
- source_dir = self._validate_directory(source_dir, create_if_not_exists=False)
134
- output_dir = self._validate_directory(output_dir, create_if_not_exists=True)
135
-
136
- # Print current working directory
137
- cwd = Path.cwd().resolve()
138
- logger.info(f"当前工作目录: {cwd}")
139
-
140
- # Prepare environment
141
- env = environment.copy() if environment else {}
142
-
143
- # Ensure GOMODCACHE is set
144
- if "GOMODCACHE" not in env and "GOPATH" not in env:
145
- default_cache = Path.home() / "go" / "pkg" / "mod"
146
- env["GOMODCACHE"] = str(default_cache)
147
- logger.info(f"Go模块缓存: {default_cache}")
148
-
149
- if mirror_enabled:
150
- mirror_key = self._mirror or "go"
151
- env = apply_mirror_environment(mirror_key, env)
152
-
153
- # Check for go.mod
154
- go_mod = source_dir / "go.mod"
155
- has_go_mod = go_mod.exists()
156
-
157
- # Download dependencies if go.mod exists
158
- if has_go_mod:
159
- deps_result = self._run_build(
160
- [go_executable, "mod", "download"],
161
- source_dir,
162
- output_dir,
163
- environment=env,
164
- stream_output=stream_output,
165
- )
166
-
167
- if not deps_result["success"]:
168
- return deps_result
169
-
170
- # Build the project
171
- build_args = [go_executable, "build", "-o", str(output_dir)]
172
-
173
- if extra_args:
174
- build_args.extend(extra_args)
175
-
176
- return self._run_build(
177
- build_args,
178
- source_dir,
179
- output_dir,
180
- environment=env,
181
- stream_output=stream_output,
182
- )
183
-
184
- def build_binary(
185
- self,
186
- source_dir: Path,
187
- output_path: Path,
188
- *,
189
- target: str | Path | None = None,
190
- environment: dict[str, str] | None = None,
191
- mirror_enabled: bool = True,
192
- ldflags: str | None = None,
193
- tags: list[str] | None = None,
194
- stream_output: bool = True,
195
- ) -> BuildResult:
196
- """Build a specific Go binary.
197
-
198
- Args:
199
- source_dir: Source code directory (working directory for build)
200
- output_path: Output path for the binary
201
- target: Build target - can be a .go file (e.g., "server.go", "cmd/server/main.go")
202
- or a directory (e.g., "./cmd/server"). If None, builds current directory.
203
- environment: Additional environment variables
204
- mirror_enabled: Whether to use Go proxy mirror
205
- ldflags: Linker flags to pass to the compiler
206
- tags: Build tags to pass to the compiler
207
- stream_output: Whether to stream output in real-time (default: True)
208
-
209
- Returns:
210
- BuildResult containing success status and output information.
211
- """
212
- from loguru import logger
213
-
214
- go_executable = self._get_executable_path()
215
-
216
- source_dir = self._validate_directory(source_dir, create_if_not_exists=False)
217
-
218
- # Ensure output directory exists
219
- output_path.parent.mkdir(parents=True, exist_ok=True)
220
-
221
- # Print current working directory
222
- cwd = Path.cwd().resolve()
223
- logger.info(f"当前工作目录: {cwd}")
224
-
225
- # Prepare environment
226
- env = environment.copy() if environment else {}
227
-
228
- # Ensure GOMODCACHE is set
229
- if "GOMODCACHE" not in env and "GOPATH" not in env:
230
- default_cache = Path.home() / "go" / "pkg" / "mod"
231
- env["GOMODCACHE"] = str(default_cache)
232
- logger.info(f"Go模块缓存: {default_cache}")
233
-
234
- if mirror_enabled:
235
- mirror_key = self._mirror or "go"
236
- env = apply_mirror_environment(mirror_key, env)
237
-
238
- build_args = [go_executable, "build", "-o", str(output_path)]
239
-
240
- if ldflags:
241
- build_args.extend(["-ldflags", ldflags])
242
-
243
- if tags:
244
- build_args.extend(["-tags", ",".join(tags)])
245
-
246
- # Add target if specified (target is relative to source_dir)
247
- if target:
248
- build_args.append(str(target))
249
-
250
- return self._run_build(
251
- build_args,
252
- source_dir,
253
- output_path.parent,
254
- environment=env,
255
- stream_output=stream_output,
256
- )
257
-
258
- def build_all(
259
- self,
260
- source_dir: Path,
261
- output_dir: Path,
262
- *,
263
- environment: dict[str, str] | None = None,
264
- mirror_enabled: bool = True,
265
- platform: str | None = None,
266
- stream_output: bool = True,
267
- ) -> BuildResult:
268
- """Build all binaries defined in a Makefile or build script.
269
-
270
- Args:
271
- source_dir: Source code directory
272
- output_dir: Output directory for all binaries
273
- environment: Additional environment variables
274
- mirror_enabled: Whether to use Go proxy mirror
275
- platform: Target platform (e.g., "linux/amd64", "windows/amd64")
276
- stream_output: Whether to stream output in real-time (default: True)
277
-
278
- Returns:
279
- BuildResult containing success status and output information.
280
- """
281
- from loguru import logger
282
-
283
- go_executable = self._get_executable_path()
284
-
285
- source_dir = self._validate_directory(source_dir, create_if_not_exists=False)
286
- output_dir = self._validate_directory(output_dir, create_if_not_exists=True)
287
-
288
- # Print current working directory
289
- cwd = Path.cwd().resolve()
290
- logger.info(f"当前工作目录: {cwd}")
291
-
292
- # Prepare environment
293
- env = environment.copy() if environment else {}
294
-
295
- # Ensure GOMODCACHE is set
296
- if "GOMODCACHE" not in env and "GOPATH" not in env:
297
- default_cache = Path.home() / "go" / "pkg" / "mod"
298
- env["GOMODCACHE"] = str(default_cache)
299
- logger.info(f"Go模块缓存: {default_cache}")
300
-
301
- if mirror_enabled:
302
- mirror_key = self._mirror or "go"
303
- env = apply_mirror_environment(mirror_key, env)
304
-
305
- build_args = [go_executable, "build", "-o", str(output_dir), "./..."]
306
-
307
- if platform:
308
- env["GOOS"], env["GOARCH"] = platform.split("/")
309
-
310
- return self._run_build(
311
- build_args,
312
- source_dir,
313
- output_dir,
314
- environment=env,
315
- stream_output=stream_output,
316
- )
317
-
318
- def run_tests(
319
- self,
320
- source_dir: Path,
321
- *,
322
- environment: dict[str, str] | None = None,
323
- mirror_enabled: bool = True,
324
- verbose: bool = True,
325
- race: bool = False,
326
- stream_output: bool = True,
327
- ) -> BuildResult:
328
- """Run Go tests.
329
-
330
- Args:
331
- source_dir: Source code directory
332
- environment: Additional environment variables
333
- mirror_enabled: Whether to use Go proxy mirror
334
- verbose: Enable verbose test output
335
- race: Enable race detector
336
- stream_output: Whether to stream output in real-time (default: True)
337
-
338
- Returns:
339
- BuildResult containing success status and output information.
340
- """
341
- from loguru import logger
342
-
343
- go_executable = self._get_executable_path()
344
-
345
- source_dir = self._validate_directory(source_dir, create_if_not_exists=False)
346
-
347
- # Print current working directory
348
- cwd = Path.cwd().resolve()
349
- logger.info(f"当前工作目录: {cwd}")
350
-
351
- # Prepare environment
352
- env = environment.copy() if environment else {}
353
-
354
- # Ensure GOMODCACHE is set
355
- if "GOMODCACHE" not in env and "GOPATH" not in env:
356
- default_cache = Path.home() / "go" / "pkg" / "mod"
357
- env["GOMODCACHE"] = str(default_cache)
358
- logger.info(f"Go模块缓存: {default_cache}")
359
-
360
- if mirror_enabled:
361
- mirror_key = self._mirror or "go"
362
- env = apply_mirror_environment(mirror_key, env)
363
-
364
- test_args = [go_executable, "test"]
365
-
366
- if verbose:
367
- test_args.append("-v")
368
-
369
- if race:
370
- test_args.append("-race")
371
-
372
- return self._run_build(
373
- test_args,
374
- source_dir,
375
- source_dir,
376
- environment=env,
377
- stream_output=stream_output,
378
- )
379
-
380
- def tidy_modules(
381
- self,
382
- source_dir: Path,
383
- *,
384
- environment: dict[str, str] | None = None,
385
- mirror_enabled: bool = True,
386
- stream_output: bool = True,
387
- ) -> BuildResult:
388
- """Run go mod tidy to clean up dependencies.
389
-
390
- Args:
391
- source_dir: Source code directory
392
- environment: Additional environment variables
393
- mirror_enabled: Whether to use Go proxy mirror
394
- stream_output: Whether to stream output in real-time (default: True)
395
-
396
- Returns:
397
- BuildResult containing success status and output information.
398
- """
399
- from loguru import logger
400
-
401
- go_executable = self._get_executable_path()
402
-
403
- source_dir = self._validate_directory(source_dir, create_if_not_exists=False)
404
-
405
- # Print current working directory
406
- cwd = Path.cwd().resolve()
407
- logger.info(f"当前工作目录: {cwd}")
408
-
409
- # Prepare environment
410
- env = environment.copy() if environment else {}
411
-
412
- # Ensure GOMODCACHE is set
413
- if "GOMODCACHE" not in env and "GOPATH" not in env:
414
- default_cache = Path.home() / "go" / "pkg" / "mod"
415
- env["GOMODCACHE"] = str(default_cache)
416
- logger.info(f"Go模块缓存: {default_cache}")
417
-
418
- if mirror_enabled:
419
- mirror_key = self._mirror or "go"
420
- env = apply_mirror_environment(mirror_key, env)
421
-
422
- return self._run_build(
423
- [go_executable, "mod", "tidy"],
424
- source_dir,
425
- source_dir,
426
- environment=env,
427
- stream_output=stream_output,
428
- )
429
-
430
- def clean(self, directory: Path) -> bool:
431
- """Clean Go build artifacts in the specified directory.
432
-
433
- Args:
434
- directory: Directory to clean
435
-
436
- Returns:
437
- True if successful, False otherwise.
438
- """
439
- import shutil
440
-
441
- try:
442
- directory = self._validate_directory(directory, create_if_not_exists=False)
443
-
444
- # Remove go.sum
445
- go_sum = directory / "go.sum"
446
- if go_sum.exists():
447
- go_sum.unlink()
448
-
449
- # Remove vendor directory
450
- vendor = directory / "vendor"
451
- if vendor.exists():
452
- shutil.rmtree(vendor)
453
-
454
- # Remove bin directory
455
- bin_dir = directory / "bin"
456
- if bin_dir.exists():
457
- shutil.rmtree(bin_dir)
458
-
459
- return True
460
-
461
- except Exception:
462
- return False
463
-
464
- def _get_executable_path(self) -> str:
465
- """Get the go executable path."""
466
- if self._go_path:
467
- return self._go_path
468
-
469
- go_path = shutil.which("go")
470
- if go_path is None:
471
- raise RuntimeError("go not found in PATH. Please install Go or provide go_path.")
472
-
473
- return go_path
474
-
475
- @staticmethod
476
- def create(source_dir: Path, *, mirror_enabled: bool = True) -> "GoCompiler":
477
- """Factory method to create a GoCompiler instance.
478
-
479
- Args:
480
- source_dir: Source directory for the project
481
- mirror_enabled: Whether to enable mirror acceleration by default
482
-
483
- Returns:
484
- Configured GoCompiler instance
485
- """
486
- compiler = GoCompiler()
487
- return compiler
488
-
489
-
490
- def main() -> None:
491
- """Go compiler CLI entry point."""
492
- import argparse
493
- import sys
494
-
495
- parser = argparse.ArgumentParser(description="Go Build Compiler")
496
- parser.add_argument("source_dir", type=Path, help="Source directory (working directory)")
497
- parser.add_argument("-o", "--output", type=Path, required=True, help="Output binary path")
498
- 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)")
499
- parser.add_argument("--mirror", action="store_true", default=True, help="Enable Go proxy mirror")
500
- parser.add_argument("--no-mirror", dest="mirror", action="store_false", help="Disable Go proxy mirror")
501
- parser.add_argument("--ldflags", type=str, help="Linker flags")
502
- parser.add_argument("--tags", type=str, help="Build tags (comma-separated)")
503
- parser.add_argument("--test", action="store_true", help="Run tests instead of building")
504
- parser.add_argument("--tidy", action="store_true", help="Run go mod tidy")
505
- parser.add_argument("--all", action="store_true", help="Build all packages")
506
-
507
- args = parser.parse_args()
508
-
509
- compiler = GoCompiler()
510
-
511
- if args.test:
512
- result = compiler.run_tests(args.source_dir, mirror_enabled=args.mirror)
513
- elif args.tidy:
514
- result = compiler.tidy_modules(args.source_dir, mirror_enabled=args.mirror)
515
- elif args.all:
516
- result = compiler.build_all(
517
- args.source_dir,
518
- args.output,
519
- mirror_enabled=args.mirror,
520
- )
521
- else:
522
- tags = args.tags.split(",") if args.tags else None
523
- result = compiler.build_binary(
524
- args.source_dir,
525
- args.output,
526
- target=args.target,
527
- mirror_enabled=args.mirror,
528
- ldflags=args.ldflags,
529
- tags=tags,
530
- )
531
-
532
- sys.exit(0 if result["success"] else 1)