Alexey-T / CudaText_up

Bash script to download CudaText sources (all packages) and compile them. Requires Lazarus 2.0+.
MIT License
15 stars 10 forks source link

cudaup.sh not portable (does not run "out of the box" on freebsd) #11

Open bogen85 opened 3 years ago

bogen85 commented 3 years ago

I got cudatext to build on freebsd by hacking cudaup.sh in a non-maintainable way.

diff --git a/cudaup.sh b/cudaup.sh
index 03ba3bd..d418e90 100755
--- a/cudaup.sh
+++ b/cudaup.sh
@@ -1,4 +1,6 @@
-#!/bin/bash
+#!/usr/bin/env bash
+
+set -euo pipefail

 #set -e
 OS="linux"
@@ -29,17 +31,17 @@ Options:

 [ $# -eq 0 ] && { echo "$usage"; exit 0; }

-OPTIONS=hgpml:o:c:w:
-LONGOPTS=clean,help,get,packs,make,lazdir:,os:,cpu:,ws:
-! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
-if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
-       echo "$usage"  
-       exit 2
-fi
-eval set -- "$PARSED"
+#OPTIONS=hgpml:o:c:w:
+#LONGOPTS=clean,help,get,packs,make,lazdir:,os:,cpu:,ws:
+#! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
+#if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
+#      echo "$usage"
+#      exit 2
+#fi
+#eval set -- "$PARSED"

 while true; do
-       case "$1" in
+       case "${1:-__NONE__}" in
        --clean)
                DoClean=true
                shift
@@ -80,6 +82,9 @@ while true; do
                shift
                break
                ;;
+       __NONE__)
+               break
+               ;;
        esac
 done

@@ -162,7 +167,7 @@ then
                        "$lazdir/lazbuild" $inc -q --lazarusdir="$lazdir" "./src/$i"
                done
        fi
-       rm "./src/CudaText/app/cudatext"
+       rm -f "./src/CudaText/app/cudatext"
        "$lazdir/lazbuild" $inc -q --lazarusdir="$lazdir" "./src/CudaText/app/cudatext.lpi"
        OUTDIR="./bin/$OS-$CPU-$WS"
        mkdir -pv $OUTDIR

Only needed to install a few packages to get the build via ./cudaup.sh -o freebsd -m to complete

sudo pkg ins lazarus-gtk2
sudo pkg ins fpc
sudo pkg ins fpc-fcl-stl
...
(9022) Compiling resource /usr/home/dwight/build/cudatext/CudaText_up/src/CudaText/app/lib/x86_64-freebsd/cudatext.or
(9015) Linking /usr/home/dwight/build/cudatext/CudaText_up/src/CudaText/app/cudatext
(1008) 939 lines compiled, 11.4 sec
(1021) 42 warning(s) issued
(1022) 27 hint(s) issued
(1023) 1 note(s) issued

I would like to fix this and submit a PR that makes cudaup portable on Linux and FreeBSD, but I'd almost prefer to rewrite it in python (so it is not relying on external commands like getopt that may not be portable between Linux and FreeBSD) and just have cudaup.sh be a wrapper for cudaup.py, and determine which python to execute by checking which python versions are installed, and choosing the latest (or something like that, to be determined...).

So I'd like to discuss the most agreeable way to proceed on this.

Alexey-T commented 3 years ago

@bogen85 Let's proceed and rewrite it in python. You can start by creating the CudaText_up_py repo just now. Let's have the additional cudaup repo. we will merge or not merge it later.

bogen85 commented 3 years ago

Alright, sounds good. I'll create my own CudaText_up_py repo and proceed from there.

bogen85 commented 3 years ago

@Alexey-T I created CudaText_up_py

It seems to work on FreeBSD and Linux, but I'm sure I have permissions and other issues to work out, plus I've not exercised the "install packages to Lazarus" as I've not make my own custom Lazarus directory.

As such, I would consider this work in progress as I work out any issues.

For now see ./cudaup.sh --help until I get a working README.md

Python to use is automatic, ./cudaup.sh finds a compatible one and uses it (but one can be specified). I will document that in the README.md.

One does not need to be in the CudaText_up_py directory to run the script, one can provide the complete path to the script (the other files/folders it comes with must reside with the the script.) I don't have it working if it is in PATH yet, but I will add the ability to run it from anywhere if it is the PATH.

By default the working directory (where src is created/used) is the current directory, but a different one can be specified.

Alexey-T commented 3 years ago

Great! I will try it soon.

veksha commented 2 years ago

Hi, guys. Tried CudaText_up_py for MacOS.

opened an issue here: https://github.com/bogen85/CudaText_up_py/issues/1