Skip to content

Instantly share code, notes, and snippets.

@ChugunovRoman
Last active June 27, 2018 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChugunovRoman/103592691f6ecb1a913a10b0314d0997 to your computer and use it in GitHub Desktop.
Save ChugunovRoman/103592691f6ecb1a913a10b0314d0997 to your computer and use it in GitHub Desktop.
Gulp for make a C++ app (In develop still)
const fs = require('fs');
const path = require('path');
const cp = require('child_process');
const gulp = require('gulp'),
watch = require('gulp-watch');
if (process.env.PROJECT == "") {
console.error(`You need specified the PROJECT=<project_folder> env. This variable indicates to project dir, which need to build.`);
return;
}
const QTBIN = `/home/ruut/Qt5.9.6/5.9.6/gcc_64/bin`;
const QTLIB = `/home/ruut/Qt5.9.6/5.9.6/gcc_64/lib`;
// const CXX = 'g++';
// const DEFINES = `-DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_XML_LIB -DQT_CORE_LIB`;
// const CXXFLAGS = `-c -pipe -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC ${DEFINES}`;
// const INCPATH = `-I../call_assistance -I. -I/home/ruut/Qt5.9.6/5.9.6/gcc_64/include -I/home/ruut/Qt5.9.6/5.9.6/gcc_64/include/QtGui -I/home/ruut/Qt5.9.6/5.9.6/gcc_64/include/QtNetwork -I/home/ruut/Qt5.9.6/5.9.6/gcc_64/include/QtXml -I/home/ruut/Qt5.9.6/5.9.6/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I/home/ruut/Qt5.9.6/5.9.6/gcc_64/mkspecs/linux-g++`;
// const QMAKE = `${process.env.HOME}/Qt5.9.6/5.9.6/gcc_64/bin/qmake`;
// const QOBJCMD = `${CXX} ${CXXFLAGS} ${INCPATH}`;
const INCLUDEPATH = `${process.env.HOME}/Qt5.9.6/5.9.6/gcc_64/include ${process.env.HOME}/Qt5.9.6/5.9.6/gcc_64/include/QtGui ${process.env.HOME}/Qt5.9.6/5.9.6/gcc_64/include/QtNetwork ${process.env.HOME}/Qt5.9.6/5.9.6/gcc_64/include/QtXml ${process.env.HOME}/Qt5.9.6/5.9.6/gcc_64/include/QtCore`
const LIBS = `-L${QTLIB}`;
const LFLAGS = `-Wl,-rpath,${QTLIB}`;
const OUT = 'build';
const PROJECT = process.env.PROJECT;
const DEPLOYCMD = `linuxdeployqt ${PROJECT}/release/${PROJECT}`;
let cpp = [], h = [];
cp.exec(`mkdir -p ${PROJECT}/${OUT}`);
const build = () => new Promise((reslove, reject) => {
const CMD = `cd ${PROJECT}/${OUT} && qmake ../${PROJECT}.pro -spec linux-g++ CONFIG+='release c++11' LIBS+='${LFLAGS} ${LIBS}' INCLUDEPATH+='${INCLUDEPATH}'`;
cp.exec(CMD, (err, stdout, stderr) => {
console.log(`${stdout}, ${err}, ${stderr}`);
if (err) {
console.log(`\nERROR: ${err}\n`);
reject(err);
}
cp.exec(`cd ${PROJECT}/${OUT} && make && make install`, (err, stdout, stderr) => {
if (err) {
console.log(`\nERROR: ${err}\n`);
reject(err);
}
console.log(`${stdout}, ${err}, ${stderr}`);
fs.exists(`${PROJECT}/settings.ini`, isExists => {
isExists ?
cp.exec(`cp ${PROJECT}/settings.ini ${PROJECT}/${OUT}/settings.ini`, (err, stdout, stderr) => {
if (err) {
console.log(`Copy the settings.ini is failed: `, err);
}
console.log(`${stdout}, ${err}, ${stderr}`);
}) : 0;
});
reslove();
});
});
});
const exec = cmd => new Promise((resolve, reject) => {
cp.exec(cmd, (err, stdout, stderr) => {
console.log(`${stdout}, ${err}, ${stderr}`);
if (err) {
console.log(`\nERROR: ${err}\n`);
reject(err);
}
resolve();
});
});
gulp.task('build', () => {
build().then(() => {
console.log('The build task complete successful!');
}).catch((err) => {
console.log('The build task complete error: ', err);
});
/**
* Вручную собирать промежуточный байт-код
* Оставлю на всякий.
*/
// fs.readdir(PROJECT, (err, files) => {
// files.forEach(f => {
// if (path.extname(f) === '.cpp') {
// cp.exec(`${QOBJCMD} ${PROJECT}/${f} -o ${PROJECT}/${OUT}/${path.basename(f, '.cpp')}.o`, (err, stdout, stderr) => {
// console.log(`${stdout}, ${err}, ${stderr}`);
// });
// }
// });
// });
});
gulp.task('run', async () => {
await build();
const run = cp.exec(`./${PROJECT}/${OUT}/${PROJECT}`);
run.stdout.on('data', (data) => {
console.log(`${data}`);
});
run.stderr.on('data', (data) => {
console.log(`Error msg: ${data}`);
});
run.on('close', (data) => {
console.log(`closing code: ${data}`);
});
});
gulp.task('clear', async () => {
await exec(`rm -rf ./${PROJECT}/${OUT}/*`);
});
gulp.task('deploy', async () => {
await exec(`rm -rf ${PROJECT}/release`);
await exec(`mkdir -p ${PROJECT}/release`);
await exec(`cp ${PROJECT}/${OUT}/${PROJECT} ${PROJECT}/release`);
await exec(`PATH=${QTBIN}:$PATH ${DEPLOYCMD}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment