Skip to content

Commit 3885f56

Browse files
committed
cleanup
1 parent fd0579a commit 3885f56

File tree

4 files changed

+11
-75
lines changed

4 files changed

+11
-75
lines changed

app/src/main/java/com/duy/ccppcompiler/compiler/compilers/CompilerFactory.java

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public static ICompiler getCompilerForFile(Context context, File[] sourceFiles)
5050

5151
switch (compilerType) {
5252
case G_PLUS_PLUS:
53-
return new GPlusPlusCompiler(context, false, false, new CompileSetting(context));
53+
return new GPlusPlusCompiler(context, false, new CompileSetting(context));
5454

5555
case GCC:
56-
return new GCCCompiler(context, false, false, new CompileSetting(context));
56+
return new GCCCompiler(context, false, new CompileSetting(context));
5757

5858
case MAKE:
5959
return new MakeCompiler(context);
@@ -83,43 +83,10 @@ public static ICompiler getNativeActivityCompilerForFile(Context context, File[]
8383

8484
switch (compilerType) {
8585
case G_PLUS_PLUS:
86-
return new GPlusPlusCompiler(context, true, false, new CompileSetting(context));
86+
return new GPlusPlusCompiler(context, true, new CompileSetting(context));
8787

8888
case GCC:
89-
return new GCCCompiler(context, true, false, new CompileSetting(context));
90-
91-
case MAKE:
92-
return new MakeCompiler(context);
93-
94-
default:
95-
return null;
96-
}
97-
}
98-
99-
@Nullable
100-
public static ICompiler getSDLActivityCompilerForFile(Context context, File[] sourceFiles) {
101-
File file = sourceFiles[0];
102-
String filePath = file.getAbsolutePath();
103-
String fileName = file.getName();
104-
105-
CompileType compilerType = CompileType.NONE;
106-
if (Catalog.getModeByName("C++").acceptFile(filePath, fileName)) {
107-
compilerType = CompileType.G_PLUS_PLUS;
108-
109-
} else if (Catalog.getModeByName("C").acceptFile(filePath, fileName)) {
110-
compilerType = CompileType.GCC;
111-
} else if (Catalog.getModeByName("Makefile").acceptFile(filePath, fileName)) {
112-
113-
compilerType = CompileType.MAKE;
114-
}
115-
116-
117-
switch (compilerType) {
118-
case G_PLUS_PLUS:
119-
return new GPlusPlusCompiler(context, false, true, new CompileSetting(context));
120-
121-
case GCC:
122-
return new GCCCompiler(context, false, true, new CompileSetting(context));
89+
return new GCCCompiler(context, true, new CompileSetting(context));
12390

12491
case MAKE:
12592
return new MakeCompiler(context);

app/src/main/java/com/duy/ccppcompiler/compiler/compilers/GCCCompiler.java

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
import android.support.annotation.Nullable;
2121

2222
import com.duy.ccppcompiler.compiler.ICompileSetting;
23-
import com.duy.ccppcompiler.compiler.shell.CommandBuilder;
24-
import com.duy.ccppcompiler.compiler.shell.CommandResult;
2523
import com.duy.ccppcompiler.compiler.result.CompileResult;
2624
import com.duy.ccppcompiler.compiler.result.NativeActivityCompileResult;
27-
import com.duy.ccppcompiler.compiler.result.SDLCompileResult;
25+
import com.duy.ccppcompiler.compiler.shell.CommandBuilder;
26+
import com.duy.ccppcompiler.compiler.shell.CommandResult;
2827
import com.duy.ccppcompiler.packagemanager.Environment;
2928
import com.duy.common.DLog;
3029

@@ -41,14 +40,12 @@ public class GCCCompiler extends CompilerImpl {
4140
protected final ICompileSetting mSetting;
4241

4342
protected final boolean mBuildNativeActivity;
44-
protected final boolean mBuildSDL;
4543

4644
File mOutFile;
4745

48-
public GCCCompiler(Context context, boolean nativeActivity, boolean buildSDL, @Nullable ICompileSetting setting) {
46+
public GCCCompiler(Context context, boolean nativeActivity, @Nullable ICompileSetting setting) {
4947
super(context);
5048
mBuildNativeActivity = nativeActivity;
51-
mBuildSDL = buildSDL;
5249
mSetting = setting;
5350
}
5451

@@ -59,8 +56,6 @@ public CompileResult compile(File[] sourceFiles) {
5956
CompileResult result;
6057
if (mBuildNativeActivity) {
6158
result = new NativeActivityCompileResult(shellResult);
62-
} else if (mBuildSDL) {
63-
result = new SDLCompileResult(shellResult);
6459
} else {
6560
result = new CompileResult(shellResult);
6661
}
@@ -85,8 +80,6 @@ protected String buildArgs(File[] sourceFiles) {
8580

8681
if (mBuildNativeActivity) {
8782
args.addFlags(buildNativeActivityFlags(sourceFiles));
88-
} else if (mBuildSDL) {
89-
args.addFlags(buildSDLActivityFlags(sourceFiles));
9083
} else {
9184
args.addFlags(buildExecutableFlags(sourceFiles));
9285
}
@@ -99,28 +92,6 @@ protected String buildArgs(File[] sourceFiles) {
9992
return args.build();
10093
}
10194

102-
protected ArrayList<String> buildSDLActivityFlags(File[] sourceFiles) {
103-
File source = sourceFiles[0];
104-
String nameNoExt = source.getName().substring(0, source.getName().lastIndexOf("."));
105-
106-
if (DLog.DEBUG) DLog.d(TAG, "buildArgs: build native activity");
107-
String soName = "lib" + nameNoExt + ".so";
108-
mOutFile = new File(source.getParent(), soName);
109-
String cctools = Environment.getCCtoolsDir(mContext);
110-
CommandBuilder flags = new CommandBuilder();
111-
112-
//default flags
113-
flags.addFlags("-DANDROID")
114-
.addFlags("-I" + new File(Environment.getSdCardHomeDir(), "SDL/include").getAbsolutePath())
115-
//ld flags
116-
.addFlags("-shared")
117-
.addFlags(new File(Environment.getSdCardHomeDir(), "SDL/lib/SDL_android_main.o").getAbsolutePath())
118-
.addFlags("-I" + new File(Environment.getSdCardHomeDir(), "SDL/lib").getAbsolutePath())
119-
.addFlags("-o", mOutFile.getAbsolutePath());
120-
121-
return flags.toList();
122-
}
123-
12495
protected ArrayList<String> buildExecutableFlags(File[] sourceFiles) {
12596
File source = sourceFiles[0];
12697
String nameNoExt = source.getName().substring(0, source.getName().lastIndexOf("."));

app/src/main/java/com/duy/ccppcompiler/compiler/compilers/GPlusPlusCompiler.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
public class GPlusPlusCompiler extends GCCCompiler {
3232
private static final String G_PLUS_PLUS_COMPILER_NAME = "g++-4.9";
3333

34-
public GPlusPlusCompiler(Context context, boolean nativeActivity, boolean buildSDL, ICompileSetting setting) {
35-
super(context, nativeActivity, buildSDL, setting);
34+
public GPlusPlusCompiler(Context context, boolean nativeActivity, ICompileSetting setting) {
35+
super(context, nativeActivity, setting);
3636
}
3737

3838
@Override
@@ -53,8 +53,6 @@ protected String buildArgs(File[] sourceFiles) {
5353
}
5454
if (mBuildNativeActivity) {
5555
args.addFlags(buildNativeActivityFlags(sourceFiles));
56-
} else if (mBuildSDL) {
57-
args.addFlags(buildSDLActivityFlags(sourceFiles));
5856
} else {
5957
args.addFlags(buildExecutableFlags(sourceFiles));
6058
}

app/src/main/java/com/duy/ccppcompiler/ui/InstallActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ protected Boolean doInBackground(Void... voids) {
192192
IOUtils.write("int main(){ return 0; }", output);
193193
output.close();
194194

195-
GCCCompiler compiler = new GCCCompiler(context, false, false, null);
195+
GCCCompiler compiler = new GCCCompiler(context, false, null);
196196
CompileResult result = compiler.compile(new File[]{file});
197197
if (result == null || result.getResultCode() != 0) {
198198
publishProgress("Could not execute C compiler, please install compiler");
@@ -204,7 +204,7 @@ protected Boolean doInBackground(Void... voids) {
204204
output = new FileOutputStream(file);
205205
IOUtils.write("int main() { return 0; }", output);
206206
output.close();
207-
compiler = new GPlusPlusCompiler(context, false, false, null);
207+
compiler = new GPlusPlusCompiler(context, false, null);
208208
result = compiler.compile(new File[]{file});
209209
if (result == null || result.getResultCode() != 0) {
210210
publishProgress("Could not execute C++ compiler, please install compiler");

0 commit comments

Comments
 (0)