Skip to content

Building from source

Marvin1099 edited this page Apr 11, 2024 · 31 revisions

I you want to build from source, you can do so on Windows and Linux.
Here is a detailed step by step guide.
Grab Python
Download the repository
Fix a later Issue
Download Dependency's
Sound Effects
Update Submodules
Run Pyinstaller
Add BEE Items
Linux Puzzlemaker Fix
Run BEE 2
Add a shortcut
Fully Automated Building Script

1. Grab Python

  • On Linux
    • Download python from your your package manager (also grab python-pip and git)
    • If you want to you can try and grab the required packages from your package manager
    • Not all of them will exist in your package manager
    • So grab the rest or just all of the required packages over a python venv
      • For this you will need to run something like this
      • python -m venv %YOUR-PREFERRED-PATH-FOR-VENV% (You will need to change this to any path you like to use)
      • At this point you will need to source the venv, so on a bash terminal you will need to run
      • source %YOUR-PREFERRED-PATH-FOR-VENV%/bin/activate
  • On Windows

2. Download the repository

  • For that go copy the main github repo link (so https://github.com/BEEmod/BEE2.4)
  • Then clone the repo (you can also download the zip on the main github repo)
    • Run git clone --recurse-submodules https://github.com/BEEmod/BEE2.4.git for the main repo
    • Alternatively you can run git clone -b dev --recurse-submodules https://github.com/BEEmod/BEE2.4.git to get the dev branch

3. Fix a problem for later

  • Here you will need to rename or delete the geocable.py that is not working right now (and is not required anyway)
    • So on Linux run mv BEE2.4/hammeraddons/transforms/geocable.py BEE2.4/hammeraddons/transforms/geocable.py.disabeled
    • On Windows run ren BEE2.4\hammeraddons\transforms\geocable.py BEE2.4\hammeraddons\transforms\geocable.py.disabeled

4. Download Dependency's

  • For that fist go into the cloned BEE2.4 directory
    • So type cd Bee2.4
  • So now install the requirements from the requirements.txt file
    • So run pip install -r requirements.txt
    • You also need to run pip install -r dev-requirements.txt if you grabbed the dev branch

5. Enable sound effects

  • For that you will need a copy of FFmpeg
  • You will need to put these in the lib-32 and/or lib-64/ folders (if you are in the BEE2.4 Folder).
    • Download the 32-bit (win32-lgpl-shared)
    • Or 64-bit builds (win64-lgpl-shared)
  • Then copy the contents of the bin folder into the appropriate lib-XX folder mentioned.
  • You can try adding the files from the linux64-lgpl-shared bin folder (to the lib-64 folder)
    But on linux, as far as I have seen, sound is not working jet

6. Update the submodules

  • Here just run git submodule update --init

7. Run the pyinstaller

  • To do this run cd src from the BEE2.4 directory (your terminal should still be in there)
  • Compile the app
    • Here run pyinstaller --distpath ../dist/64bit/ --workpath ../build_tmp compiler.spec
    • Also run pyinstaller --distpath ../dist/64bit/ --workpath ../build_tmp BEE2.spec

8. Add Items to BEE

  • Change directory to ../dist/64bit/BEE2/packages/ (relative fron the src directory)
    • So on Linux run cd ../dist/64bit/BEE2/
    • On Windows you will need cd ..\dist\64bit\BEE2\
    • Keep in mind if you build for 32 bit you will need to use the 32bit folder
  • Create the packages folder
    • So run mkdir packages
  • Here you will need to grab the items from the newest release
  • Then copy over the files inside the zip into the package directory

9. Fix puzzlemaker on Linux

  • On Linux the puzzlemaker seems to be broken
  • One way that was found to fix it is here portal2/issues/403
  • Essentially what you will need to do is download a old version and copy over the working library file
  • Fist make sure steam is not running
  • Then run steam -console or steam-native -console
  • After steam has started click on console
  • Then in there run download_depot 620 661 2854055004190207766
  • Then go to the folder $HOME/.local/share/Steam/ubuntu12_32/steamapps/content/app_620/depot_661/bin/linux32
  • There copy the filesystem_stdio.so to $HOME/.local/share/Steam/steamapps/common/Portal 2/bin/linux32
    • You can also use this command for that cp "$HOME/.local/share/Steam/ubuntu12_32/steamapps/content/app_620/depot_661/bin/linux32/filesystem_stdio.so" "$HOME/.local/share/Steam/steamapps/common/Portal 2/bin/linux32/filesystem_stdio.so"

10. Run Bee2

  • Finally go back to the BEE2.4/dist/64bit/BEE2/ folder and run the BEE2 file (or 32bit if you used that)
  • At this point you can do any use BEE2 as you expect it to. For example you can set presets and export your setup to portal 2 (Or other suported games like aperture tag)

11. Add a Shortcut

  • To add a shortcut on windows rightclick the BEE2.exe and select create shortcut
  • Now you can copy or move the shorcut to your prefered location
  • In the following don't forget to replace %yourbeeroot% with the location to the BEE2.4 folder
    So on Linux create a file named BEE2.desktop with the following content
=== Click here to expand the shortcut code ===
[Desktop Entry]
Exec=%yourbeeroot%/dist/64bit/BEE2/BEE2
GenericName=BEE2
Icon=%yourbeeroot%/dist/64bit/BEE/icon/BEE2.ico
Name=BEE2
Path=%yourbeeroot%/dist/64bit/BEE2
StartupNotify=true
StartupWMClass=BEE2
Terminal=false
Type=Application
  • Now copy or move the file to any folder you like to have a shortcut at

12. Fully Automate Building on Linux

  • Since the Windows version is getting auto builds you probably only want to build Linux Here is a way to automate building on Linux
  • Preparation (Only has to be done once)
    • Add a python venv like it says in here Grab Python under Linux
    • Prepare a main folder where your patch files can live For me that is: $HOME/Documents/Coding/Git/Build-Bee2/
    • All patch files and the BEE2.4 folder will go in this folder so chose wisely
  • The Fully Automated Script
    • Now in the script don't forget to change the line at the start pythonenv="%PATH-HERE%" to your python venv
    • Keep in mind that the building and creating of folders is completely automated
    • Also do not run anything that you do not trust, so make sure you somewhat understand what is going on in the script
    • To run the script you will need Bash, Python, Git, Curl, JQ, tar, unzip, pyinstaller, awk and pip
      Some of these you probably have installed, if not download them in your package manager
    • So now go ahead and make a new file in the build root and name it something like bee-builder.sh then add the following
=== Click here to expand the automation code ===
#!/bin/bash

# pythonenv="%PATH-HERE%" # uncomment and set to python environment activation file
# (eg. /home/marvin/Apps/Games/python-env/bin/activate)
# or just use pythonenv=false to disable the use

echo "Usage: $0 [options]"
echo "Options or User input choices:"
echo "options/choices are a List of options separated by commas (e.g., '0,1,2,3')"
echo "  Use '0' to disable user input (only from command line) and use defaults / arguments"
echo "  Use '1' to delete old build files (warning deletes the entire BEE2.4 folder)"
echo "  Use '2' to run bee after building"
echo "  Use '3' to create a shortcut next to this script"
echo "Options or User input choices that disable things:"
echo "  Use '4' to disable pip update"
echo "  Use '5' to build from the main branch and not from dev"
echo "  Use '6' to skip download of pip requirements"
echo "  Use '7' to not get the icon file"
echo "  Use '8' to not enable the geocable.py"
echo "  Use '9' to stop the linux portal puzzelmaker fix file copy"
echo "  Use '10' to use the current ffmpeg files"
echo "  Use '11' to use the current packages items"
echo "  Use '12' to not re/create a link to dist"
echo "Exit by using '13'"
echo "Leave blank to use the defaults"
echo ""

# Check if user input is disabled or provided via command line
if [[ "$1" != *",0"* && "$1" != "0,"* && "$1" != *",0,"* && "$1" != "0" ]]; then
    echo "Enter your choices separated by commas (timeout in 30 seconds)"
    read -t 30 -p "> " choice
fi

# Combine command line arguments and user input
if [[ -z "${1}" ]]; then
    list="$choice"
else
    list="$1,$choice"
fi

# Set default values
goexit=false
fresh=false
run=false
shortcut=false
pipupdate=true
dev=true
distlink=true
requirements=true
geticon=true
geocablebug=true
portallinuxbug=true
newffmpeg=true
newpackages=true

# Process user input
IFS=',' read -r -a choices <<< "$list"
for choice in "${choices[@]}"; do
    case $choice in
        0) i=true;;
        1) fresh=true;;
        2) run=true;;
        3) shortcut=true;;
        4) pipupdate=false;;
        5) dev=false;;
        6) requirements=false;;
        7) geticon=false;;
        8) geocablebug=false;;
        9) portallinuxbug=false;;
        10) newffmpeg=false;;
        11) newpackages=false;;
        12) distlink=false;;
        13) goexit=true;;
        *) echo "Invalid choice: $choice";;
    esac
