Skip to content

Commit 12ce244

Browse files
committed
cleanup
1 parent 187fbec commit 12ce244

File tree

14 files changed

+165
-87
lines changed

14 files changed

+165
-87
lines changed

.idea/copyright/GNU_GPL_3.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copyright/profiles_settings.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/duy/ccppcompiler/compiler/CompileManager.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,48 @@
1818

1919
import android.content.Intent;
2020

21-
import com.duy.ccppcompiler.compiler.shell.GccCompileResult;
21+
import com.duy.ccppcompiler.compiler.shell.CommandResult;
22+
import com.duy.ccppcompiler.compiler.shell.CompileResult;
23+
import com.duy.ccppcompiler.compiler.shell.NativeActivityCompileResult;
2224
import com.duy.ccppcompiler.console.TermActivity;
2325
import com.duy.editor.CodeEditorActivity;
2426
import com.pdaxrom.cctools.BuildConstants;
27+
import com.pdaxrom.cctools.LauncherNativeActivity;
2528

2629
import java.io.File;
2730

2831
/**
2932
* Created by Duy on 25-Apr-18.
3033
*/
3134

32-
public class CompileManager extends CompileManagerImpl<GccCompileResult> {
35+
public class CompileManager extends CompileManagerImpl {
3336

3437
public CompileManager(CodeEditorActivity activity) {
3538
super(activity);
3639
}
3740

3841
@Override
39-
public void onCompileSuccess(GccCompileResult commandResult) {
40-
super.onCompileSuccess(commandResult);
41-
42-
//now run binary file
43-
File binFile = commandResult.getBinaryFile();
44-
if (binFile != null) {
45-
Intent intent = new Intent(mActivity, TermActivity.class);
46-
intent.putExtra(BuildConstants.EXTRA_FILE_NAME, binFile.getAbsolutePath());
47-
intent.putExtra(BuildConstants.EXTRA_WORK_DIR, binFile.getParent());
48-
mActivity.startActivity(intent);
42+
public void onCompileSuccess(CommandResult result) {
43+
super.onCompileSuccess(result);
44+
45+
if (result instanceof NativeActivityCompileResult) {
46+
//now run binary file
47+
File binFile = ((NativeActivityCompileResult) result).getBinaryFile();
48+
if (binFile != null) {
49+
Intent intent = new Intent(getActivity(), LauncherNativeActivity.class);
50+
intent.putExtra(BuildConstants.EXTRA_FILE_NAME, binFile.getAbsolutePath());
51+
intent.putExtra(BuildConstants.EXTRA_WORK_DIR, binFile.getParent());
52+
mActivity.startActivity(intent);
53+
}
54+
55+
} else if (result instanceof CompileResult) {
56+
File binFile = ((CompileResult) result).getBinaryFile();
57+
if (binFile != null) {
58+
Intent intent = new Intent(getActivity(), TermActivity.class);
59+
intent.putExtra(BuildConstants.EXTRA_FILE_NAME, binFile.getAbsolutePath());
60+
intent.putExtra(BuildConstants.EXTRA_WORK_DIR, binFile.getParent());
61+
mActivity.startActivity(intent);
62+
}
4963
}
5064
}
5165

app/src/main/java/com/duy/ccppcompiler/compiler/CompileManagerImpl.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
import com.duy.ccppcompiler.R;
2626
import com.duy.ccppcompiler.compiler.compilers.ICompiler;
2727
import com.duy.ccppcompiler.compiler.shell.CommandResult;
28-
import com.duy.ide.Diagnostic;
29-
import com.duy.ide.DiagnosticPresenter;
30-
import com.duy.ide.DiagnosticsCollector;
3128
import com.duy.ccppcompiler.compiler.shell.OutputParser;
3229
import com.duy.common.DLog;
3330
import com.duy.editor.CodeEditorActivity;
31+
import com.duy.ide.Diagnostic;
32+
import com.duy.ide.DiagnosticPresenter;
33+
import com.duy.ide.DiagnosticsCollector;
3434
import com.duy.ide.editor.SimpleEditorActivity;
3535
import com.jecelyin.editor.v2.widget.menu.MenuDef;
3636

@@ -40,10 +40,10 @@
4040
/**
4141
* Created by Duy on 18-May-18.
4242
*/
43-
public abstract class CompileManagerImpl<T extends CommandResult> implements ICompileManager<T> {
43+
public abstract class CompileManagerImpl implements ICompileManager {
4444
private static final String TAG = "CompileManager";
4545
@NonNull
46-
protected SimpleEditorActivity mActivity;
46+
SimpleEditorActivity mActivity;
4747
@Nullable
4848
private ProgressDialog mCompileDialog;
4949
@Nullable
@@ -84,27 +84,24 @@ public void onNewMessage(CharSequence charSequence) {
8484
}
8585

8686
@Override
87-
public void onCompileFailed(T commandResult) {
88-
finishCompile(commandResult);
87+
public void onCompileFailed(CommandResult compileResult) {
88+
finishCompile(compileResult);
8989

9090
if (mDiagnosticPresenter != null) {
9191
mDiagnosticPresenter.expandView();
9292
}
9393

9494
Toast.makeText(mActivity, "Compiled failed", Toast.LENGTH_LONG).show();
95-
if (DLog.DEBUG) DLog.w(TAG, "onCompileFailed: \n" + commandResult.getMessage());
95+
if (DLog.DEBUG) DLog.w(TAG, "onCompileFailed: \n" + compileResult.getMessage());
9696
}
9797

9898
@Override
99-
public void onCompileSuccess(T commandResult) {
99+
public void onCompileSuccess(CommandResult commandResult) {
100+
if (DLog.DEBUG) DLog.d(TAG, "onCompileSuccess() commandResult = [" + commandResult + "]");
100101
finishCompile(commandResult);
101102
}
102103

103-
public void setDiagnosticPresenter(DiagnosticPresenter diagnosticPresenter) {
104-
this.mDiagnosticPresenter = diagnosticPresenter;
105-
}
106-
107-
private void finishCompile(T commandResult) {
104+
private void finishCompile(CommandResult compileResult) {
108105
hideDialog();
109106

110107
mActivity.setMenuStatus(R.id.action_run, MenuDef.STATUS_NORMAL);
@@ -113,11 +110,11 @@ private void finishCompile(T commandResult) {
113110
if (mDiagnosticPresenter != null) {
114111
DiagnosticsCollector diagnosticsCollector = new DiagnosticsCollector();
115112
OutputParser parser = new OutputParser(diagnosticsCollector);
116-
parser.parse(commandResult.getMessage());
113+
parser.parse(compileResult.getMessage());
117114

118115
ArrayList<Diagnostic> diagnostics = diagnosticsCollector.getDiagnostics();
119116
mDiagnosticPresenter.setDiagnostics(diagnostics);
120-
mDiagnosticPresenter.log(commandResult.getMessage());
117+
mDiagnosticPresenter.log(compileResult.getMessage());
121118
}
122119
}
123120

@@ -128,7 +125,16 @@ private void hideDialog() {
128125
}
129126
}
130127

128+
public void setDiagnosticPresenter(DiagnosticPresenter diagnosticPresenter) {
129+
this.mDiagnosticPresenter = diagnosticPresenter;
130+
}
131+
131132
public void setCompiler(ICompiler compiler) {
132133
this.mCompiler = compiler;
133134
}
135+
136+
@NonNull
137+
public SimpleEditorActivity getActivity() {
138+
return mActivity;
139+
}
134140
}

app/src/main/java/com/duy/ccppcompiler/compiler/CompileTask.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import com.duy.ccppcompiler.compiler.compilers.ICompiler;
2424
import com.duy.ccppcompiler.compiler.shell.CommandResult;
25-
import com.duy.common.DLog;
2625

2726
import java.io.File;
2827

@@ -63,8 +62,6 @@ protected CommandResult doInBackground(Void... voids) {
6362
@Override
6463
protected void onPostExecute(CommandResult commandResult) {
6564
super.onPostExecute(commandResult);
66-
if (DLog.DEBUG)
67-
DLog.d(TAG, "onPostExecute() called with: shellResult = [" + commandResult + "]");
6865
if (mCompileManager == null) {
6966
return;
7067
}

app/src/main/java/com/duy/ccppcompiler/compiler/ICompileManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* Created by Duy on 25-Apr-18.
2727
*/
2828

29-
public interface ICompileManager<T extends CommandResult> {
29+
public interface ICompileManager {
3030
@MainThread
3131
void onNewMessage(CharSequence charSequence);
3232

@@ -47,12 +47,12 @@ public interface ICompileManager<T extends CommandResult> {
4747
* This method will be call when compile success
4848
*/
4949
@MainThread
50-
void onCompileSuccess(T commandResult);
50+
void onCompileSuccess(CommandResult compileResult);
5151

5252
/**
5353
* This method will be call when compile failed with error
5454
*/
5555
@MainThread
56-
void onCompileFailed(T commandResult);
56+
void onCompileFailed(CommandResult compileResult);
5757

5858
}

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
/*
2-
* Copyright 2018 Mr Duy
2+
* Copyright (C) 2018 Duy Tran Le
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
78
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
913
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1516
*/
1617

1718
package com.duy.ccppcompiler.compiler.compilers;

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import com.duy.ccppcompiler.compiler.ICompileSetting;
2424
import com.duy.ccppcompiler.compiler.shell.CommandBuilder;
25-
import com.duy.ccppcompiler.compiler.shell.GccCompileResult;
25+
import com.duy.ccppcompiler.compiler.shell.CompileResult;
2626
import com.duy.ccppcompiler.packagemanager.Environment;
2727
import com.pdaxrom.utils.Utils;
2828

@@ -40,10 +40,9 @@ public class GCCCompiler extends CompilerImpl {
4040
private static final String TAG = "GCCCompiler";
4141
private static final String GCC_COMPILER_NAME = "gcc-4.9";
4242

43-
protected File mOutFile;
44-
protected ICompileSetting mSetting;
45-
46-
private boolean mBuildNativeActivity;
43+
File mOutFile;
44+
ICompileSetting mSetting;
45+
boolean mBuildNativeActivity;
4746

4847
public GCCCompiler(Context context, boolean nativeActivity, @Nullable ICompileSetting setting) {
4948
super(context);
@@ -52,8 +51,8 @@ public GCCCompiler(Context context, boolean nativeActivity, @Nullable ICompileSe
5251
}
5352

5453
@Override
55-
public GccCompileResult compile(File[] sourceFiles) {
56-
GccCompileResult result = new GccCompileResult(super.compile(sourceFiles));
54+
public CompileResult compile(File[] sourceFiles) {
55+
CompileResult result = new CompileResult(super.compile(sourceFiles));
5756
if (result.getResultCode() == RESULT_NO_ERROR) {
5857
if (mOutFile != null && mOutFile.exists()) {
5958
try {
@@ -99,17 +98,19 @@ protected String buildArgs(File[] sourceFiles) {
9998
}
10099

101100
if (mBuildNativeActivity) {
102-
mOutFile = new File(source.getParent(), "lib" + nameNoExt + ".so");
101+
String outFile = nameNoExt;
102+
// mOutFile = new File(source.getParent(), "lib" + nameNoExt + ".so");
103+
outFile = "lib" + outFile + ".so";
103104
String cCtoolsDir = Environment.getCCtoolsDir(mContext);
104105
args.addFlags(String.format("-I%s/sources/native_app_glue", cCtoolsDir))
105106
.addFlags(String.format("%s/sources/native_app_glue/android_native_app_glue.c", cCtoolsDir))
106-
.addFlags(String.format("-Wl,-soname,%s", mOutFile.getAbsolutePath()))
107+
.addFlags(String.format("-Wl,-soname,%s", outFile))
107108
.addFlags("-shared")
108109
.addFlags("-Wl,--no-undefined -Wl,-z,noexecstack")
109110
.addFlags("-llog")
110111
.addFlags("-landroid")
111112
.addFlags("-lm")
112-
.addFlags("-o", mOutFile.getAbsolutePath());
113+
.addFlags("-o", outFile);
113114
} else {
114115
mOutFile = new File(source.getParent(), nameNoExt);
115116
args.addFlags("-o", mOutFile.getAbsolutePath());

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
package com.duy.ccppcompiler.compiler.compilers;
1818

1919
import android.content.Context;
20+
import android.os.Build;
2021

2122
import com.duy.ccppcompiler.compiler.ICompileSetting;
23+
import com.duy.ccppcompiler.compiler.shell.CommandBuilder;
24+
import com.duy.ccppcompiler.packagemanager.Environment;
25+
26+
import java.io.File;
2227

2328
/**
2429
* G++ compiler as GCC compiler but it different name, just override {@link #getCompilerProgram()}
@@ -35,4 +40,41 @@ public GPlusPlusCompiler(Context context, boolean nativeActivity, ICompileSettin
3540
protected String getCompilerProgram() {
3641
return G_PLUS_PLUS_COMPILER_NAME;
3742
}
43+
44+
@Override
45+
protected String buildArgs(File[] sourceFiles) {
46+
File source = sourceFiles[0];
47+
String nameNoExt = source.getName().substring(0, source.getName().lastIndexOf("."));
48+
49+
CommandBuilder args = new CommandBuilder();
50+
for (File sourceFile : sourceFiles) {
51+
args.addFlags(sourceFile.getAbsolutePath());
52+
}
53+
if (mSetting != null) {
54+
args.addFlags(mSetting.getCxxFlags());
55+
}
56+
57+
if (mBuildNativeActivity) {
58+
mOutFile = new File(source.getParent(), "lib" + nameNoExt + ".so");
59+
String cCtoolsDir = Environment.getCCtoolsDir(mContext);
60+
args.addFlags(String.format("-I%s/sources/native_app_glue", cCtoolsDir))
61+
.addFlags(String.format("%s/sources/native_app_glue/android_native_app_glue.c", cCtoolsDir))
62+
.addFlags(String.format("-Wl,-soname,%s", mOutFile.getAbsolutePath()))
63+
.addFlags("-shared")
64+
.addFlags("-Wl,--no-undefined -Wl,-z,noexecstack")
65+
.addFlags("-llog")
66+
.addFlags("-landroid")
67+
.addFlags("-lm")
68+
.addFlags("-o", mOutFile.getAbsolutePath());
69+
} else {
70+
mOutFile = new File(source.getParent(), nameNoExt);
71+
args.addFlags("-o", mOutFile.getAbsolutePath());
72+
}
73+
74+
if (Build.VERSION.SDK_INT >= 21) {
75+
args.addFlags("-pie");
76+
}
77+
78+
return args.build();
79+
}
3880
}

app/src/main/java/com/duy/ccppcompiler/compiler/shell/CommandResult.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ public CommandResult(CommandResult commandResult) {
3737
this(commandResult.getResultCode(), commandResult.getMessage());
3838
}
3939

40+
@Override
41+
public String toString() {
42+
return "CommandResult{" +
43+
"message='" + message + '\'' +
44+
", resultCode=" + resultCode +
45+
", time=" + time +
46+
'}';
47+
}
48+
4049
public long getTime() {
4150
return time;
4251
}
@@ -45,15 +54,6 @@ public void setTime(long time) {
4554
this.time = time;
4655
}
4756

48-
@Override
49-
public String toString() {
50-
return "ShellResult{" +
51-
"resultCode=" + resultCode +
52-
", message='" + message + '\'' +
53-
", time=" + time +
54-
'}';
55-
}
56-
5757
public int getResultCode() {
5858
return resultCode;
5959
}

0 commit comments

Comments
 (0)