diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2021-05-31 21:58:41 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2021-06-07 16:32:24 +0000 |
commit | f0a39bab91c7ea823dcfb645c0b7f934d3f4fcdf (patch) | |
tree | cfd05591b28a0955e40106e828f1f6451ec9f277 | |
parent | 2bbadbf3d012c29b3a046913fed95ce29e1b9726 (diff) |
baremetal: Implement validate script in CPP toolchain modules
It makes sense to check the architecture inside of the 'validate'
script in the module; and then we can throw an error only once.
Change-Id: I17821404ad854e38bafc70f1ca6904c33c48147f
Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
-rw-r--r-- | share/qbs/modules/cpp/CppModule.qbs | 11 | ||||
-rw-r--r-- | share/qbs/modules/cpp/cosmic.js | 22 | ||||
-rw-r--r-- | share/qbs/modules/cpp/cosmic.qbs | 2 | ||||
-rw-r--r-- | share/qbs/modules/cpp/cpp.js | 13 | ||||
-rw-r--r-- | share/qbs/modules/cpp/iar.js | 36 | ||||
-rw-r--r-- | share/qbs/modules/cpp/iar.qbs | 4 | ||||
-rw-r--r-- | share/qbs/modules/cpp/keil.js | 16 | ||||
-rw-r--r-- | share/qbs/modules/cpp/keil.qbs | 2 | ||||
-rw-r--r-- | share/qbs/modules/cpp/sdcc.js | 4 | ||||
-rw-r--r-- | share/qbs/modules/cpp/sdcc.qbs | 2 |
10 files changed, 33 insertions, 79 deletions
diff --git a/share/qbs/modules/cpp/CppModule.qbs b/share/qbs/modules/cpp/CppModule.qbs index 98bf72e9f..b88248725 100644 --- a/share/qbs/modules/cpp/CppModule.qbs +++ b/share/qbs/modules/cpp/CppModule.qbs @@ -32,7 +32,7 @@ import qbs.ModUtils import qbs.Utilities import qbs.WindowsUtils - +import "cpp.js" as Cpp import "setuprunenv.js" as SetupRunEnv Module { @@ -212,6 +212,8 @@ Module { property string libraryPathFlag property string linkerScriptFlag + property stringList knownArchitectures: [] + property string linkerMode: "automatic" PropertyOptions { name: "linkerMode" @@ -541,6 +543,13 @@ Module { return '"' + a + '"'; }).join(", ") + ". See https://docs.microsoft.com/en-us/windows/desktop/SysInfo/operating-system-version"); } + + if (knownArchitectures && knownArchitectures.length > 0) { + var isSupported = Cpp.supportsArchitecture(qbs.architecture, knownArchitectures); + if (!isSupported) { + throw ModUtils.ModuleError("Unsupported architecture: '" + qbs.architecture + "'"); + } + } } } diff --git a/share/qbs/modules/cpp/cosmic.js b/share/qbs/modules/cpp/cosmic.js index ca8cc5a14..7d4aa04a0 100644 --- a/share/qbs/modules/cpp/cosmic.js +++ b/share/qbs/modules/cpp/cosmic.js @@ -49,8 +49,6 @@ function compilerName(qbs) { return "cx6812"; else if (architecture === "m68k") return "cx332"; - throw "Unable to deduce compiler name for unsupported architecture: '" - + architecture + "'"; } function assemblerName(qbs) { @@ -65,8 +63,6 @@ function assemblerName(qbs) { return "ca6812"; else if (architecture === "m68k") return "ca332"; - throw "Unable to deduce assembler name for unsupported architecture: '" - + architecture + "'"; } function linkerName(qbs) { @@ -78,8 +74,6 @@ function linkerName(qbs) { || architecture === "m68k") { return "clnk"; } - throw "Unable to deduce linker name for unsupported architecture: '" - + architecture + "'"; } function listerName(qbs) { @@ -91,8 +85,6 @@ function listerName(qbs) { || architecture === "m68k") { return "clabs"; } - throw "Unable to deduce lister name for unsupported architecture: '" - + architecture + "'"; } function archiverName(qbs) { @@ -104,8 +96,6 @@ function archiverName(qbs) { || architecture === "m68k") { return "clib"; } - throw "Unable to deduce archiver name for unsupported architecture: '" - + architecture + "'"; } function staticLibrarySuffix(qbs) { @@ -120,8 +110,6 @@ function staticLibrarySuffix(qbs) { return ".h12"; else if (architecture === "m68k") return ".332"; - throw "Unable to deduce static library suffix for unsupported architecture: '" - + architecture + "'"; } function executableSuffix(qbs) { @@ -136,8 +124,6 @@ function executableSuffix(qbs) { return ".h12"; else if (architecture === "m68k") return ".332"; - throw "Unable to deduce executable suffix for unsupported architecture: '" - + architecture + "'"; } function objectSuffix(qbs) { @@ -149,8 +135,6 @@ function objectSuffix(qbs) { || architecture === "m68k") { return ".o"; } - throw "Unable to deduce object file suffix for unsupported architecture: '" - + architecture + "'"; } function imageFormat(qbs) { @@ -162,8 +146,6 @@ function imageFormat(qbs) { || architecture === "m68k") { return "cosmic"; } - throw "Unable to deduce image format for unsupported architecture: '" - + architecture + "'"; } function guessArchitecture(compilerFilePath) { @@ -178,8 +160,6 @@ function guessArchitecture(compilerFilePath) { return "hcs12"; else if (baseName === "cx332") return "m68k"; - throw "Unable to deduce architecture for unsupported compiler: '" - + baseName + "'"; } function dumpMacros(compilerFilePath) { @@ -243,8 +223,6 @@ function guessEndianness(architecture) { || architecture === "m68k") { return "big"; } - throw "Unable to deduce endianness for unsupported architecture: '" - + architecture + "'"; } function dumpDefaultPaths(compilerFilePath, architecture) { diff --git a/share/qbs/modules/cpp/cosmic.qbs b/share/qbs/modules/cpp/cosmic.qbs index f1e8d2784..c1ed51859 100644 --- a/share/qbs/modules/cpp/cosmic.qbs +++ b/share/qbs/modules/cpp/cosmic.qbs @@ -104,6 +104,8 @@ CppModule { libraryPathFlag: "-l" linkerScriptFlag: "" + knownArchitectures: ["arm", "hcs12", "hcs8", "m68k", "stm8"] + Rule { id: assembler inputs: ["asm"] diff --git a/share/qbs/modules/cpp/cpp.js b/share/qbs/modules/cpp/cpp.js index da433f254..49ed678df 100644 --- a/share/qbs/modules/cpp/cpp.js +++ b/share/qbs/modules/cpp/cpp.js @@ -326,3 +326,16 @@ function collectMiscEscapableLinkerArguments(product) { return [].concat(ModUtils.moduleProperty(product, "platformLinkerFlags"), ModUtils.moduleProperty(product, "linkerFlags")); } + +function supportsArchitecture(architecture, knownArchitectures) { + for (var i = 0; i < knownArchitectures.length; ++i) { + if (architecture.startsWith("arm")) { + if (architecture.startsWith(knownArchitectures[i])) + return true; + } else { + if (architecture === knownArchitectures[i]) + return true; + } + } + return false; +} diff --git a/share/qbs/modules/cpp/iar.js b/share/qbs/modules/cpp/iar.js index 6da431766..434e57bc8 100644 --- a/share/qbs/modules/cpp/iar.js +++ b/share/qbs/modules/cpp/iar.js @@ -252,8 +252,6 @@ function compilerName(qbs) { return "iccstm8"; else if (architecture === "v850") return "iccv850"; - throw "Unable to deduce compiler name for unsupported architecture: '" - + architecture + "'"; } function assemblerName(qbs) { @@ -298,8 +296,6 @@ function assemblerName(qbs) { return "iasmstm8"; else if (architecture === "v850") return "av850"; - throw "Unable to deduce assembler name for unsupported architecture: '" - + architecture + "'"; } function linkerName(qbs) { @@ -308,8 +304,6 @@ function linkerName(qbs) { return "xlink"; else if (supportILinker(architecture)) return architecture.startsWith("arm") ? "ilinkarm" : ("ilink" + architecture); - throw "Unable to deduce linker name for unsupported architecture: '" - + architecture + "'"; } function archiverName(qbs) { @@ -318,47 +312,29 @@ function archiverName(qbs) { return "xar"; else if (supportIArchiver(architecture)) return "iarchive"; - throw "Unable to deduce archiver name for unsupported architecture: '" - + architecture + "'"; } function staticLibrarySuffix(qbs) { var architecture = qbs.architecture; var code = architectureCode(architecture); - if (code === undefined) { - throw "Unable to deduce static library suffix for unsupported architecture: '" - + architecture + "'"; - } return (code !== "") ? (".r" + code) : ".a"; } function executableSuffix(qbs) { var architecture = qbs.architecture; var code = architectureCode(architecture); - if (code === undefined) { - throw "Unable to deduce executable suffix for unsupported architecture: '" - + architecture + "'"; - } return (code !== "") ? ((qbs.debugInformation) ? (".d" + code) : (".a" + code)) : ".out"; } function objectSuffix(qbs) { var architecture = qbs.architecture; var code = architectureCode(architecture); - if (code === undefined) { - throw "Unable to deduce object file suffix for unsupported architecture: '" - + architecture + "'"; - } return (code !== "") ? (".r" + code) : ".o"; } function imageFormat(qbs) { var architecture = qbs.architecture; var code = architectureCode(architecture); - if (code === undefined) { - throw "Unable to deduce image format for unsupported architecture: '" - + architecture + "'"; - } return (code !== "") ? "ubrof" : "elf"; } @@ -368,8 +344,6 @@ function libraryPathFlag(qbs) { return "-L"; else if (supportXLinker((architecture))) return "-I"; - throw "Unable to deduce library path flag for unsupported architecture: '" - + architecture + "'"; } function linkerScriptFlag(qbs) { @@ -378,8 +352,6 @@ function linkerScriptFlag(qbs) { return "--config"; else if (supportXLinker((architecture))) return "-f"; - throw "Unable to deduce linker script flag for unsupported architecture: '" - + architecture + "'"; } function linkerSilentFlag(qbs) { @@ -388,8 +360,6 @@ function linkerSilentFlag(qbs) { return "--silent"; else if (supportXLinker(architecture)) return "-S"; - throw "Unable to deduce linker silent flag for unsupported architecture: '" - + architecture + "'"; } function linkerMapFileFlag(qbs) { @@ -398,8 +368,6 @@ function linkerMapFileFlag(qbs) { return "--map"; else if (supportXLinker(architecture)) return "-l"; - throw "Unable to deduce linker map flag for unsupported architecture: '" - + architecture + "'"; } function linkerEntryPointFlag(qbs) { @@ -408,8 +376,6 @@ function linkerEntryPointFlag(qbs) { return "--entry"; else if (supportXLinker(architecture)) return "-s"; - throw "Unable to deduce linker entry point flag for unsupported architecture: '" - + architecture + "'"; } function guessArmArchitecture(core) { @@ -540,8 +506,6 @@ function cppLanguageOption(compilerFilePath) { case "iccv850": return "--ec++"; } - throw "Unable to deduce C++ language option for unsupported compiler: '" - + FileInfo.toNativeSeparators(compilerFilePath) + "'"; } function dumpMacros(compilerFilePath, tag) { diff --git a/share/qbs/modules/cpp/iar.qbs b/share/qbs/modules/cpp/iar.qbs index 8209c3e57..092d1a092 100644 --- a/share/qbs/modules/cpp/iar.qbs +++ b/share/qbs/modules/cpp/iar.qbs @@ -103,6 +103,10 @@ CppModule { libraryPathFlag: IAR.libraryPathFlag(qbs) linkerScriptFlag: IAR.linkerScriptFlag(qbs) + knownArchitectures: ["78k", "arm", "avr", "avr32", "cr16", + "hcs12", "hcs8", "m16c", "m32c", "m68k", "mcs51", "msp430", + "r32c", "rh850", "riscv", "rl78", "rx", "sh", "stm8", "v850"] + Rule { id: assembler inputs: ["asm"] diff --git a/share/qbs/modules/cpp/keil.js b/share/qbs/modules/cpp/keil.js index b439019a2..9eb2098c1 100644 --- a/share/qbs/modules/cpp/keil.js +++ b/share/qbs/modules/cpp/keil.js @@ -87,8 +87,6 @@ function compilerName(qbs) { return "c166"; if (isArmArchitecture(architecture)) return "armcc"; - throw "Unable to deduce compiler name for unsupported architecture: '" - + architecture + "'"; } function assemblerName(qbs) { @@ -101,8 +99,6 @@ function assemblerName(qbs) { return "a166"; if (isArmArchitecture(architecture)) return "armasm"; - throw "Unable to deduce assembler name for unsupported architecture: '" - + architecture + "'"; } function linkerName(qbs) { @@ -115,8 +111,6 @@ function linkerName(qbs) { return "l166"; if (isArmArchitecture(architecture)) return "armlink"; - throw "Unable to deduce linker name for unsupported architecture: '" - + architecture + "'"; } function archiverName(qbs) { @@ -129,8 +123,6 @@ function archiverName(qbs) { return "lib166"; if (isArmArchitecture(architecture)) return "armar"; - throw "Unable to deduce archiver name for unsupported architecture: '" - + architecture + "'"; } function disassemblerName(qbs) { @@ -144,8 +136,6 @@ function staticLibrarySuffix(qbs) { || isArmArchitecture(architecture)) { return ".lib"; } - throw "Unable to deduce static library suffix for unsupported architecture: '" - + architecture + "'"; } function executableSuffix(qbs) { @@ -154,8 +144,6 @@ function executableSuffix(qbs) { return ".abs"; if (isArmArchitecture(architecture)) return ".axf"; - throw "Unable to deduce executable suffix for unsupported architecture: '" - + architecture + "'"; } function objectSuffix(qbs) { @@ -164,8 +152,6 @@ function objectSuffix(qbs) { return ".obj"; if (isArmArchitecture(architecture)) return ".o"; - throw "Unable to deduce object file suffix for unsupported architecture: '" - + architecture + "'"; } function linkerMapSuffix(qbs) { @@ -185,8 +171,6 @@ function imageFormat(qbs) { return "omf"; if (isArmArchitecture(architecture)) return "elf"; - throw "Unable to deduce image format for unsupported architecture: '" - + architecture + "'"; } function preincludeFlag(compilerPath) { diff --git a/share/qbs/modules/cpp/keil.qbs b/share/qbs/modules/cpp/keil.qbs index eeab4e9a0..7aab9ba3b 100644 --- a/share/qbs/modules/cpp/keil.qbs +++ b/share/qbs/modules/cpp/keil.qbs @@ -105,6 +105,8 @@ CppModule { libraryPathFlag: "--userlibpath=" linkerScriptFlag: "--scatter" + knownArchitectures: ["arm", "c166", "mcs251", "mcs51"] + Rule { id: assembler inputs: ["asm"] diff --git a/share/qbs/modules/cpp/sdcc.js b/share/qbs/modules/cpp/sdcc.js index c78cae23a..1c99b902c 100644 --- a/share/qbs/modules/cpp/sdcc.js +++ b/share/qbs/modules/cpp/sdcc.js @@ -54,8 +54,6 @@ function assemblerName(qbs) { case "hcs8": return "sdas6808"; } - throw "Unable to deduce assembler name for unsupported architecture: '" - + qbs.architecture + "'"; } function linkerName(qbs) { @@ -67,8 +65,6 @@ function linkerName(qbs) { case "hcs8": return "sdld6808"; } - throw "Unable to deduce linker name for unsupported architecture: '" - + qbs.architecture + "'"; } function archiverName(qbs) { diff --git a/share/qbs/modules/cpp/sdcc.qbs b/share/qbs/modules/cpp/sdcc.qbs index 45c039596..f2b182059 100644 --- a/share/qbs/modules/cpp/sdcc.qbs +++ b/share/qbs/modules/cpp/sdcc.qbs @@ -104,6 +104,8 @@ CppModule { libraryPathFlag: "-L" linkerScriptFlag: "-f" + knownArchitectures: ["hcs8", "mcs51", "stm8"] + Rule { id: assembler inputs: ["asm"] |