Skip to content

Commit

Permalink
🔨 Build scripts cleanup (#27157)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
  • Loading branch information
classicrocker883 and thinkyhead authored Jun 14, 2024
1 parent ae28439 commit 959be66
Show file tree
Hide file tree
Showing 41 changed files with 130 additions and 151 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/HAL/DUE/upload_extra_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

if current_OS == 'Windows':

Import("env")
env = pioutil.env

# Use bossac.exe on Windows
env.Replace(
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/LPC1768/upload_extra_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
target_drive = "REARM"

import platform

current_OS = platform.system()
Import("env")

env = pioutil.env

def print_error(e):
print('\nUnable to find destination disk (%s)\n' \
Expand Down
56 changes: 0 additions & 56 deletions Marlin/src/HAL/STM32F1/build_flags.py

This file was deleted.

3 changes: 1 addition & 2 deletions buildroot/share/PlatformIO/scripts/SAMD21_minitronics20.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
if pioutil.is_pio_build():
from os.path import join, isfile
import shutil

Import("env")
env = pioutil.env

mf = env["MARLIN_FEATURES"]
rxBuf = mf["RX_BUFFER_SIZE"] if "RX_BUFFER_SIZE" in mf else "0"
Expand Down
3 changes: 1 addition & 2 deletions buildroot/share/PlatformIO/scripts/SAMD51_grandcentral_m4.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
if pioutil.is_pio_build():
from os.path import join, isfile
import shutil

Import("env")
env = pioutil.env

mf = env["MARLIN_FEATURES"]
rxBuf = mf["RX_BUFFER_SIZE"] if "RX_BUFFER_SIZE" in mf else "0"
Expand Down
3 changes: 1 addition & 2 deletions buildroot/share/PlatformIO/scripts/STM32F103RC_MEEB_3DP.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#
import pioutil
if pioutil.is_pio_build():

Import("env", "projenv")
env = pioutil.env

flash_size = 0
vect_tab_addr = 0
Expand Down
5 changes: 2 additions & 3 deletions buildroot/share/PlatformIO/scripts/STM32F103RC_fysetc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
#
import pioutil
if pioutil.is_pio_build():
from os.path import join
from os.path import expandvars
Import("env")
from os.path import join, expandvars
env = pioutil.env

# Custom HEX from ELF
env.AddPostAction(
Expand Down
63 changes: 63 additions & 0 deletions buildroot/share/PlatformIO/scripts/STM32F1_build_flags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python
#
# STM32F1_build_flags.py
# Add build_flags for the base STM32F1_maple environment (stm32f1-maple.ini)
#
from __future__ import print_function
import sys

# Dynamic build flags for generic compile options
if __name__ == "__main__":

# Print these plus the given args when running directly on the command-line
args = [
"-std=gnu++14",
"-Os",
"-mcpu=cortex-m3",
"-mthumb",

"-fsigned-char",
"-fno-move-loop-invariants",
"-fno-strict-aliasing",
"-fsingle-precision-constant",

"--specs=nano.specs",
"--specs=nosys.specs",

"-MMD", "-MP",

"-IMarlin/src/HAL/STM32F1",

"-DTARGET_STM32F1",
"-DARDUINO_ARCH_STM32",
"-DPLATFORM_M997_SUPPORT"
] + sys.argv[1:]

print(" ".join(args))

else:

# Extra script for stm32f1-maple.ini build_flags

import pioutil
if pioutil.is_pio_build():
pioutil.env.Append(
ARFLAGS=["rcs"],

ASFLAGS=["-x", "assembler-with-cpp"],

CXXFLAGS=[
"-fabi-version=0",
"-fno-use-cxa-atexit",
"-fno-threadsafe-statics"
],
LINKFLAGS=[
"-Os",
"-mcpu=cortex-m3",
"-ffreestanding",
"-mthumb",
"--specs=nano.specs",
"--specs=nosys.specs",
"-u_printf_float",
],
)
5 changes: 2 additions & 3 deletions buildroot/share/PlatformIO/scripts/STM32F1_create_variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
#
import pioutil
if pioutil.is_pio_build():
import shutil,marlin
import shutil, marlin
from pathlib import Path

Import("env")
env = pioutil.env
platform = env.PioPlatform()
board = env.BoardConfig()

Expand Down
6 changes: 0 additions & 6 deletions buildroot/share/PlatformIO/scripts/add_nanolib.py

This file was deleted.

4 changes: 2 additions & 2 deletions buildroot/share/PlatformIO/scripts/chitu_crypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#
import pioutil
if pioutil.is_pio_build():
import struct,uuid,marlin
import struct, uuid, marlin

board = marlin.env.BoardConfig()
board = pioutil.env.BoardConfig()

def calculate_crc(contents, seed):
accumulating_xor_value = seed
Expand Down
3 changes: 1 addition & 2 deletions buildroot/share/PlatformIO/scripts/collect-code-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
if pioutil.is_pio_build():

import os, re
Import("env")
Import("projenv")
env = pioutil.env

os.environ['PATH'] = f"./buildroot/bin/:./buildroot/tests/:{os.environ['PATH']}"

Expand Down
2 changes: 1 addition & 1 deletion buildroot/share/PlatformIO/scripts/common-cxxflags.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pioutil
if pioutil.is_pio_build():
Import("env")
env = pioutil.env

cxxflags = [
# "-Wno-incompatible-pointer-types",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#
import pioutil
if pioutil.is_pio_build():
Import("env", "projenv")
env = pioutil.env
projenv = env
Import("projenv") # src_dir environment. Only for post: scripts!

def apply_board_build_flags():
if not 'BOARD_CUSTOM_BUILD_FLAGS' in env['MARLIN_FEATURES']:
Expand Down
4 changes: 2 additions & 2 deletions buildroot/share/PlatformIO/scripts/common-dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import pioutil
if pioutil.is_pio_build():

import subprocess,os,re,fnmatch,glob
import os, re, fnmatch, glob
srcfilepattern = re.compile(r".*[.](cpp|c)$")
marlinbasedir = os.path.join(os.getcwd(), "Marlin/")
Import("env")
env = pioutil.env

from platformio.package.meta import PackageSpec
from platformio.project.config import ProjectConfig
Expand Down
11 changes: 4 additions & 7 deletions buildroot/share/PlatformIO/scripts/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def blab(str,level=1):
if verbose >= level: print(f"[config] {str}")

def config_path(cpath):
return Path("Marlin", cpath, encoding='utf-8')
return Path("Marlin", cpath)

# Apply a single name = on/off ; name = value ; etc.
# TODO: Limit to the given (optional) configuration
Expand Down Expand Up @@ -223,7 +223,7 @@ def apply_config_ini(cp):
sect = 'base'
if '@' in ckey: sect, ckey = map(str.strip, ckey.split('@'))
cp2 = configparser.ConfigParser()
cp2.read(config_path(ckey))
cp2.read(config_path(ckey), encoding='utf-8')
apply_sections(cp2, sect)
ckey = 'base'

Expand Down Expand Up @@ -270,7 +270,7 @@ def apply_config_ini(cp):

if ini_file:
user_ini = configparser.ConfigParser()
user_ini.read(ini_file)
user_ini.read(ini_file, encoding='utf-8')
apply_config_ini(user_ini)

else:
Expand All @@ -279,11 +279,8 @@ def apply_config_ini(cp):
#
import pioutil
if pioutil.is_pio_build():

Import("env")

try:
verbose = int(env.GetProjectOption('custom_verbose'))
verbose = int(pioutil.env.GetProjectOption('custom_verbose'))
except:
pass

Expand Down
2 changes: 1 addition & 1 deletion buildroot/share/PlatformIO/scripts/custom_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pioutil
if pioutil.is_pio_build():
import marlin
board = marlin.env.BoardConfig()
board = pioutil.env.BoardConfig()

address = board.get("build.address", "")
if address:
Expand Down
4 changes: 2 additions & 2 deletions buildroot/share/PlatformIO/scripts/download_mks_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#
import pioutil
if pioutil.is_pio_build():
Import("env")
import requests,zipfile,tempfile,shutil
import requests, zipfile, tempfile, shutil
from pathlib import Path

env = pioutil.env
url = "https://github.com/makerbase-mks/Mks-Robin-Nano-Marlin2.0-Firmware/archive/0263cdaccf.zip"
deps_path = Path(env.Dictionary("PROJECT_LIBDEPS_DIR"))
zip_path = deps_path / "mks-assets.zip"
Expand Down
3 changes: 1 addition & 2 deletions buildroot/share/PlatformIO/scripts/fix_framework_weakness.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from os.path import join, isfile
from pprint import pprint

Import("env")

env = pioutil.env
if env.MarlinHas("POSTMORTEM_DEBUGGING"):
FRAMEWORK_DIR = env.PioPlatform().get_package_dir("framework-arduinoststm32-maple")
patchflag_path = join(FRAMEWORK_DIR, ".exc-patching-done")
Expand Down
4 changes: 2 additions & 2 deletions buildroot/share/PlatformIO/scripts/generic_create_variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import pioutil, re
marlin_variant_pattern = re.compile("marlin_.*")
if pioutil.is_pio_build():
import shutil,marlin
import shutil, marlin
from pathlib import Path

#
# Get the platform name from the 'platform_packages' option,
# or look it up by the platform.class.name.
#
env = marlin.env
env = pioutil.env
platform = env.PioPlatform()

from platformio.package.meta import PackageSpec
Expand Down
2 changes: 1 addition & 1 deletion buildroot/share/PlatformIO/scripts/lerdge.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
import pioutil
if pioutil.is_pio_build():
import os,marlin
import os, marlin

board = marlin.env.BoardConfig()

Expand Down
4 changes: 1 addition & 3 deletions buildroot/share/PlatformIO/scripts/mc-apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
#
# Create a Configuration from marlin_config.json
#
import json
import sys
import shutil
import json, sys, shutil

opt_output = '--opt' in sys.argv
output_suffix = '.sh' if opt_output else '' if '--bare-output' in sys.argv else '.gen'
Expand Down
3 changes: 1 addition & 2 deletions buildroot/share/PlatformIO/scripts/openblt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import pioutil
if pioutil.is_pio_build():
from os.path import join

Import("env")
env = pioutil.env

board = env.BoardConfig()
board_keys = board.get("build").keys()
Expand Down
5 changes: 3 additions & 2 deletions buildroot/share/PlatformIO/scripts/pioutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
# pioutil.py
#

from SCons.Script import DefaultEnvironment
env = DefaultEnvironment()

# Make sure 'vscode init' is not the current command
def is_pio_build():
from SCons.Script import DefaultEnvironment
env = DefaultEnvironment()
if "IsCleanTarget" in dir(env) and env.IsCleanTarget(): return False
return not env.IsIntegrationDump()

Expand Down
Loading

0 comments on commit 959be66

Please sign in to comment.