Skip to content
This repository was archived by the owner on May 14, 2026. It is now read-only.

feat: hermetic build OS detection#1988

Merged
diegomarquezp merged 7 commits into
mainfrom
feat/hermetic-build/os-detection
Sep 13, 2023
Merged

feat: hermetic build OS detection#1988
diegomarquezp merged 7 commits into
mainfrom
feat/hermetic-build/os-detection

Conversation

@diegomarquezp

Copy link
Copy Markdown
Contributor

Adds OS detection to generate_library.sh

Manual input from workflow matrix is removed in favor of automatic detection

@product-auto-label product-auto-label Bot added the size: s Pull request size is small. label Sep 13, 2023
@diegomarquezp

Copy link
Copy Markdown
Contributor Author

Mismatch in diff due to googleapis recently pushing a commit not found in googleapis-gen (link)

@diegomarquezp diegomarquezp marked this pull request as ready for review September 13, 2023 17:39
@diegomarquezp diegomarquezp requested a review from a team September 13, 2023 17:39
Comment thread library_generation/utilities.sh Outdated
Comment thread library_generation/utilities.sh Outdated
detect_OS() {
if [[ "${OSTYPE}" == "linux-gnu"* ]] || [[ "${OSTYPE}" == "freebsd"* ]]; then
os_architecture="linux-x86_64"
elif [[ "${OSTYPE}" == "darwin"* ]]; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about osx-aarm_64?

I think you can use uname -sm to detect OS type and CPU architecture, but I'm not sure whether windows can run this command.

@diegomarquezp diegomarquezp Sep 13, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I defaulted to win32 regardless of architecture and changed it to uname -m to detect the architecture only, while keeping reliance on ${OSTYPE}

Comment thread library_generation/utilities.sh Outdated
Comment thread library_generation/utilities.sh Outdated
}

detect_os_architecture() {
case "${OSTYPE}" in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

where does OSTYPE come from?

Comment thread library_generation/utilities.sh Outdated
os_architecture="linux-$(uname -m)"
;;
"darwin"*)
os_architecture="osx-$(uname -m)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When I run uname -m on my machine, the output is arm64.
However, the right os architecture should be osx-aarch_64.
You can reference the os architecture here

I also implemented a os architecture detection function:

get_os_architecture() {
  local os_type
  local os_architecture
  os_type=$(uname -sm)
  case "${os_type}" in
    *"Linux x86_64"*)
      os_architecture="linux-x86_64"
      ;;
    *"Darwin x86_64"*)
      os_architecture="osx-x86_64"
      ;;
    *)
      os_architecture="osx-aarch_64"
      ;;
  esac
  echo "${os_architecture}"
}

@diegomarquezp diegomarquezp Sep 13, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ah, thanks for the function :) I couldn't confirm for the aarch64 case since I don't have such machine, but I switched the detection function to this one

uses function by Joe Wang
@sonarqubecloud

Copy link
Copy Markdown

[gapic-generator-java-root] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarqubecloud

Copy link
Copy Markdown

[java_showcase_integration_tests] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarqubecloud

Copy link
Copy Markdown

[java_showcase_unit_tests] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@diegomarquezp diegomarquezp merged commit 4fc844e into main Sep 13, 2023
@diegomarquezp diegomarquezp deleted the feat/hermetic-build/os-detection branch September 13, 2023 20:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants