Only download & compile required libraries (#18699)
This commit is contained in:
@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* The purpose of this file is just include Marlin Configuration files,
|
||||
* to discover which FEATURES are enabled, without any HAL include.
|
||||
* Used by common-features-dependencies.py
|
||||
*/
|
||||
|
||||
#ifndef __MARLIN_FIRMWARE__
|
||||
#define __MARLIN_FIRMWARE__
|
||||
#endif
|
||||
|
||||
//
|
||||
// Prefix header to acquire configurations
|
||||
//
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../../../../Marlin/src/core/boards.h"
|
||||
#include "../../../../Marlin/src/core/macros.h"
|
||||
#include "../../../../Marlin/Configuration.h"
|
||||
|
||||
#include "../../../../Marlin/Version.h"
|
||||
|
||||
#include "../../../../Marlin/src/inc/Conditionals_LCD.h"
|
||||
|
||||
#include "../../../../Marlin/src/core/drivers.h"
|
||||
#include "../../../../Marlin/Configuration_adv.h"
|
||||
|
||||
#include "../../../../Marlin/src/inc/Conditionals_adv.h"
|
@ -0,0 +1,135 @@
|
||||
#
|
||||
# common-features-dependencies.py
|
||||
# Convenience script to check dependencies and add libs and sources for Marlin Enabled Features
|
||||
#
|
||||
import subprocess
|
||||
import os
|
||||
import re
|
||||
try:
|
||||
import configparser
|
||||
except ImportError:
|
||||
import ConfigParser as configparser
|
||||
from platformio.managers.package import PackageManager
|
||||
|
||||
Import("env")
|
||||
|
||||
FEATURE_DEPENDENCIES = {}
|
||||
|
||||
def load_config():
|
||||
config = configparser.ConfigParser()
|
||||
config.read("platformio.ini")
|
||||
items = config.items('features')
|
||||
for key in items:
|
||||
deps = re.sub(',\\s*', '\n', key[1]).strip().split('\n')
|
||||
if not key[0].upper() in FEATURE_DEPENDENCIES:
|
||||
FEATURE_DEPENDENCIES[key[0].upper()] = {
|
||||
'lib_deps': []
|
||||
}
|
||||
for dep in deps:
|
||||
parts = dep.split('=')
|
||||
name = parts.pop(0)
|
||||
rest = '='.join(parts)
|
||||
if name == 'extra_scripts':
|
||||
FEATURE_DEPENDENCIES[key[0].upper()]['extra_scripts'] = rest
|
||||
elif name == 'src_filter':
|
||||
FEATURE_DEPENDENCIES[key[0].upper()]['src_filter'] = rest
|
||||
else:
|
||||
FEATURE_DEPENDENCIES[key[0].upper()]['lib_deps'] += [dep]
|
||||
|
||||
def install_features_dependencies():
|
||||
load_config()
|
||||
for feature in FEATURE_DEPENDENCIES:
|
||||
if not env.MarlinFeatureIsEnabled(feature):
|
||||
continue
|
||||
|
||||
if 'lib_deps' in FEATURE_DEPENDENCIES[feature]:
|
||||
print("Adding lib_deps for %s... " % feature)
|
||||
|
||||
# deps to add
|
||||
deps_to_add = {}
|
||||
for dep in FEATURE_DEPENDENCIES[feature]['lib_deps']:
|
||||
name, _, _ = PackageManager.parse_pkg_uri(dep)
|
||||
deps_to_add[name] = dep
|
||||
|
||||
# first check if the env already have the dep
|
||||
deps = env.GetProjectOption("lib_deps")
|
||||
for dep in deps:
|
||||
name, _, _ = PackageManager.parse_pkg_uri(dep)
|
||||
if name in deps_to_add:
|
||||
del deps_to_add[name]
|
||||
|
||||
# check if we need ignore any lib
|
||||
lib_ignore = env.GetProjectOption("lib_ignore")
|
||||
for dep in deps:
|
||||
name, _, _ = PackageManager.parse_pkg_uri(dep)
|
||||
if name in deps_to_add:
|
||||
del deps_to_add[name]
|
||||
|
||||
# any left?
|
||||
if len(deps_to_add) <= 0:
|
||||
continue
|
||||
|
||||
# add only the missing deps
|
||||
proj = env.GetProjectConfig()
|
||||
proj.set("env:" + env["PIOENV"], "lib_deps", deps + list(deps_to_add.values()))
|
||||
|
||||
if 'extra_scripts' in FEATURE_DEPENDENCIES[feature]:
|
||||
print("Executing extra_scripts for %s... " % feature)
|
||||
env.SConscript(FEATURE_DEPENDENCIES[feature]['extra_scripts'], exports="env")
|
||||
|
||||
if 'src_filter' in FEATURE_DEPENDENCIES[feature]:
|
||||
print("Adding src_filter for %s... " % feature)
|
||||
proj = env.GetProjectConfig()
|
||||
src_filter = env.GetProjectOption("src_filter")
|
||||
|
||||
# first we need to remove the references to the same folder
|
||||
my_srcs = re.findall( r'[+-](<.*?>)', FEATURE_DEPENDENCIES[feature]['src_filter'])
|
||||
cur_srcs = re.findall( r'[+-](<.*?>)', src_filter[0])
|
||||
for d in my_srcs:
|
||||
if d in cur_srcs:
|
||||
src_filter[0] = re.sub(r'[+-]' + d, '', src_filter[0])
|
||||
|
||||
src_filter[0] = FEATURE_DEPENDENCIES[feature]['src_filter'] + ' ' + src_filter[0]
|
||||
proj.set("env:" + env["PIOENV"], "src_filter", src_filter)
|
||||
env.Replace(SRC_FILTER=src_filter)
|
||||
|
||||
# load marlin features
|
||||
def load_marlin_features():
|
||||
if "MARLIN_FEATURES" in env:
|
||||
return
|
||||
|
||||
# procces defines
|
||||
# print(env.Dump())
|
||||
build_flags = env.get('BUILD_FLAGS')
|
||||
build_flags = env.ParseFlagsExtended(build_flags)
|
||||
cmd = []
|
||||
# build flags from board.json
|
||||
# if 'BOARD' in env:
|
||||
# cmd += [env.BoardConfig().get("build.extra_flags")]
|
||||
for s in build_flags['CPPDEFINES']:
|
||||
if isinstance(s, tuple):
|
||||
cmd += ['-D' + s[0] + '=' + str(s[1])]
|
||||
else:
|
||||
cmd += ['-D' + s]
|
||||
# cmd += ['-w -dM -E -x c++ Marlin/src/inc/MarlinConfigPre.h']
|
||||
cmd += ['-w -dM -E -x c++ buildroot/share/PlatformIO/scripts/common-features-dependencies.h']
|
||||
cmd = [env.get('CXX')] + cmd
|
||||
cmd = ' '.join(cmd)
|
||||
print(cmd)
|
||||
define_list = subprocess.check_output(cmd, shell=True).splitlines()
|
||||
marlin_features = {}
|
||||
for define in define_list:
|
||||
feature = define[8:].strip().decode().split(' ')
|
||||
feature, definition = feature[0], ' '.join(feature[1:])
|
||||
marlin_features[feature] = definition
|
||||
env["MARLIN_FEATURES"] = marlin_features
|
||||
|
||||
def MarlinFeatureIsEnabled(env, feature):
|
||||
load_marlin_features()
|
||||
return feature in env["MARLIN_FEATURES"]
|
||||
|
||||
# add a method for others scripts to check if a feature is enabled
|
||||
env.AddMethod(MarlinFeatureIsEnabled)
|
||||
|
||||
# install all dependencies for features enabled in Configuration.h
|
||||
install_features_dependencies()
|
Reference in New Issue
Block a user