-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration handling from environment variables (#84)
Adds environment variable handling for common configuration variables. Based on #83.
- Loading branch information
1 parent
970aca4
commit 07fbafa
Showing
6 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//===- EnvVarConfig.h - EnvVar Configuration builder ----------*- C++-*----===// | ||
// | ||
// (C) Copyright IBM 2023. | ||
// | ||
// Any modifications or derivative works of this code must retain this | ||
// copyright notice, and modified files need to carry a notice indicating | ||
// that they have been altered from the originals. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// Populate the configuration from environment variables. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef QSSC_ENVVARCONFIG_H | ||
#define QSSC_ENVVARCONFIG_H | ||
|
||
#include "Config/QSSConfig.h" | ||
|
||
namespace qssc::config { | ||
|
||
/// @brief Populate arguments of the QSSConfig | ||
/// from environment variables. | ||
/// | ||
/// | ||
/// The qss-compiler makes several several QSSConfig configuration | ||
/// options configurable from environment variables through the | ||
/// EnvVarConfigBuilder. | ||
/// | ||
/// These currently are: | ||
/// - `QSSC_TARGET_NAME`: Sets QSSConfig::targetName. | ||
/// - `QSSC_TARGET_CONFIG_PATH`: Sets QSSConfig::targetConfigPath. | ||
/// | ||
class EnvVarConfigBuilder : public QSSConfigBuilder { | ||
public: | ||
llvm::Error populateConfig(QSSConfig &config) override; | ||
|
||
private: | ||
llvm::Error populateConfigurationPath_(QSSConfig &config); | ||
llvm::Error populateTarget_(QSSConfig &config); | ||
}; | ||
|
||
} // namespace qssc::config | ||
#endif // QSS_ENVVARCONFIG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//===- EnvVarConfigBuilder.cpp - QSSConfig from EnvVars ----* C++*--------===// | ||
// | ||
// (C) Copyright IBM 2023. | ||
// | ||
// Any modifications or derivative works of this code must retain this | ||
// copyright notice, and modified files need to carry a notice indicating | ||
// that they have been altered from the originals. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file implements building the configuration from environemnt variables. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "Config/EnvVarConfig.h" | ||
|
||
#include <cstdlib> | ||
|
||
using namespace qssc::config; | ||
|
||
llvm::Error EnvVarConfigBuilder::populateConfig(QSSConfig &config) { | ||
if (auto err = populateConfigurationPath_(config)) | ||
return err; | ||
|
||
if (auto err = populateTarget_(config)) | ||
return err; | ||
|
||
return llvm::Error::success(); | ||
} | ||
|
||
llvm::Error EnvVarConfigBuilder::populateConfigurationPath_(QSSConfig &config) { | ||
if (const char *configurationPath = std::getenv("QSSC_TARGET_CONFIG_PATH")) | ||
config.targetConfigPath = configurationPath; | ||
return llvm::Error::success(); | ||
} | ||
|
||
llvm::Error EnvVarConfigBuilder::populateTarget_(QSSConfig &config) { | ||
if (const char *targetStr = std::getenv("QSSC_TARGET_NAME")) | ||
config.targetName = targetStr; | ||
return llvm::Error::success(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
// RUN: qss-compiler --target Mock --config path/to/config --allow-unregistered-dialect=false --add-target-passes=false --show-config | FileCheck %s --check-prefix CLI | ||
// RUN: QSSC_TARGET_NAME="MockEnv" QSSC_TARGET_CONFIG_PATH="path/to/config/Env" qss-compiler --allow-unregistered-dialect=false --add-target-passes=false --show-config | FileCheck %s --check-prefix ENV | ||
|
||
// CLI: targetName: Mock | ||
// CLI: targetConfigPath: path/to/config | ||
// CLI: allowUnregisteredDialects: 0 | ||
// CLI: addTargetPasses: 0 | ||
|
||
// ENV: targetName: MockEnv | ||
// ENV: targetConfigPath: path/to/config/Env | ||
// ENV: allowUnregisteredDialects: 0 | ||
// ENV: addTargetPasses: 0 |