Skip to content

Commit b3c69c0

Browse files
authored
Merge pull request #2 from emarteca/remove-usability-improvements
Remove usability improvements
2 parents ddcf336 + e5d1b7b commit b3c69c0

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@ cd ../..
106106
./transform.sh Playground/serve-static "static"
107107
```
108108

109+
#### Remove Functions in `serve-static`
110+
111+
Stubbifier also supports a `--removeFuns <>` option, allowing users to specify a set of functions that should be totally removed from an application.
112+
The format of the file should match the format of the static callgraph; thus, we illustrate this functionality with `serve-static` using the static CG:
113+
114+
```
115+
./resetProject.sh Playground/serve-static
116+
117+
# If you haven't already: ./genStaticCG.sh Playground/serve-static serve-static
118+
119+
#
120+
./remove.sh Playground/serve-static "static"
121+
```
122+
123+
This should (1) remove all functions detected with the static call graph, and stub the rest.
124+
If you look at, e.g., index.js (`vim Playground/serve-static/index.js`), you should see a mix of removed functions and stubbed functions.
125+
109126
### Integration with bundlers
110127
We also support integration with `rollup`, a popular JavaScript bundler.
111128
`bundler_mode` is another mode of `stubbifier` execution, with options:

functionLevelStubs.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ function processAST(ast: babel.Program,
9494
)]);
9595
}
9696
} else if ((bundlerMode && shouldTransformBundlerMode(path.node)) || (shouldTransformFunction(functionUIDName, reachableFuns, uncoveredMode, path.node))) {
97-
// console.log("Triggered stubbification.");
9897
if (path.node.kind == "constructor" || path.node.generator || path.node.async) { // TODO broken for generators -- is this true?
9998
path.skip(); // don't transform a constructor or anything in a constructor (stubs dont work with "super" and "this")
10099
} else {

remove.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# finds the absolute path from relative path
4+
# called realpath bc thats the utility on linux
5+
# https://stackoverflow.com/questions/3572030/bash-script-absolute-path-with-os-x
6+
realpathMACHACK() {
7+
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
8+
}
9+
10+
transformType=$2
11+
projDir=$1
12+
guardedMode="true"
13+
bundlerMode="no"
14+
15+
if [ "$#" -ge 3 ]; then
16+
guardedMode=$3
17+
fi
18+
19+
if [ "$#" -ge 4 ]; then
20+
bundlerMode=$4
21+
fi
22+
23+
if [[ "$transformType" == "dynamic" ]]; then
24+
node stubbifyRunner.js --transform $projDir --removeFuns `realpathMACHACK $projDir/coverage/coverage-final.json` --dependencies $projDir/dep_list.txt --guarded_exec_mode $guardedMode --bundler_mode $bundlerMode
25+
elif [[ "$transformType" == "static" ]]; then
26+
node stubbifyRunner.js --transform $projDir --callgraph `realpathMACHACK $projDir/static_callgraph.csv` --removeFuns `realpathMACHACK $projDir/static_callgraph.csv` --dependencies $projDir/dep_list.txt --guarded_exec_mode $guardedMode --bundler_mode $bundlerMode
27+
else
28+
echo "Error: transform_type must be either \"dynamic\" or \"static\""
29+
echo "Usage: ./transform.sh proj_dir ( \"dynamic\" | \"static\" )"
30+
fi

stubbifyRunner.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { fileStubFile} from './fileLevelStubs.js'
66
import {getTargetsFromACG, getTargetsFromCoverageReport, buildHappyName, buildEvalCheck, getFileName, generateBundlerConfig} from './ACGParseUtils.js';
77
import {argv} from 'yargs';
88
import { execSync } from "child_process";
9+
import { debugPort } from "process";
910

1011
const getAllFiles = function( dirname, recurse = false, listOfFiles = []) {
1112
let baseListOfFiles = fs.readdirSync( dirname);
@@ -79,6 +80,7 @@ let removeFuns : string[] = [];
7980
let noCG : boolean = true;
8081
let uncoveredMode: boolean = !(argv.uncovered == undefined);
8182
let depList: string[];
83+
8284
if ( callgraphpath) {
8385
let targets: string[] = getTargetsFromACG(callgraphpath);
8486
functions = targets.map(buildHappyName);
@@ -88,7 +90,10 @@ if ( callgraphpath) {
8890
let zipFiles = false; // Currently don't ever do this.
8991

9092
if (removeFunsPath) {
91-
removeFuns = getTargetsFromACG(removeFunsPath).map(buildHappyName);
93+
const targetsForRemoval = getTargetsFromACG(removeFunsPath);
94+
listedFiles = listedFiles.concat(targetsForRemoval.map(getFileName));
95+
removeFuns = targetsForRemoval.map(buildHappyName);
96+
noCG = false;
9297
}
9398

9499
if ( uncoveredMode) {
@@ -101,9 +106,6 @@ if ( uncoveredMode) {
101106
listedFiles.push(element);
102107
});
103108
noCG = false;
104-
105-
console.log(listedFiles);
106-
console.log(functions);
107109
}
108110

109111
if ( argv.dependencies) {
@@ -175,8 +177,8 @@ if (bundlerMode != "no") {
175177
files.forEach(function(file, index) {
176178
// console.log(file);
177179
// only stubify JS files
178-
let curPath: string = filename + file;
179-
curPath = file;
180+
// let curPath: string = filename + file;
181+
const curPath = file;
180182
// console.log("decision: " + shouldStubbify(curPath, file, depList));
181183
// let curAbsPath: string = process.cwd() + curPath;
182184
if( shouldStubbify( curPath, file, depList)) { // don't even try to stub externs

0 commit comments

Comments
 (0)