Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: hermetic build OS detection #1988

Merged
merged 7 commits into from Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/verify_library_generation.yaml
Expand Up @@ -28,8 +28,7 @@ jobs:
library_generation/test/generate_library_integration_test.sh \
-p google/bigtable/v2 \
-d google-cloud-bigtable-v2-java \
--googleapis_gen_url https://cloud-java-bot:${{ secrets.CLOUD_JAVA_BOT_GITHUB_TOKEN }}@github.com/googleapis/googleapis-gen.git \
--os_type ${{ matrix.os }}
--googleapis_gen_url https://cloud-java-bot:${{ secrets.CLOUD_JAVA_BOT_GITHUB_TOKEN }}@github.com/googleapis/googleapis-gen.git
unit_tests:
strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion library_generation/generate_library.sh
Expand Up @@ -78,7 +78,7 @@ if [ -z "${include_samples}" ]; then
fi

if [ -z "${os_architecture}" ]; then
os_architecture="linux-x86_64"
os_architecture=$(detect_OS)
fi

mkdir -p "${destination_path}"
Expand Down
Expand Up @@ -78,11 +78,6 @@ include_samples=$(get_config_from_BUILD \
"false"
)
echo "GAPIC options are transport=${transport}, rest_numeric_enums=${rest_numeric_enums}, include_samples=${include_samples}."
os_architecture="linux-x86_64"
if [[ "$os_type" == *"macos"* ]]; then
os_architecture="osx-x86_64"
fi
echo "OS Architecture is ${os_architecture}."
# generate GAPIC client library
echo "Generating library from ${proto_path}, to ${destination_path}..."
"${library_generation_dir}"/generate_library.sh \
Expand All @@ -93,8 +88,7 @@ echo "Generating library from ${proto_path}, to ${destination_path}..."
--grpc_version "${grpc_version}" \
--transport "${transport}" \
--rest_numeric_enums "${rest_numeric_enums}" \
--include_samples "${include_samples}" \
--os_architecture "${os_architecture}"
--include_samples "${include_samples}"

echo "Generate library finished."
echo "Checking out googleapis-gen repository..."
Expand Down
16 changes: 16 additions & 0 deletions library_generation/utilities.sh
Expand Up @@ -273,3 +273,19 @@ get_version_from_versions_txt() {
version=$(grep "$key:" "${versions}" | cut -d: -f3) # 3rd field is snapshot
echo "${version}"
}

detect_OS() {
JoeWang1127 marked this conversation as resolved.
Show resolved Hide resolved
if [[ "${OSTYPE}" == "linux-gnu"* ]] || [[ "${OSTYPE}" == "freebsd"* ]]; then
JoeWang1127 marked this conversation as resolved.
Show resolved Hide resolved
os_architecture="linux-x86_64"
elif [[ "${OSTYPE}" == "darwin"* ]]; then
Copy link
Collaborator

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.

Copy link
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}

os_architecture="osx-x86_64"
elif [[ "${OSTYPE}" == "cygwin" ]] || [[ "${OSTYPE}" == "msys" ]]; then
os_architecture="win32"
else
>&2 echo 'Could not detect OS. Please specify it with --os_architecture'
>&2 echo 'Also, see https://github.com/protocolbuffers/protobuf/releases for a list of available OS (e.g. linux-aarch_64)'
exit 1
fi
>&2 echo "Detected OS architecture: ${os_architecture}" >2
echo "${os_architecture}"
}