How can I override compile flags (as in CFLAGS) for a single package in NixOS/Nix environments?
Here's what I've got by now:
let
optimizeForThisHost = pkg:
pkgs.lib.overrideDerivation pkg (old: {
exportOptimizations = ''
export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -fPIC -O3 -march=native"
'';
phaseNames = ["exportOptimizations"] ++ old.phaseNames;
});
in
muttWithoutThings = pkgs: (pkgs.mutt.override {
sslSupport = false;
saslSupport = false;
imapSupport = false;
withSidebar = false;
};
});
mutt = pkgs:
(optimizeForThisHost (muttWithoutThings pkgs));
in my configuration.nix, though this fails with
error: attribute ‘phaseNames’ missing
Here is a working example that builds (and runs) a copy of GNU hello with custom compiler flags:
nix-shell -p 'hello.overrideDerivation (old: { NIX_CFLAGS_COMPILE = "-Ofoo"; })' --run "hello --version"
If you want to convince yourself whether this really works, try passing a non-existent flag to the compiler, like -Ofoo, and verify that the builds fails as expected.
More information about the overrideDerivation function (and similar alternatives) can found in the Nixpkgs manual at http://nixos.org/nixpkgs/manual/index.html#sec-pkg-overrideDerivation.
I managed to write a function which I can apply to the packages I want to compile with custom flags:
optimizeWithFlags = pkg: flags:
pkgs.lib.overrideDerivation pkg (old:
let
newflags = pkgs.lib.foldl' (acc: x: "${acc} ${x}") "" flags;
oldflags = if (pkgs.lib.hasAttr "NIX_CFLAGS_COMPILE" old)
then "${old.NIX_CFLAGS_COMPILE}"
else "";
in
{
NIX_CFLAGS_COMPILE = "${oldflags} ${newflags}";
});
This function takes a package and a list of strings (which are the flags) and builds a new package with the existing one, but with the additional compiler flags.
For convenience, I wrote another set of helper functions:
optimizeForThisHost = pkg:
optimizeWithFlags pkg [ "-O3" "-march=native" "-fPIC" ];
withDebuggingCompiled = pkg:
optimizeWithFlags pkg [ "-DDEBUG" ];
Now, I can override packages (here mutt and dmenu):
muttWithoutThings = pkgs: (pkgs.mutt.override {
sslSupport = false;
saslSupport = false;
imapSupport = false;
withSidebar = false;
});
mutt = pkgs:
(utils pkgs).withoutConfigureFlag "--enable-debug"
((utils pkgs).optimizeForThisHost (muttWithoutThings pkgs)
);
dmenu = pkgs:
(utils pkgs).optimizeForThisHost
(pkgs.dmenu.override {
patches = [ ./patches/dmenu-fuzzymatch-4.6.diff ];
});
In the above utils is utils = pkgs: import ./util.nix { pkgs = pkgs; }; and the util.nix file returns a function which spits out a set of functions.
Related
function abc(){
var Site = require('dw/system/Site');
var utils= require('app_nars/cartridge/scripts/util/utils.js');
var mySite : String = (Site.getCurrent().getID() == "a") ? "" : "-" + Site.getCurrent().getID();
var customerGroupName : String ;
if (mySite == "A") {
customerGroupName = "A";
} else {
customerGroupName = "B";
}
var grpNam= utils.getGroup(customerGroupName);
var grpFileName = 'test';
/* No script api available for pipelet ExportCustomerGroups*/
var Pipelet = require('dw/system/Pipelet');
var PipeletExecutionResponse = new dw.system.Pipelet('ExportCustomerGroups').execute({
CustomerGroups: grpNam.iterator(),
ExportFile : grpFileName,
OverwriteExportFile:true
});
app.getView().render('path/templateName');
}
How can we replace the Pipelet ExportCustomerGroups here , i could see in documentation we can use job steps and there is no script replacement
You have to create with your own code, construct the xml needed while parsing the customers.[enter image description here][1]
Or you can use this step when configuring job if no custom code needed there:
[1]: https://i.stack.imgur.com/s1VQa.png
Below code is working fine for HTML module but not working for HTML PRO module.
HtmlTextController htmlTextController = new HtmlTextController();
WorkflowStateController workflowStateController = new WorkflowStateController();
int workflowId = htmlTextController.GetWorkflow(ModuleId, TabId, PortalId).Value;
List<HtmlTextInfo> htmlContents = htmlTextController.GetAllHtmlText(ModuleModId);
htmlContents = htmlContents.OrderBy(c => c.Version).ToList();
foreach (var content in htmlContents)
{
HtmlTextInfo htmlContent = new HtmlTextInfo();
htmlContent.ItemID = -1;
htmlContent.StateID = workflowStateController.GetFirstWorkflowStateID(workflowId);
htmlContent.WorkflowID = workflowId;
htmlContent.ModuleID = ModuleId;
htmlContent.IsPublished = content.IsPublished;
htmlContent.Approved = content.Approved;
htmlContent.IsActive = content.IsActive;
htmlContent.Content = content.Content;
htmlContent.Summary = content.Summary;
htmlContent.Version = content.Version;
}
htmlTextController.UpdateHtmlText(htmlContent, htmlTextController.GetMaximumVersionHistory(PortalId));
This is occurred due to HTML Pro module has different methods. That is partially different from DNN HTML Module. below is the code.
HtmlTextController htmlTextController = new HtmlTextController();
WorkflowStateController workflowStateController = new WorkflowStateController();
WorkflowStateInfo wsinfo = new WorkflowStateInfo();
int workflowId = wsinfo.WorkflowID;
HtmlTextInfo htmlContents = htmlTextController.GetLatestHTMLContent(ModuleModId);
HtmlTextInfo htmlContent = new HtmlTextInfo();
htmlContent.ItemID = -1;
htmlContent.StateID = workflowStateController.GetFirstWorkflowStateID(workflowId);
htmlContent.WorkflowID = workflowId;
htmlContent.ModuleID = ModuleId;
htmlContent.IsPublished = htmlContents.IsPublished;
htmlContent.Approved = htmlContents.Approved;
htmlContent.IsActive = htmlContents.IsActive;
htmlContent.Content = htmlContents.Content;
htmlContent.Summary = htmlContents.Summary;
htmlContent.Version = htmlContents.Version;
if (Tags != null && Tags.Count > 0)
{
foreach (KeyValuePair<string, string> tag in Tags)
{
if (htmlContent.Content.Contains(tag.Key))
{
htmlContent.Content = htmlContent.Content.Replace(tag.Key, tag.Value);
}
}
}
htmlTextController.SaveHtmlContent(htmlContent, newModule);
And please add below reference to the code to refer the methods.
using DotNetNuke.Modules.HtmlPro;
using DotNetNuke.Professional.HtmlPro;
using DotNetNuke.Professional.HtmlPro.Components;
using DotNetNuke.Professional.HtmlPro.Services;
If you are looking to simply "copy" the content from one to the other, you might investigate the usage of the "Import" and "Export" functions that are part of these modules.
I recommend using this route to help you ensure better compatibility as time progresses. Should they update fields or other data elements you will not have to investigate and then update your code as part of this.
You can simply look at the .dnn manifest for each of these modules and find the BusinessControllerClass which will have two methods "ImportModule" and "ExportModule" that you could use.
Using the node-mssql library to pull data from SQL. I've been using Sinon for a while now (written about 200 tests with it); having a ton of trouble getting my head around how to stub this library out. The code looks like:
var sql = require('mssql');
var conn = new sql.Connection(sqlConfig); // sqlConfig is connection info, defined elsewhere
conn.connect(function(err) {
var req, selectFromTable;
if (err != null) {
// handle error
}
req = new sql.Request(conn);
selectFromTable = "select * from DW." + table + " where DWCreatedDate >= '" + start + "' and DWCreatedDate <= '" + end + "' ";
logger.debug("Selecting with: ", selectFromTable);
req.input('statement', sql.NVarChar, selectFromTable);
return req.execute('sp_executesql', function(err, results, returnValue, affected) {
if (err != null) {
// etc.
} else {
// data processing
}
});
});
Code works fine. Now I'm trying to write a test for it. I knew this library would be difficult to test so I procrastinated. My closest code:
var conn, reqExecute, sqlReqStub;
sqlReqStub = sinon.stub();
sqlReqStub.execute = sinon.stub();
sinon.stub(sql, 'Request').returns(sqlReqStub);
conn = sinon.stub();
sinon.stub(sql, 'Connection').returns(conn);
conn.connect = sinon.stub().callsArgWith(0, null);
reqExecute = sqlReqStub.execute.withArgs('sp_executesql').onFirstCall().callsArgWith(1, null, {
a: 1
});
Your natural inclination might be to say "well, use createStubInstance" but when I use that I get back connection objects (new sql.Connection(config)) that have TediousRequest (what the library defaults to when it builds out the driver object inside of the connection) in them instead of my stub request. I can't find TediousRequest anywhere in the sql object to stub it out.
I'm stuck here; hoping someone has some code around that does this or can explain what I'm doing wrong.
Well, I did manage to solve it but it feels a little hacky for some reason. Possibly because I never figured out how to stub the new sql.Request(conn) call.
Ideally I'd like to get this working without having to include the sql library in my module.exports. I can do that with the request library but after a few hours knocking away at this library I'm unable to get it working in the same way.
First: export the sql library:
sql = require('mssql')
// much code
module.exports.sqlLib = sql
Second: stub things:
var connection, sqlReqStub, sqlStubLib;
var server = require('./index.js')
sqlStubLib = {};
connection = new EventEmitter();
connection.connected = true;
connection.close = function() {};
connection.connect = sinon.stub().callsArgWith(0, null);
sqlStubLib.Connect = sinon.stub();
sqlStubLib.Connection = function() {
return connection;
};
sqlReqStub = sinon.stub();
sqlReqStub.input = function() {};
sqlReqStub.execute = sinon.stub();
sqlReqStub.execute.withArgs('sp_executesql').onFirstCall().callsArgWith(1, null, [
[
// js object
]
], null, null);
sqlStubLib.Request = function() {
return sqlReqStub;
};
server.sqlLib = sqlStubLib;
I'm attempting to convert an existing project into a cocoapod so that it will be easier to use however when I run
pod spec lint --verbose
I get a number of errors similar to
- ERROR | [iOS] xcodebuild: CoreDataServices/CoreDataServices/Services/Count/CDSCountService.m:28:9: error: use of undeclared identifier 'NSFetchRequest'
I have the following as my podspec:
Pod::Spec.new do |s|
s.name = "CoreDataServices"
s.version = "0.2.0"
s.summary = "CoreDataServices contains a set of helper classes to abstract away common core data functionality."
s.homepage = "http://www.williamboles.me"
s.license = { :type => 'MIT',
:file => 'LICENSE.md' }
s.author = "William Boles"
s.platform = :ios, "8.0"
s.source = { :git => "https://github.com/wibosco/CoreDataServices.git",
:branch => "master",
:tag => s.version }
s.source_files = "CoreDataServices/**/*.{h,m}"
s.public_header_files = "CoreDataServices/**/*.{h}"
s.frameworks = 'UIKit', 'CoreData'
s.requires_arc = true
end
I have cocoapod version 0.39.0 installed.
Building the project using xcodebuild outside of cocoapods results in the project being built without errors.
I managed to get there in the end but it's an odd one:
Pod::Spec.new do |s|
s.name = "CoreDataServices"
s.version = "0.2.0"
s.summary = "CoreDataServices contains a set of helper classes to abstract away common core data functionality."
s.homepage = "http://www.williamboles.me"
s.license = { :type => 'MIT',
:file => 'LICENSE.md' }
s.author = "William Boles"
s.platform = :ios, "8.0"
s.source = { :git => "https://github.com/wibosco/CoreDataServices.git",
:branch => "master",
:tag => s.version }
s.source_files = "CoreDataServices/**/*.{h,m}"
s.public_header_files = "CoreDataServices/**/*.{h}"
s.requires_arc = true
s.frameworks = 'UIKit', 'CoreData'
end
I moved s.requires_arc = true to be above s.framework = 'UIKit', 'CoreData' and the errors went away.
I also noticed that if I inverted the ordering of the framesworks so that it becomes
s.frameworks = 'CoreData', 'UIKit'
s.requires_arc = true
that also worked
Since font awesome 4.3, they added the fonts as woff2 format.
I'm guetting 404ed when trying to serve this file through owin :
app.UseFileServer(new FileServerOptions() {
RequestPath = PathString.Empty,
FileSystem = new PhysicalFileSystem(#"banana")
});
How do I serve woff2 mime type files through file server in owin ?
Two possibilities :
Serve all kind of file types :
var options = new FileServerOptions() {
RequestPath = PathString.Empty,
FileSystem = new PhysicalFileSystem(#"banana")
};
options.StaticFileOptions.ServeUnknownFileTypes = true;
app.UseFileServer(options);
Add woff2 mime type :
var options = new FileServerOptions() {
RequestPath = PathString.Empty,
FileSystem = new PhysicalFileSystem(#"banana")
};
((FileExtensionContentTypeProvider)options.StaticFileOptions.ContentTypeProvider)
.Mappings.Add(".woff2", "application/font-woff2");
app.UseFileServer(options);
Second options seems not as elegant but is nonetheless the best. Read why mime types are important.
You can avoid the not-very-nice casting by using inheritance:
FileServerOptions options = new FileServerOptions
{
StaticFileOptions =
{
ContentTypeProvider = new CustomFileExtensionContentTypeProvider(),
}
};
where
private class CustomFileExtensionContentTypeProvider : FileExtensionContentTypeProvider
{
public CustomFileExtensionContentTypeProvider()
{
Mappings.Add(".json", "application/json");
Mappings.Add(".mustache", "text/template");
}
}