done

# Print the selected options
echo ""
echo "Selected options:"
echo "  Build from dev branch: $dev"
echo "  Fresh build: $fresh"
echo "  Run after building: $run"
echo "  Create shortcut: $shortcut"
echo "  Download pip updates: $pipupdate"
echo "  Download requirements: $requirements"
echo "  Get icon: $geticon"
echo "  Disable geocable.py fix: $geocablebug"
echo "  Copying Linux Portal puzzle-maker fix files: $portallinuxbug"
echo "  Download new ffmpeg files: $newffmpeg"
echo "  Download new package items: $newpackages"
echo "  Create syslink to dist: $distlink"
echo "----------"
echo ""

if [[ $goexit = true ]]
then
    echo "Exit selected, exiting"; sleep 1; exit
fi

if [[ -z $pythonenv && $pythonenv != false ]]
then
    echo "Please set the path to your python enviroment on the top of the script"
    echo "If you don't have a python enviroment yet run"
    echo "  python -m venv \"%YOUR-PREFERRED-PATH-FOR-VENV%\""
    echo "So the command could be"
    echo "  python -m venv \"$(pwd)/venv\""
    echo "Then set the path at the top of the script"
    sleep 1
    exit
elif [[ $pythonenv != false ]]
then
    echo "Set enviroment path to '$pythonenv'"
    source "$pythonenv"
