Skip to content

Support multi-dash project names via ZOPEN_PROJECT_NAME and intelligent fallback#1122

Merged
IgorTodorovskiIBM merged 9 commits intomainfrom
update-go-template
Nov 18, 2025
Merged

Support multi-dash project names via ZOPEN_PROJECT_NAME and intelligent fallback#1122
IgorTodorovskiIBM merged 9 commits intomainfrom
update-go-template

Conversation

@IgorTodorovskiIBM
Copy link
Copy Markdown
Member

@IgorTodorovskiIBM IgorTodorovskiIBM commented Oct 24, 2025

Summary

Adds support for projects with dashes in their names (e.g., xcb-proto, gitlab-runner, libX11) by introducing the ZOPEN_PROJECT_NAME variable and implementing intelligent fallback parsing. This ensures that zopen build creates the same directory structure as zopen install for consistency.

NEW: Adds cross-platform support for running zopen build on macOS and Linux - useful for static scanning or analysis of patches on other platforms.

Problem

Previously, project names with dashes were incorrectly parsed during zopen build:

  • xcb-proto-1.17.0 → installed to /xcb/xcb-proto-1.17.0/ instead of /xcb-proto/xcb-proto-1.17.0/
  • gitlab-runner-17.6.0 → installed to /gitlab/gitlab-runner-17.6.0/ instead of /gitlab-runner/gitlab-runner-17.6.0/
  • Environment variables: XCB-PROTO_HOME (invalid shell variable name) ❌

This created a mismatch with zopen install, which correctly uses the full project name for the parent directory.

Solution

1. Introduced ZOPEN_PROJECT_NAME variable

  • zopen-generate now exports ZOPEN_PROJECT_NAME="<project-name>" in buildenv
  • Explicitly sets the project name without version
  • Recommended approach for new ports

2. Intelligent fallback parsing

When ZOPEN_PROJECT_NAME is not set (backward compatibility):

  1. Extract version from package name (rightmost segment starting with digit)
  2. Derive project name by removing -version suffix
  3. Lowercase for directory structure (matching zopen install convention)
  4. Convert dashes to underscores for environment variables

3. Updated locations

  • generateMetadataJSON() - metadata.json creation
  • createEnvAndSetup() - .env file and environment variables
  • set_install_caveats() - installation messages
  • ZOPEN_INSTALL_DIR setting (line 2298) - critical for correct install path

Cross-Platform Support (NEW)

Skip dependency installation with -g flag

  • Added early return in setDepsEnv() when using --get-source mode
  • Allows fetching and patching source without installing build dependencies

Platform-specific chtag handling

  • OS/390: Uses native chtag command
  • macOS/Linux: Uses alias chtag=true stub to avoid errors

Fixed color escape sequences

  • OS/390: Uses EBCDIC escape codes (\047)
  • macOS/Linux: Uses ASCII escape codes (\033)
  • Updated printColors() to use printf on non-OS/390 for proper interpretation

Platform-specific CPU detection

  • OS/390: numcpus.rexx
  • macOS: sysctl -n hw.ncpu
  • Linux: nproc or /proc/cpuinfo
  • Other platforms: defaults to 1

Portability improvements

  • Changed /bin/printf to printf for broader compatibility

Results

✅ Aligns zopen build directory structure with zopen install
✅ Install directories: /xcb-proto/xcb-proto-1.17.0/, /gitlab-runner/gitlab-runner-17.6.0/
✅ Environment variables: XCB_PROTO_HOME, GITLAB_RUNNER_HOME (valid shell names)
✅ Backward compatible with existing single-dash ports
NEW: Works on macOS and Linux for source download and patching with -g flag

Test Cases

Package Name Install Dir Env Variable
xcb-proto-1.17.0 /xcb-proto/xcb-proto-1.17.0/ XCB_PROTO_HOME
gitlab-runner-17.6.0 /gitlab-runner/gitlab-runner-17.6.0/ GITLAB_RUNNER_HOME
libX11-1.8.12 /libx11/libX11-1.8.12/ LIBX11_HOME
curl-8.5.0 /curl/curl-8.5.0/ CURL_HOME

Migration Path

New ports: zopen-generate automatically adds ZOPEN_PROJECT_NAME

Existing ports: Will use intelligent fallback automatically, or can add ZOPEN_PROJECT_NAME manually for clarity

Improved the Go template to match production ports (crushport, lazygitport,
gitlab-runnerport) with the following changes:

