-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: kcl scripts and bump kclvm to kcl (#564)
- Loading branch information
Showing
12 changed files
with
363 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Stop on error. | ||
set -e | ||
|
||
topdir=$PWD | ||
# Environment | ||
if [ -f "/etc/os-release" ]; then | ||
source /etc/os-release | ||
os=$ID | ||
else | ||
os=$(uname) | ||
fi | ||
|
||
prepare_dirs () { | ||
cpython_build_dir="$topdir/_build/build/$os/cpython" | ||
mkdir -p "$cpython_build_dir" | ||
cpython_install_dir="$topdir/_build/python_dist/$os/cpython" | ||
mkdir -p "$cpython_install_dir" | ||
} | ||
|
||
# Switch configuration options. | ||
config_option="Default" | ||
if [ "$os" != "" ]; then | ||
config_option=$os | ||
fi | ||
|
||
# python version | ||
py_ver_major="3" | ||
py_ver_minor="7" | ||
py_ver_micro="6" | ||
|
||
for config in "$config_option" | ||
do | ||
case $config in | ||
"Default" | "centos") | ||
config_envs="LANG=C.UTF-8" | ||
config_options="--enable-optimizations --with-ssl" | ||
echo "$REPLY: The configuration is $config: config_envs=$config_envs config_options=$config_options" | ||
break | ||
;; | ||
"Darwin") | ||
if [ "$sslpath" == "" ]; then | ||
sslpath=$(brew --prefix openssl@1.1) | ||
fi | ||
|
||
py_ver_major="3" | ||
py_ver_minor="9" | ||
py_ver_micro="12" | ||
|
||
config_envs="LANG=C.UTF-8" | ||
config_options="--enable-optimizations --with-openssl=$sslpath --with-ssl-default-suites=python" | ||
echo "$REPLY: The configuration is $config: config_envs=$config_envs config_options=$config_options" | ||
break | ||
;; | ||
"ubuntu" | "debian" | "Ubuntu" |"Debian" | "Static-Debian" | "Cood1-Debian" | "Cood1Shared-Debian") | ||
config_envs="CFLAGS=-Wno-coverage-mismatch" | ||
config_options="--enable-optimizations --with-ssl" | ||
echo "$REPLY: The configuration is $config: config_envs=$config_envs config_options=$config_options" | ||
break | ||
;; | ||
*) echo "Invalid config option $REPLY:$config" | ||
exit 1 | ||
break | ||
;; | ||
esac | ||
done | ||
|
||
# py_ver_str="$(python3 -c 'import os; print(os.path.basename(os.path.dirname(os.__file__)))')" | ||
py_ver_str="${py_ver_major}.${py_ver_minor}.${py_ver_micro}" | ||
|
||
# wget python | ||
mkdir -p $topdir/_build/3rdparty | ||
wget -P $topdir/_build/3rdparty "https://www.python.org/ftp/python/${py_ver_str}/Python-${py_ver_str}.tgz" | ||
tar zxvf $topdir/_build/3rdparty/Python-${py_ver_str}.tgz -C $topdir/_build/3rdparty | ||
|
||
prepare_dirs | ||
prefix_option="--prefix=$cpython_install_dir" | ||
cpython_source_dir="$topdir/_build/3rdparty/Python-${py_ver_str}" | ||
|
||
# Perform the configuration/make/make install process. | ||
set -x | ||
cd $cpython_build_dir | ||
eval $config_envs $cpython_source_dir/configure $prefix_option $config_options "--enable-shared" | ||
eval $config_envs $cpython_source_dir/configure $prefix_option $config_options | ||
# The make -j command may fail on some OS. | ||
# make -j "$(nproc)" | ||
make -j8 build_all | ||
make -j8 altinstall | ||
set +x | ||
|
||
# Print the summary. | ||
echo "================ Summary ================" | ||
echo " CPython is built into $cpython_build_dir" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Stop on error. | ||
set -e | ||
|
||
topdir=$PWD | ||
# Environment | ||
if [ -f "/etc/os-release" ]; then | ||
source /etc/os-release | ||
os=$ID | ||
else | ||
os=$(uname) | ||
fi | ||
|
||
prepare_dirs () { | ||
cpython_build_dir="$topdir/_build/python_dist/$os/cpython" | ||
kclvm_packages_dir="$topdir/_build/packages" | ||
kcl_install_dir="$topdir/_build/python_dist/$os/kclvm" | ||
mkdir -p "$kcl_install_dir" | ||
mkdir -p "$kclvm_packages_dir" | ||
} | ||
|
||
prepare_dirs | ||
|
||
# python exe name | ||
py_exe_name="python3.7" | ||
if [ -d "${cpython_build_dir}/lib/python3.9" ]; then | ||
py_exe_name="python3.9" | ||
fi | ||
|
||
# py_lib_basename: python3.x | ||
py_lib_basename="python3.7" | ||
if [ -d "${cpython_build_dir}/lib/python3.9" ]; then | ||
py_lib_basename="python3.9" | ||
fi | ||
|
||
# Perform the build process. | ||
set -x | ||
|
||
# Copy files from CPython. | ||
cd $kcl_install_dir | ||
mkdir -p bin | ||
mkdir -p lib | ||
cp $cpython_build_dir/bin/${py_exe_name} $kcl_install_dir/bin/kclvm | ||
cp -r $cpython_build_dir/lib/${py_lib_basename} $kcl_install_dir/lib/ | ||
|
||
# Darwin dylib | ||
if [ -e $cpython_build_dir/lib/lib${py_lib_basename}.dylib ]; then | ||
touch $kcl_install_dir/lib/lib${py_lib_basename}.dylib | ||
rm $kcl_install_dir/lib/lib${py_lib_basename}.dylib | ||
mv $cpython_build_dir/lib/lib${py_lib_basename}.dylib $kcl_install_dir/lib/lib${py_lib_basename}.dylib | ||
fi | ||
# Linux so | ||
if [ -e $cpython_build_dir/lib/lib${py_lib_basename}m.so.1.0 ]; then | ||
touch $kcl_install_dir/lib/lib${py_lib_basename}.so | ||
rm $kcl_install_dir/lib/lib${py_lib_basename}.so | ||
mv $cpython_build_dir/lib/lib${py_lib_basename}m.so.1.0 $kcl_install_dir/lib/lib${py_lib_basename}.so | ||
fi | ||
# Windows dll | ||
if [ -e $cpython_build_dir/lib/lib${py_lib_basename}.dll ]; then | ||
touch $kcl_install_dir/lib/lib${py_lib_basename}.dll | ||
rm $kcl_install_dir/lib/lib${py_lib_basename}.dll | ||
mv $cpython_build_dir/lib/lib${py_lib_basename}.dll $kcl_install_dir/lib/lib${py_lib_basename}.dll | ||
fi | ||
cp -r $cpython_build_dir/include $kcl_install_dir/ | ||
|
||
# Copy KCL Scripts. | ||
scripts_dir="$topdir/internal/scripts/python-plugin/cli" | ||
cp "$scripts_dir/kcl" $kcl_install_dir/bin/ | ||
cp "$scripts_dir/kcl-plugin" $kcl_install_dir/bin/ | ||
cp "$scripts_dir/kcl-doc" $kcl_install_dir/bin/ | ||
cp "$scripts_dir/kcl-test" $kcl_install_dir/bin/ | ||
cp "$scripts_dir/kcl-lint" $kcl_install_dir/bin/ | ||
cp "$scripts_dir/kcl-fmt" $kcl_install_dir/bin/ | ||
cp "$scripts_dir/kcl-vet" $kcl_install_dir/bin/ | ||
chmod +x $kcl_install_dir/bin/kcl | ||
chmod +x $kcl_install_dir/bin/kcl-plugin | ||
chmod +x $kcl_install_dir/bin/kcl-doc | ||
chmod +x $kcl_install_dir/bin/kcl-test | ||
chmod +x $kcl_install_dir/bin/kcl-lint | ||
chmod +x $kcl_install_dir/bin/kcl-fmt | ||
chmod +x $kcl_install_dir/bin/kcl-vet | ||
|
||
if [ -d $kcl_install_dir/lib/${py_lib_basename}/kclvm ]; then | ||
rm -rf $kcl_install_dir/lib/${py_lib_basename}/kclvm | ||
fi | ||
|
||
# Get site-packages. | ||
$kcl_install_dir/bin/kclvm -m pip install --upgrade -U kclvm | ||
|
||
# Install plugins | ||
cp -rf $topdir/plugins $kcl_install_dir/ | ||
|
||
set +x | ||
|
||
# build kcl | ||
|
||
cd $topdir/kclvm | ||
cargo build --release | ||
|
||
# Switch dll file extension according to os. | ||
dll_extension="so" | ||
case $os in | ||
"Default" | "default" | "centos" | "ubuntu" | "debian" | "Ubuntu" |"Debian" | "Static-Debian" | "Cood1-Debian" | "Cood1Shared-Debian") | ||
dll_extension="so" | ||
;; | ||
"Darwin" | "darwin" | "ios" | "macos") | ||
dll_extension="dylib" | ||
;; | ||
*) dll_extension="dll" | ||
;; | ||
esac | ||
|
||
# Copy libkclvm_cli lib | ||
|
||
if [ -e $topdir/kclvm/target/release/libkclvm_cli_cdylib.$dll_extension ]; then | ||
touch $kcl_install_dir/bin/libkclvm_cli_cdylib.$dll_extension | ||
rm $kcl_install_dir/bin/libkclvm_cli_cdylib.$dll_extension | ||
cp $topdir/kclvm/target/release/libkclvm_cli_cdylib.$dll_extension $kcl_install_dir/bin/libkclvm_cli_cdylib.$dll_extension | ||
fi | ||
|
||
# build kcl LSP server | ||
|
||
cd $topdir/kclvm/tools/src/LSP | ||
cargo build --release | ||
|
||
touch $kcl_install_dir/bin/kcl-language-server | ||
rm $kcl_install_dir/bin/kcl-language-server | ||
cp $topdir/kclvm/target/release/kcl-language-server $kcl_install_dir/bin/kcl-language-server | ||
|
||
|
||
cd $topdir/kclvm_cli | ||
cargo build --release | ||
|
||
touch $kcl_install_dir/bin/kclvm_cli | ||
rm $kcl_install_dir/bin/kclvm_cli | ||
cp ./target/release/kclvm_cli $kcl_install_dir/bin/kclvm_cli | ||
|
||
|
||
# Copy kcl C API header | ||
cd $topdir/kclvm/runtime | ||
cp src/_kclvm.h $kcl_install_dir/include/_kclvm.h | ||
|
||
# build kcl plugin python module | ||
cd $topdir/kclvm/plugin | ||
cp ./kclvm_plugin.py $kcl_install_dir/lib/site-packages/ | ||
cp ./kclvm_runtime.py $kcl_install_dir/lib/site-packages/ | ||
|
||
cd $topdir | ||
# Print the summary. | ||
echo "================ Summary ================" | ||
echo " KCLVM is updated into $kcl_install_dir" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/sh | ||
|
||
kclvm_path=$(cd `dirname $0`; pwd)/kclvm | ||
install_dir=$(cd `dirname $0`/..; pwd) | ||
export KCLVM_CLI_BIN_PATH=$install_dir/bin | ||
export PATHONPATH='' | ||
$kclvm_path -m kclvm "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/sh | ||
|
||
kclvm_path=$(cd `dirname $0`; pwd)/kclvm | ||
install_dir=$(cd `dirname $0`/..; pwd) | ||
export KCLVM_CLI_BIN_PATH=$install_dir/bin | ||
export PATHONPATH='' | ||
$kclvm_path -m kclvm.tools.docs "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/sh | ||
|
||
kclvm_path=$(cd `dirname $0`; pwd)/kclvm | ||
install_dir=$(cd `dirname $0`/..; pwd) | ||
export KCLVM_CLI_BIN_PATH=$install_dir/bin | ||
export PATHONPATH='' | ||
$kclvm_path -m kclvm.tools.format "$@" |
Oops, something went wrong.