Skip to content
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.

Commit

Permalink
Build: Switch to exec()
Browse files Browse the repository at this point in the history
Change-Id: I0e2280bdc2047f0f1a752deaee6672bbe8114c9a
  • Loading branch information
Gabriel Schulhof committed Nov 7, 2016
1 parent a9e7e95 commit d0b8d75
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions build-scripts/build-csdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

var path = require( "path" );
var run = require( "child_process" ).execSync;
var run = require( "child_process" ).exec;
var fs = require( "fs" );
var repoPaths = require( "./helpers/repo-paths" );

Expand Down Expand Up @@ -52,6 +52,8 @@ var csdkRevision = process.env.CSDK_REVISION ||

var iotivityPath = path.join( repoPaths.root, "iotivity-native" );

var commands = [];

// We assume that, if the path is there, its contents are also ready to go
if ( fs.existsSync( iotivityPath ) ) {
return;
Expand All @@ -63,35 +65,49 @@ architecture =
archMap[ architecture[ 2 ] ] ? archMap[ architecture[ 2 ] ][ architecture[ 3 ] ] : null;

// Do a shallow checkout of iotivity
run( "git clone --depth 1 --single-branch --branch " + csdkRevision +
commands.push( [ "git clone --depth 1 --single-branch --branch " + csdkRevision +
" https://gerrit.iotivity.org/gerrit/iotivity \"" + iotivityPath + "\"",
{ stdio: "inherit" } );
{ stdio: "inherit" } ] );

// Apply patches
if ( fs.existsSync( patchesDirectory ) && fs.statSync( patchesDirectory ).isDirectory() ) {
fs.readdirSync( patchesDirectory ).forEach( function( item ) {
item = path.join( patchesDirectory, item );
run( "git apply \"" + item + "\"",
{ cwd: iotivityPath, stdio: "inherit" } );
commands.push( [ "git apply \"" + item + "\"",
{ cwd: iotivityPath, stdio: "inherit" } ] );
} );
}

// Clone tinycbor inside iotivity
run( "git clone https://github.com/01org/tinycbor.git extlibs/tinycbor/tinycbor",
{ cwd: iotivityPath, stdio: "inherit" } );
commands.push( [ "git clone https://github.com/01org/tinycbor.git extlibs/tinycbor/tinycbor",
{ cwd: iotivityPath, stdio: "inherit" } ] );

// Build
run( "scons " + []
commands.push( [ "scons " + []
.concat( architecture ? [ "TARGET_ARCH=" + architecture ] : [] )
.concat( process.env.npm_config_debug === "true" ?
[ "RELEASE=False" ] : [] )
.concat( [ "logger", "octbstack", "connectivity_abstraction", "coap", "c_common", "ocsrm",
"routingmanager"
] )
.join( " " ),
{ cwd: iotivityPath, stdio: "inherit" } );

// Move the binaries from iotivity-native/out/<os>/<arch>/<buildtype> to a hardcoded path. This is
// a necessary step because the binding.gyp file is being evaluated before the path
// iotivity-native/out/<os>/<arch>/<buildtype> is created, so it cannot be found at that time.
fs.renameSync( findBins( iotivityPath ), path.join( iotivityPath, "binaries" ) );
{ cwd: iotivityPath, stdio: "inherit" } ] );

// Actually run the commands
( function runCommand( index ) {
run.apply( null, [].concat( commands[ index ] ).concat( [ function( error ) {
if ( error ) {
throw error;
} else if ( ++index < commands.length ) {
runCommand( index );
} else {

// The last step is to move the binaries from
// iotivity-native/out/<os>/<arch>/<buildtype> to a hardcoded path. This is a necessary
// step because the binding.gyp file is being evaluated before the path
// iotivity-native/out/<os>/<arch>/<buildtype> is created, so it cannot be found at
// that time.
fs.renameSync( findBins( iotivityPath ), path.join( iotivityPath, "binaries" ) );
}
} ] ) );
} )( 0 );

0 comments on commit d0b8d75

Please sign in to comment.