- Add ZOPEN_COMP=GO setting
- Add ZOPEN_CONFIGURE_MINIMAL=1 and ZOPEN_MAKE_MINIMAL=1 flags
- Set ZOPEN_CHECK="skip" by default for Go projects
- Add ZOPEN_CLEAN="zopen_clean" with cleanup function
- Improve zopen_init() to unset CC/CXX and create bin directory
- Enhance zopen_wharf() with realistic dependency management example
- Simplify build functions: zopen_build() and zopen_install()
- Add zopen_clean() to remove Go workspace artifacts

These changes align the template with established patterns used in working
Go ports and provide better guidance for new port developers.
- Add ZOPEN_PROJECT_NAME export to zopen-generate buildenv template
- Update zopen-build generateMetadataJSON() to use ZOPEN_PROJECT_NAME
- Update zopen-build createEnvAndSetup() to use ZOPEN_PROJECT_NAME
- Update zopen-build set_install_caveats() to use ZOPEN_PROJECT_NAME
- Maintain backward compatibility with fallback parsing for old ports
- Fixes install directory naming for multi-dash projects like gitlab-runner
- When ZOPEN_PROJECT_NAME not set, extract version first using smart sed pattern
- Derive name by removing version suffix (e.g., xcb-proto-1.17.0 -> xcb-proto)
- Apply to all three functions: generateMetadataJSON, createEnvAndSetup, set_install_caveats
- Fixes install directory for projects like xcb-proto without requiring ZOPEN_PROJECT_NAME
- Still recommend setting ZOPEN_PROJECT_NAME for clarity
Strategy:
1. Extract version first (rightmost segment starting with digit)
2. If version found, derive name by removing -version suffix
3. If no version found, fall back to old cut method

Benefits:
- Handles multi-dash names: xcb-proto-1.17.0 -> xcb-proto ✅
- Handles simple names: curl-8.5.0 -> curl ✅
- Handles complex names: gitlab-runner-17.6.0 -> gitlab-runner ✅
- ZOPEN_PROJECT_NAME still recommended but not required

Applied to:
- generateMetadataJSON()
- createEnvAndSetup()
- set_install_caveats()
…dash projects

Problem 1: ZOPEN_INSTALL_DIR was using cut -d'-' -f1
- xcb-proto-1.17.0 was installing to /xcb/ instead of /xcb-proto/
- Applied intelligent fallback to line 2298

Problem 2: Environment variable names had dashes (XCB-PROTO_HOME)
- Shell variables cannot contain dashes
- Now converts dashes to underscores: xcb-proto -> XCB_PROTO_HOME
- Applied sed 's/-/_/g' before uppercase conversion

Fixes:
- Install dir: /home/.../zopen/xcb-proto/xcb-proto-1.17.0/ ✅
- Env variable: XCB_PROTO_HOME=... ✅
Fix: libX11-1.8.12 was creating /libX11/ instead of /libx11/
- Added awk tolower() after extracting PROJECT_NAME in fallback
- Only applies to fallback (when ZOPEN_PROJECT_NAME not set)
- Preserves ZOPEN_NAME case for versioned directory

Result:
- Parent dir: /libx11/ (lowercase) ✅
- Child dir: /libX11-1.8.12/ (preserves original case) ✅
IgorTodorovskiIBM and others added 2 commits October 24, 2025 10:00
Before: Same version extraction and name derivation logic duplicated in 4 places
- generateMetadataJSON()
- createEnvAndSetup()
- set_install_caveats()
- ZOPEN_INSTALL_DIR setting

After: Single helper function getProjectName()
- Centralizes logic for extracting project name from package
- Uses ZOPEN_PROJECT_NAME if set
- Intelligent fallback with version extraction
- Falls back to old cut method if needed

Benefits:
- ~60 lines of duplicated code → ~20 lines in one function
- Easier to maintain and update
- Consistent behavior across all usages
- More readable code
- Skip dependency installation when using -g (--get-source) flag
- Use alias chtag=true for non-OS/390 platforms to avoid xargs errors
- Fix color escape sequences: use \033 (ASCII) for Mac/Linux vs \047 (EBCDIC) for OS/390
- Update printColors() to use printf on non-OS/390 for proper escape interpretation
- Add platform-specific CPU detection:
  - OS/390: numcpus.rexx
  - macOS: sysctl -n hw.ncpu
  - Linux: nproc or /proc/cpuinfo
  - Others: default to 1
- Change /bin/printf to printf for portability

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@IgorTodorovskiIBM IgorTodorovskiIBM marked this pull request as ready for review October 28, 2025 02:09
Copy link
Copy Markdown
Member

@sachintu47 sachintu47 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@IgorTodorovskiIBM IgorTodorovskiIBM merged commit 099958e into main Nov 18, 2025
1 of 2 checks passed
@IgorTodorovskiIBM IgorTodorovskiIBM deleted the update-go-template branch November 18, 2025 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants