Skip to content

Commit

Permalink
Output build command when building library only. includes also added …
Browse files Browse the repository at this point in the history
…to bundle
  • Loading branch information
ashleyj committed Aug 1, 2016
1 parent f2a503d commit 364d1e1
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 27 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ task distTargz( type: Tar) {
from ("vm/LICENSE.txt")
}

into ("${baseName}/include") {
from ("vm/core/include")
}

extension = 'tar.gz'
compression = Compression.GZIP
}
11 changes: 5 additions & 6 deletions compiler/src/main/java/aura/compiler/AppCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,14 @@ private void compile() throws IOException {
}
}

if (config.isBuildAsLib()) {
/*TODO output compilation details */
return;
}

long start = System.currentTimeMillis();
linker.link(linkClasses);
long duration = System.currentTimeMillis() - start;
config.getLogger().info("Linked %d classes in %.2f seconds", linkClasses.size(), duration / 1000.0);
if (config.isBuildAsLib()) {
System.out.println("\nBuild Args: " + config.getTarget().getBuildCommand());
} else {
config.getLogger().info("Linked %d classes in %.2f seconds", linkClasses.size(), duration / 1000.0);
}
}

public static void main(String[] args) throws IOException {
Expand Down
12 changes: 5 additions & 7 deletions compiler/src/main/java/aura/compiler/Linker.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ public void link(Set<Clazz> classes) throws IOException {

Arch arch = config.getArch();
OS os = config.getOs();

Set<Clazz> linkClasses = new TreeSet<Clazz>(classes);
config.getLogger().info("Linking %d classes (%s %s %s)", linkClasses.size(),
os, arch, config.isDebug() ? "debug" : "release");

if (!config.isBuildAsLib()) {
config.getLogger().info("Linking %d classes (%s %s %s)", linkClasses.size(),
os, arch, config.isDebug() ? "debug" : "release");
}

ModuleBuilder mb = new ModuleBuilder();
mb.addInclude(getClass().getClassLoader().getResource(String.format("header-%s-%s.ll", os.getFamily(), arch)));
Expand Down Expand Up @@ -261,13 +263,10 @@ public void link(Set<Clazz> classes) throws IOException {
stubRefsArray.add(new ConstantBitcast(fn.ref(), I8_PTR));
}
stubRefsArray.add(new NullConstant(I8_PTR));

mb.addGlobal(new Global("_bcStrippedMethodStubs", stubRefsArray.build()));

Random rnd = new Random();

buildTypeInfos(typeInfos);

Set<String> checkcasts = new HashSet<>();
Set<String> instanceofs = new HashSet<>();
Set<String> invokes = new HashSet<>();
Expand All @@ -282,7 +281,6 @@ public void link(Set<Clazz> classes) throws IOException {
for (Triple<String, String, String> node : config.getDependencyGraph().findReachableMethods()) {
reachableMethods.add(node.getLeft() + "." + node.getMiddle() + node.getRight());
}

int totalMethodCount = 0;
int reachableMethodCount = 0;
for (Clazz clazz : linkClasses) {
Expand Down
20 changes: 18 additions & 2 deletions compiler/src/main/java/aura/compiler/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ protected Config build() throws IOException {

public static class Home {
private File binDir = null;
private File includeDir = null;
private File libVmDir = null;
private File rtPath = null;
private Map<Cacerts, File> cacertsPath = null;
Expand All @@ -884,14 +885,16 @@ protected Home(File homeDir, boolean validate) {
}
}
binDir = new File(homeDir, "bin");
includeDir = new File(homeDir, "include");
libVmDir = new File(homeDir, "lib/vm");
rtPath = new File(homeDir, "lib/aura-rt.jar");
cacertsPath = new HashMap<Cacerts, File>();
cacertsPath.put(Cacerts.full, new File(homeDir, "lib/cacerts-full.jar"));
}

private Home(File devDir, File binDir, File libVmDir, File rtPath) {
private Home(File devDir, File binDir, File includeDir, File libVmDir, File rtPath) {
this.binDir = binDir;
this.includeDir = includeDir;
this.libVmDir = libVmDir;
this.rtPath = rtPath;
cacertsPath = new HashMap<Cacerts, File>();
Expand All @@ -908,6 +911,10 @@ public File getBinDir() {
return binDir;
}

public File getIncludeDir() {
return includeDir;
}

public File getLibVmDir() {
return libVmDir;
}
Expand Down Expand Up @@ -975,6 +982,10 @@ public static void validate(File dir) throws IllegalArgumentException {
if (!binDir.exists() || !binDir.isDirectory()) {
throw new IllegalArgumentException(error + "bin/ missing or invalid");
}
File includeDir = new File(dir, "include");
if (!includeDir.exists() || !includeDir.isDirectory()) {
throw new IllegalArgumentException(error + "include/ missing or invalid");
}
File libVmDir = new File(libDir, "vm");
if (!libVmDir.exists() || !libVmDir.isDirectory()) {
throw new IllegalArgumentException(error + "lib/vm/ missing or invalid");
Expand Down Expand Up @@ -1020,6 +1031,11 @@ private static Home validateDevRootDir(File dir) {
throw new IllegalArgumentException(error + "bin/ missing or invalid");
}

File includeDir = new File(dir, "include");
if (!includeDir.exists() || !includeDir.isDirectory()) {
throw new IllegalArgumentException(error + "include/ missing or invalid");
}

String rtJarName = "aura-rt-" + Version.getVersion() + ".jar";
File rtJar = new File(dir, "rt/target/" + rtJarName);
File rtClasses = new File(dir, "rt/target/classes/");
Expand All @@ -1033,7 +1049,7 @@ private static Home validateDevRootDir(File dir) {
}
}

return new Home(dir, binDir, vmBinariesDir, rtSource);
return new Home(dir, binDir, includeDir, vmBinariesDir, rtSource);
}
}

Expand Down
70 changes: 59 additions & 11 deletions compiler/src/main/java/aura/compiler/target/AbstractTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
*
*/
public abstract class AbstractTarget implements Target {
private String buildCommand = "";

@Transient
protected Config config;

Expand Down Expand Up @@ -87,18 +89,24 @@ protected List<String> getTargetLibs() {
}

public void build(List<File> objectFiles) throws IOException {
build(objectFiles, false);
}

public void build(List<File> objectFiles, boolean dryRun) throws IOException {
File outFile = new File(config.getTmpDir(), config.getExecutableName());

config.getLogger().info("Building %s binary %s", config.getTarget().getType(), outFile);

if (!config.isBuildAsLib()) {
config.getLogger().info("Building %s binary %s", config.getTarget().getType(), outFile);
}

LinkedList<String> ccArgs = new LinkedList<String>();
LinkedList<String> libs = new LinkedList<String>();

ccArgs.addAll(getTargetCcArgs());
libs.addAll(getTargetLibs());

String libSuffix = config.isUseDebugLibs() ? "-dbg" : "";

libs.add("-laura-bc" + libSuffix);
if (config.getOs().getFamily() == OS.Family.darwin) {
libs.add("-force_load");
Expand Down Expand Up @@ -188,7 +196,7 @@ public void build(List<File> objectFiles) throws IOException {
ccArgs.add("-Wl,-dead_strip");

}

if (config.getOs().getFamily() == OS.Family.darwin && !config.getFrameworks().isEmpty()) {
for (String p : config.getFrameworks()) {
libs.add("-framework");
Expand All @@ -206,7 +214,7 @@ public void build(List<File> objectFiles) throws IOException {
ccArgs.add("-F" + p.getAbsolutePath());
}
}

if (!config.getLibs().isEmpty()) {
objectFiles = new ArrayList<File>(objectFiles);
for (Config.Lib lib : config.getLibs()) {
Expand All @@ -224,7 +232,7 @@ public void build(List<File> objectFiles) throws IOException {
if (lib.isForce()) {
libs.add("-Wl,--whole-archive");
}
libs.add(new File(p).getAbsolutePath());
libs.add(new File(p).getAbsolutePath());
if (lib.isForce()) {
libs.add("-Wl,--no-whole-archive");
}
Expand All @@ -250,10 +258,45 @@ public void build(List<File> objectFiles) throws IOException {
libs.add("MobileCoreServices");
}
}

doBuild(outFile, ccArgs, objectFiles, libs);
buildCommand = flatten(ccArgs, objectFiles, libs);
if (!config.isSkipLinking()) {
doBuild(outFile, ccArgs, objectFiles, libs);
}
}


private String flatten(LinkedList<String> ccArgs, List<File> objectFiles, LinkedList<String> libs) throws IOException {
StringBuilder stringBuilder = new StringBuilder();
List<String> paths = new ArrayList<>();
boolean isDarwin = config.getOs().getFamily() == OS.Family.darwin;

boolean quote = !isDarwin;
for (File objectFile : objectFiles) {
paths.add((quote ? "\"" : "") + objectFile.getAbsolutePath() + (quote ? "\"" : ""));
}

File objectsFile = new File(config.getTmpDir(), "objects");
FileUtils.writeLines(objectsFile, paths, "\n");
stringBuilder.append("-Wl,-filelist,").append(objectsFile.getAbsolutePath()).append(" ");

for (String ccArg : ccArgs) {
stringBuilder.append(ccArg).append(" ");
}
if (config.getOs() == OS.macosx) {
stringBuilder.append("-mmacosx-version-min=" + config.getOs().getMinVersion());
if (config.getArch() == Arch.x86 || config.isDebug()) {
stringBuilder.append("-Wl,-no_pie");
}
}
stringBuilder.append(" ");
for (String lib : libs) {
stringBuilder.append(lib).append(" ");
}

stringBuilder.append("-I").append(config.getHome().getIncludeDir());

return stringBuilder.toString();
}

protected void doBuild(File outFile, List<String> ccArgs, List<File> objectFiles,
List<String> libs) throws IOException {

Expand Down Expand Up @@ -581,4 +624,9 @@ protected void stripArchive(Path path, File output) throws IOException {
IOUtils.closeQuietly(out);
}
}

@Override
public String getBuildCommand() {
return buildCommand;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ public void init(Config config) {
arch = Arch.getDefaultArch();
}
}


@Override
public String getBuildCommand() {
return super.getBuildCommand();
}

@Override
protected void doBuild(File outFile, List<String> ccArgs,
List<File> objectFiles, List<String> libArgs)
Expand Down
5 changes: 5 additions & 0 deletions compiler/src/main/java/aura/compiler/target/Target.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,9 @@ public interface Target {
* Initializes this {@link Target} from the specified {@link Config}.
*/
void init(Config config);

/**
* Return build command
*/
String getBuildCommand();
}

0 comments on commit 364d1e1

Please sign in to comment.