else
    echo "Python enviroment is disabled"
fi
echo "----------"
echo ""

cd "$(dirname "$0")"
if [[ $fresh == true ]]
then
    echo "Deleting 'BEE2.4' folder"
    rm -r ./BEE2.4
    echo "Folder removed"
    echo "----------"
    echo ""
fi

if [[ $distlink == true ]]
then
    echo "Making link to the dist folder"
    mkdir -p $(pwd)/BEE2.4/dist
    ln -sfn $(pwd)/BEE2.4/dist dist
    echo "Link created"
    echo "----------"
    echo ""
fi

if [[ $portallinuxbug == true ]]
then
    echo "Copying file to fix portal puzzlmaker linux bug"
    cp "$HOME/.local/share/Steam/ubuntu12_32/steamapps/content/app_620/depot_661/bin/linux32/filesystem_stdio.so" "$HOME/.steam/steam/steamapps/common/Portal 2/bin/linux32/filesystem_stdio.so"
    echo "File copyed"
    echo "----------"
    echo ""
fi


if [[ $dev == true ]]
then
    echo "Downloading git dev branch"
    git clone -b dev --recurse-submodules "https://github.com/BEEmod/BEE2.4.git" temp
else
    echo "Downloading git main branch"
    git clone --recurse-submodules "https://github.com/BEEmod/BEE2.4.git" temp
