feat(version): port rpm-style version comparison from ZETA
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
Warning
|
||||
Warning ## Warning for package tofu ##
|
||||
Warning
|
||||
Warning The following compiler flags have been specified in the package description
|
||||
Warning file. They are handled by DUB and direct use in packages is discouraged.
|
||||
Warning Alternatively, you can set the DFLAGS environment variable to pass custom flags
|
||||
Warning to the compiler, or use one of the suggestions below:
|
||||
Warning
|
||||
Warning warningsAsErrors: Use "buildRequirements" to control the warning level
|
||||
Warning
|
||||
Generating test runner configuration 'tofu-test-application' for 'application' (executable).
|
||||
Warning Excluding main source file src/main.d from test.
|
||||
Starting Performing "unittest" build using /usr/bin/dmd for x86_64.
|
||||
Up-to-date toml 1.0.0: target for configuration [library] is up to date.
|
||||
Building tofu ~main: building configuration [tofu-test-application]
|
||||
Linking tofu-test-application
|
||||
Finished To force a rebuild of up-to-date targets, run again with --force
|
||||
Running tofu-test-application
|
||||
Warning: malformed TOML config at /tmp/tofu-test-config-bad-178345.toml: Invalid table key declaration (2:0)
|
||||
Warning: invalid TOFU_DEFAULT_JOBS 'not-a-number', using default 1
|
||||
4 modules passed unittests
|
||||
Warning
|
||||
Warning ## Warning for package tofu ##
|
||||
Warning
|
||||
Warning The following compiler flags have been specified in the package description
|
||||
Warning file. They are handled by DUB and direct use in packages is discouraged.
|
||||
Warning Alternatively, you can set the DFLAGS environment variable to pass custom flags
|
||||
Warning to the compiler, or use one of the suggestions below:
|
||||
Warning
|
||||
Warning warningsAsErrors: Use "buildRequirements" to control the warning level
|
||||
Warning
|
||||
Starting Performing "debug" build using /usr/bin/dmd for x86_64.
|
||||
Up-to-date toml 1.0.0: target for configuration [library] is up to date.
|
||||
Up-to-date tofu ~main: target for configuration [application] is up to date.
|
||||
Finished To force a rebuild of up-to-date targets, run again with --force
|
||||
@@ -6,6 +6,46 @@ _Auto-scaffolded by /start-work. Append new entries below - never overwrite._
|
||||
|
||||
---
|
||||
|
||||
## Task 5 — tofu.vercmp (RPM-style version comparison)
|
||||
|
||||
### Module naming
|
||||
- `version` is a D reserved keyword (conditional compilation). Module is named
|
||||
`tofu.vercmp`, file `src/tofu/vercmp.d`. The `DepConstraint` struct in
|
||||
`types.d` uses field `ver` (not `version`) for the same reason.
|
||||
|
||||
### Algorithm (exact port from ZETA/lib/vercmp.lua)
|
||||
- `nextSegment`: skips any non-digit/non-letter chars (separators); then reads
|
||||
a contiguous run of same-type chars. Returns `(segment, nextIndex)`.
|
||||
- `cmpNumeric`: strips leading zeros from both segments (`"007"` → `"7"`,
|
||||
`"000"` → `"0"`). Longer stripped string wins; then lexicographic.
|
||||
- `compare`: strips all whitespace, then loops over alternating segments.
|
||||
If both segments are digit-typed → `cmpNumeric`, else lexical. When one
|
||||
version exhausts segments: the exhausted one is *older* (shorter = older).
|
||||
This matches RPM semantics: `compare("1.0.0", "1.0") > 0`.
|
||||
- `satisfies`: uses `final switch` on `DepOp` enum. Maps to `compare` result
|
||||
as expected (ge→c>=0, le→c<=0, eq→c==0, ne→c!=0, gt→c>0, lt→c<0).
|
||||
- `parseDep`: delegates to `DepConstraint.parse` (already ported in types.d by
|
||||
task 4). Both implementations are kept consistent.
|
||||
|
||||
### whitespace stripping
|
||||
- Could not use `filter`+`array` because Phobos auto-decodes `string` to
|
||||
`dchar` range elements, returning `dchar[]` not `string`. Implemented a
|
||||
manual `removeWhitespace` helper using raw code-unit indexing, with a
|
||||
`@trusted` cast since the freshly-allocated `char[]` has no aliasing.
|
||||
|
||||
### Test porting
|
||||
- All 10 ZETA test categories ported as separate `@safe unittest` blocks.
|
||||
- 4 modules pass unittests (types, vercmp, plus pre-existing ones).
|
||||
- `dub build` passes with warnings-as-errors enabled.
|
||||
|
||||
### Future considerations
|
||||
- When task 12 (constraint resolution) imports `tofu.vercmp`, the `compare`
|
||||
and `satisfies` functions are ready. The `parseDep` integration with
|
||||
`DepConstraint.parse` ensures consistency between ZETA and tofu's dep
|
||||
constraint semantics.
|
||||
|
||||
---
|
||||
|
||||
## Task 2: Config Loading (src/tofu/config.d)
|
||||
|
||||
### toml package API (v1.0.0, Kripth/toml)
|
||||
|
||||
Reference in New Issue
Block a user