From bdc8e9ae1786326ef4493f184af53cbedac1653c Mon Sep 17 00:00:00 2001 From: Phu Thai Date: Wed, 27 Oct 2021 17:16:22 -0400 Subject: [PATCH 1/4] Runs corresponding sed command for Linux and MacOS Signed-off-by: Phu Thai macos syntax fix Signed-off-by: Phu Thai --- hack/add_license_headers.sh | 70 ++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/hack/add_license_headers.sh b/hack/add_license_headers.sh index 389950f8..d3c4aa6f 100755 --- a/hack/add_license_headers.sh +++ b/hack/add_license_headers.sh @@ -4,15 +4,33 @@ # # SPDX-License-Identifier: Apache-2.0 +sed_for_linux() { + sed -i '1i\ + # Copyright 2021 The MLX Contributors\ + #\ + # SPDX-License-Identifier: Apache-2.0\ + ' "$1" +} + +sed_for_macos() { + sed -i '' '1i\ + # Copyright 2021 The MLX Contributors\ + #\ + # SPDX-License-Identifier: Apache-2.0\ + ' "$1" +} + hash_comment () { echo "$1" if ! grep -q "SPDX-License-Identifier" "$1" then - sed -i '' '1i\ - # Copyright 2021 The MLX Contributors\ - #\ - # SPDX-License-Identifier: Apache-2.0\ - ' "$1" + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + $(sed_for_linux $1) + elif [[ "$OSTYPE" == "darwin"* ]]; then + $(sed_for_macos $1) + else + echo "FAILED | OS not compatible | Check /hack/add_license_headers.sh " + fi fi } @@ -20,11 +38,13 @@ slash_comment () { echo "$1" if ! grep -q "SPDX-License-Identifier" "$1" then - sed -i '' '1i\ - // Copyright 2021 The MLX Contributors\ - //\ - // SPDX-License-Identifier: Apache-2.0\ - ' "$1" + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + $(sed_for_linux $1) + elif [[ "$OSTYPE" == "darwin"* ]]; then + $(sed_for_macos $1) + else + echo "FAILED | OS not compatible | Check /hack/add_license_headers.sh " + fi fi } @@ -32,13 +52,13 @@ css_comment () { echo "$1" if ! grep -q "SPDX-License-Identifier" "$1" then - sed -i '' '1i\ - /*\ - * Copyright 2021 The MLX Contributors\ - *\ - * SPDX-License-Identifier: Apache-2.0\ - */\ - ' "$1" + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + $(sed_for_linux $1) + elif [[ "$OSTYPE" == "darwin"* ]]; then + $(sed_for_macos $1) + else + echo "FAILED | OS not compatible | Check /hack/add_license_headers.sh " + fi fi } @@ -46,17 +66,17 @@ html_comment () { echo "$1" if ! grep -q "SPDX-License-Identifier" "$1" then - sed -i '' '1i\ - \ - ' "$1" + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + $(sed_for_linux $1) + elif [[ "$OSTYPE" == "darwin"* ]]; then + $(sed_for_macos $1) + else + echo "FAILED | OS not compatible | Check /hack/add_license_headers.sh " + fi fi } -export -f hash_comment slash_comment css_comment html_comment +export -f sed_for_linux sed_for_macos hash_comment slash_comment css_comment html_comment echo "Adding missing license headers" From b21748fec0807951118dd0186771b78e9f89370c Mon Sep 17 00:00:00 2001 From: Phu Thai Date: Wed, 27 Oct 2021 17:16:57 -0400 Subject: [PATCH 2/4] Update licensing for outdated files Signed-off-by: Phu Thai removed bundle license ignore *.bundle.js Signed-off-by: Phu Thai --- hack/add_license_headers.sh | 2 +- hack/regenerate_catalog_upload_json.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/hack/add_license_headers.sh b/hack/add_license_headers.sh index d3c4aa6f..0d244634 100755 --- a/hack/add_license_headers.sh +++ b/hack/add_license_headers.sh @@ -84,7 +84,7 @@ echo "Adding missing license headers" find . -type f -not -path '*/temp/*' -a -not -path '*/\.*' -a \( -name '*.py' -o -name '*.yaml' -o -name '*.yml' -o -name '*.sh' \) -exec bash -c 'hash_comment "$0"' {} \; # Javascript -find . -type f -not -path '*/node_modules/*' -a -not -path '*/temp/*' -a -not -path '*/\.*' -a \( -name '*.js' -o -name '*.ts' \) -exec bash -c 'slash_comment "$0"' {} \; +find . -type f -not -path '*/node_modules/*' -a -not -path '*/temp/*' -a -not -path '*/\.*' -a -not -path '*.bundles.js' -a \( -name '*.js' -o -name '*.ts' \) -exec bash -c 'slash_comment "$0"' {} \; # CSS find . -type f -not -path '*/temp/*' -a -not -path '*/\.*' -a \( -name '*.css' -o -name '*.tsx' \) -exec bash -c 'css_comment "$0"' {} \; diff --git a/hack/regenerate_catalog_upload_json.py b/hack/regenerate_catalog_upload_json.py index b9b39478..85a85728 100755 --- a/hack/regenerate_catalog_upload_json.py +++ b/hack/regenerate_catalog_upload_json.py @@ -1,3 +1,7 @@ + # Copyright 2021 The MLX Contributors + # + # SPDX-License-Identifier: Apache-2.0 + #!/usr/bin/env python3 # Copyright 2021 IBM Corporation From 95a85fe50dd525b8894d316bbc34f8e0d89371fe Mon Sep 17 00:00:00 2001 From: Phu Thai Date: Wed, 27 Oct 2021 19:05:26 -0400 Subject: [PATCH 3/4] alias sed commands based on operating system Signed-off-by: Phu Thai PR comments --- hack/add_license_headers.sh | 82 ++++++++++++-------------- hack/regenerate_catalog_upload_json.py | 18 +----- 2 files changed, 39 insertions(+), 61 deletions(-) diff --git a/hack/add_license_headers.sh b/hack/add_license_headers.sh index 0d244634..f70a9697 100755 --- a/hack/add_license_headers.sh +++ b/hack/add_license_headers.sh @@ -1,36 +1,30 @@ -#!/usr/bin/env bash +#!/usr/bin/env -S bash -i # Copyright 2021 The MLX Contributors # # SPDX-License-Identifier: Apache-2.0 -sed_for_linux() { - sed -i '1i\ - # Copyright 2021 The MLX Contributors\ - #\ - # SPDX-License-Identifier: Apache-2.0\ - ' "$1" -} - -sed_for_macos() { - sed -i '' '1i\ - # Copyright 2021 The MLX Contributors\ - #\ - # SPDX-License-Identifier: Apache-2.0\ - ' "$1" -} +if [[ "$OSTYPE" == "linux-gnu"* ]]; then # Linux + alias gsed="sed -i" +elif [[ "$OSTYPE" == "darwin"* ]]; then # macOS + alias gsed="sed -i ''" +elif [[ "$OSTYPE" == "cygwin" ]]; then # POSIX compatible emulation for Windows + alias gsed="sed -i" +else + echo "FAILED. OS not compatible with script '/hack/add_license_headers.sh'" + exit 1 +fi +export gsed hash_comment () { echo "$1" if ! grep -q "SPDX-License-Identifier" "$1" then - if [[ "$OSTYPE" == "linux-gnu"* ]]; then - $(sed_for_linux $1) - elif [[ "$OSTYPE" == "darwin"* ]]; then - $(sed_for_macos $1) - else - echo "FAILED | OS not compatible | Check /hack/add_license_headers.sh " - fi + gsed '1i\ + # Copyright 2021 The MLX Contributors\ + #\ + # SPDX-License-Identifier: Apache-2.0\ + ' "$1" fi } @@ -38,13 +32,11 @@ slash_comment () { echo "$1" if ! grep -q "SPDX-License-Identifier" "$1" then - if [[ "$OSTYPE" == "linux-gnu"* ]]; then - $(sed_for_linux $1) - elif [[ "$OSTYPE" == "darwin"* ]]; then - $(sed_for_macos $1) - else - echo "FAILED | OS not compatible | Check /hack/add_license_headers.sh " - fi + gsed '1i\ + // Copyright 2021 The MLX Contributors\ + //\ + // SPDX-License-Identifier: Apache-2.0\ + ' "$1" fi } @@ -52,13 +44,13 @@ css_comment () { echo "$1" if ! grep -q "SPDX-License-Identifier" "$1" then - if [[ "$OSTYPE" == "linux-gnu"* ]]; then - $(sed_for_linux $1) - elif [[ "$OSTYPE" == "darwin"* ]]; then - $(sed_for_macos $1) - else - echo "FAILED | OS not compatible | Check /hack/add_license_headers.sh " - fi + gsed '1i\ + /*\ + * Copyright 2021 The MLX Contributors\ + *\ + * SPDX-License-Identifier: Apache-2.0\ + */\ + ' "$1" fi } @@ -66,17 +58,17 @@ html_comment () { echo "$1" if ! grep -q "SPDX-License-Identifier" "$1" then - if [[ "$OSTYPE" == "linux-gnu"* ]]; then - $(sed_for_linux $1) - elif [[ "$OSTYPE" == "darwin"* ]]; then - $(sed_for_macos $1) - else - echo "FAILED | OS not compatible | Check /hack/add_license_headers.sh " - fi + gsed '' '1i\ + \ + ' "$1" fi } -export -f sed_for_linux sed_for_macos hash_comment slash_comment css_comment html_comment +export -f hash_comment slash_comment css_comment html_comment echo "Adding missing license headers" diff --git a/hack/regenerate_catalog_upload_json.py b/hack/regenerate_catalog_upload_json.py index 85a85728..43483461 100755 --- a/hack/regenerate_catalog_upload_json.py +++ b/hack/regenerate_catalog_upload_json.py @@ -1,22 +1,8 @@ - # Copyright 2021 The MLX Contributors - # - # SPDX-License-Identifier: Apache-2.0 - #!/usr/bin/env python3 -# Copyright 2021 IBM Corporation +# Copyright 2021 The MLX Contributors # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# SPDX-License-Identifier: Apache-2.0 from __future__ import print_function From b03d6d59f1b175061d1f8336eb380cddfd5a7317 Mon Sep 17 00:00:00 2001 From: Phu Thai Date: Mon, 1 Nov 2021 12:40:11 -0400 Subject: [PATCH 4/4] Allow aliasing accross different OS's Signed-off-by: Phu Thai --- hack/add_license_headers.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hack/add_license_headers.sh b/hack/add_license_headers.sh index f70a9697..35a49a28 100755 --- a/hack/add_license_headers.sh +++ b/hack/add_license_headers.sh @@ -1,9 +1,12 @@ -#!/usr/bin/env -S bash -i +#!/usr/bin/env bash # Copyright 2021 The MLX Contributors # # SPDX-License-Identifier: Apache-2.0 +# set interactive mode to enable defining a gsed alias +shopt -s expand_aliases + if [[ "$OSTYPE" == "linux-gnu"* ]]; then # Linux alias gsed="sed -i" elif [[ "$OSTYPE" == "darwin"* ]]; then # macOS @@ -58,7 +61,7 @@ html_comment () { echo "$1" if ! grep -q "SPDX-License-Identifier" "$1" then - gsed '' '1i\ + gsed '1i\