fi

mkdir -p BEE2.4
echo "Done getting the git project"
echo "Copying git project to BEE2.4 folder"
cp -rfa temp/. ./BEE2.4
rm -r temp
echo "Done copying"
echo "----------"
echo ""

if [[ $geocablebug == true ]]
then
    echo "Moving file to disable geocable"
    mv BEE2.4/hammeraddons/transforms/geocable.py BEE2.4/hammeraddons/transforms/geocable.py.disabeled
    echo "Done moving"
    echo "----------"
    echo ""
fi

if [[ $geticon == true ]]
then
    echo "Downloading icon"
    mkdir -p icon
    curl -L -o "icon/BEE2.ico" "https://raw.githubusercontent.com/BEEmod/BEE2.4/master/BEE2.ico"
    echo "Icon grabbed"
    echo "----------"
    echo ""
fi

if [[ $newffmpeg == true ]]
then
    echo "Downloading newest ffmpeg"
    mkdir -p BEE2.4/lib-64/
    mkdir -p bin
    curl -L -o "bin/ffmpeg-linux64-lgpl-shared.tar.xz" "$(curl -s 'https://api.github.com/repos/BtbN/FFmpeg-Builds/releases/latest' | jq -r '.assets[] | select(.name | endswith("linux64-lgpl-shared.tar.xz")) | .browser_download_url' | head -1)"
    tar --wildcards -xvf "bin/ffmpeg-linux64-lgpl-shared.tar.xz" --strip-components=1 "ffmpeg-*/bin/"
    rm bin/ffmpeg-linux64-lgpl-shared.tar.xz
    cp bin/* BEE2.4/lib-64/
    echo "Done downloading ffmpeg"
    echo "----------"
    echo ""
fi

if [[ $pipupdate == true ]]
then
    pip install --upgrade pip
fi

cd BEE2.4/
if [[ $requirements == true ]]
then
    echo "Downloading requirements"
    pip install -r requirements.txt
    if [[ $def == true ]]
    then
        echo "Downloading dev requirements"
        pip install -r dev-requirements.txt
    fi
    echo "Finished download of requirements"
    echo "----------"
    echo ""
fi

echo "Updating submodules"
git submodule update --init
echo "Grabbed submodules"
echo "----------"
echo ""

if [[ -d "./dist/64bit/compiler" ]]
then
    echo "Removing old compiler files"
    rm -r ./dist/64bit/compiler
    echo "Removed old compiler files"
    echo "----------"
    echo ""
fi

if [[ -d "./dist/64bit/BEE2" ]]
then
    echo "Removing old BEE2 files"
    rm -r ./dist/64bit/BEE2
    echo "Removed old BEE files"
    echo "----------"
    echo ""
fi

echo "Running Pyinstaller"
cd src/
pyinstaller --distpath ../dist/64bit/ --workpath ../build_tmp compiler.spec
if [[ $? != 0 ]]
then
    echo "Error Building make shure you have tk installed, and a venv added if needed"
    sleep 1
    exit
fi
pyinstaller --distpath ../dist/64bit/ --workpath ../build_tmp BEE2.spec
if [[ $? != 0 ]]
then
    echo "Error Building make shure you have tk installed, and a venv added if needed"
    echo "Continuing anyway"
fi
cd ..
echo "Finished Pyinstaller"
echo "----------"
echo ""

cd ..
if [[ $newpackages == true ]]
then
    echo "Grabing new packages"
    ZIP_URLS=$(curl -s 'https://api.github.com/repos/BEEmod/BEE2-items/releases/latest' | jq -r '.assets[] | select(.name | endswith(".zip")) | .browser_download_url')
    for url in $ZIP_URLS
    do
        # Extract the part of the filename after the second underscore
        filename=$(echo "$url" | awk -F'/' '{split($NF,a,"_"); printf "%s", a[3]; for(i=4;i<=length(a);i++) printf "_%s", a[i];}')
        foldername=${filename%.*}
        mkdir -p "$foldername"
        curl -L -o "$foldername/$filename" "$url"
        unzip -o "$foldername/$filename" -d "$foldername"
        rm "$foldername/$filename"
    done
    echo "Packages downloaded"
    echo "----------"
    echo ""
fi

cp ./packages/* BEE2.4/dist/64bit/BEE2/packages/
cp ./music_packages/* BEE2.4/dist/64bit/BEE2/packages/

if [[ $shortcut == true ]]
then
    cd ..
    echo "Creating shortcut"
    if [[ $geticon == true ]]
    then
        geticon="$(pwd)/icon/BEE2.ico"
    else
        geticon="$(pwd)/BEE2.4/dist/64bit/BEE/icon/BEE2.ico"
    fi
    echo "[Desktop Entry]
Exec=$(pwd)/BEE2.4/dist/64bit/BEE2/BEE2
GenericName=BEE2
Icon=$geticon
Name=BEE2
Path=$(pwd)/BEE2.4/dist/64bit/BEE2
StartupNotify=true
StartupWMClass=BEE2
Terminal=false
Type=Application" > BEE2.desktop
    echo "Shortcut created"
fi

if [[ $run == true ]]
then
    echo "Running BEE2"
    cd BEE2.4/dist/64bit/BEE2/
    ./BEE2
    cd ../../../..
    echo "Bee has ended"
fi
  • The Automation script will do the following
    • Create a folder named: packages, music_packages, bin (for ffmpeg), icon (for the icon) ,dist (this is a link to BEE2.4/dist)
    • The setup should look like this after you run the script
    • It will also grab the newest packages and music_packages put them in the folder and copy them after compile
    • It will do the same for ffmpeg (but it will use the bin and not compile)
    • Download the icon as well
    • And Compile BEE2.4 dev
    • Options for the automation script are:
      • Usage: [options]
      • Options or User input choices:
      • options/choices are a List of options separated by commas (e.g., '0,1,2,3')
      • Use '0' to disable user input (only from command line) and use defaults / arguments
      • Use '1' to delete old build files (warning deletes the entire BEE2.4 folder)
      • Use '2' to run bee after building
      • Use '3' to create a shortcut next to this script
      • Options or User input choices that disable things:
      • Use '4' to disable pip update
      • Use '5' to build from the main branch and not from dev
      • Use '6' to skip download of pip requirements
      • Use '7' to not get the icon file
      • Use '8' to not enable the geocable.py
      • Use '9' to stop the linux portal puzzlmaker fix file copy
      • Use '10' to use the current ffmpeg files
      • Use '11' to use the current packages items
      • Use '12' to not re/create a link to dist
      • Exit by using '13'
      • Leave blank to use the defaults
    • Options can be put as the first argument or will be asked for on script start
  • Your Done
    • At this point you can run bee from the BEE2.4/dist/64bit/BEE2/ folder (there run the file BEE2)
  • Adding a Shortcut
    • When running the bee-builder.sh you can use option 3 to automatically create a shortcut for you
    • Or you can also do it by adding a file named BEE2.desktop to your preferred location
      Than adding the following in that file (also change $HOME/Documents/Coding/Git/Build-Bee2 to your build folder)
=== Click here to expand the shortcut code ===
[Desktop Entry]
Exec=$HOME/Documents/Coding/Git/Build-Bee2/BEE2.4/dist/64bit/BEE2/BEE2
GenericName=BEE2
Icon=$HOME/Documents/Coding/Git/Build-Bee2/icon/BEE2.png
Name=BEE2
Path=$HOME/Documents/Coding/Git/Build-Bee2/BEE2.4/dist/64bit/BEE2
StartupNotify=true
StartupWMClass=BEE2
Terminal=false
Type=Application
  • At this point there is nothing to to but to use BEE2 to create some chambers
Clone this wiki locally