Skip to content

Added build-android script #1249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 17, 2017

Conversation

amraboelela
Copy link
Contributor

No description provided.

.gitignore Outdated
@@ -20,3 +20,6 @@ Build
*.swp
*.orig
.arcconfig

*.tgz
build.ninjae
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing this, why not change the sed script so that you're using an already known extension like ~ which will be ignored? Then you don't need to add this.

@@ -1325,11 +1325,13 @@ CF_SWIFT_EXPORT void _CFThreadSetName(const char *_Nullable name) {
}

CF_SWIFT_EXPORT int _CFThreadGetName(char *buf, int length) {
#if !TARGET_OS_ANDROID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than wrapping this in an if ! construct, why not add an #elif TARGET_OS_ANDROID above the #elif DEPLOYMENT_TARGET_LINUX line? Then there's a sensible place to add implementations in the future should it be needed.

Also, do you know why the variable is TARGET_OS_ANDROID rather than DEPLOYMENT_TARGET_ANDROID?

@@ -27,7 +27,10 @@
#include <CoreFoundation/ForFoundationOnly.h>
#include <fts.h>
#include <pthread.h>

#if !TARGET_OS_ANDROID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would using the other syntax of #if __has_include(<execinfo.h>) work here, to keep it in line with the other tests?

build-android Outdated
-DLIBDISPATCH_BUILD_DIR=$SWIFT_PATH/swift-corelibs-libdispatch &&

cp -r /usr/include/uuid $ANDROID_STANDALONE_SYSROOT/usr/include
sed -ie "s/-I.\/ -I\/usr\/include\/x86_64-linux-gnu -I\/usr\/include\/x86_64-linux-gnu -I\/usr\/include\/libxml2//" build.ninja
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(From above) if this was sed -i~ instead, you would generate build.ninja~ as the backup file, which would automatically be excluded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about if I just do "sed -i" will it edit without backup? I don't need to generate backup.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amraboelela Yes it should do, from the manage:

 -i[SUFFIX], --in-place[=SUFFIX]
             edit files in place (makes backup if extension supplied)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen some versions of using sed -i when you don't explicitly specify an extension, but it then takes the following word from the command line and uses that as the extension itself. I would recommend using sed -i~ so that the backups aren't committed to git (the *~ pattern is already in the .gitattributes file) and it avoids any versions of sed where running sed -i something doesn't get translated as "use something as the backup extension".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still looks outstanding from GitHub's diffs?

.gitignore Outdated
@@ -20,3 +20,6 @@ Build
*.swp
*.orig
.arcconfig

*.tgz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear what this is blocking here, and would prevent people adding .tgz examples in the future (for example). Can you explain why this is needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to know why this *.tgz is here. Can you remove this from the commit or justify why it's necessary?

Copy link
Contributor

@alblue alblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the .tgz, change the sed -ie to sed -i~, and rebase the changes (not via merge) so that we can clearly see what's added?

The changes seem to imply more than was originally added, but it's not clear if that's due to the merge and GitHub showing the differences. A clean rebase without the empty merge node and fixing the minor issues should help.

.gitignore Outdated
@@ -20,3 +20,6 @@ Build
*.swp
*.orig
.arcconfig

*.tgz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to know why this *.tgz is here. Can you remove this from the commit or justify why it's necessary?

build-android Outdated
-DLIBDISPATCH_BUILD_DIR=$SWIFT_PATH/swift-corelibs-libdispatch &&

cp -r /usr/include/uuid $ANDROID_STANDALONE_SYSROOT/usr/include
sed -ie "s/-I.\/ -I\/usr\/include\/x86_64-linux-gnu -I\/usr\/include\/x86_64-linux-gnu -I\/usr\/include\/libxml2//" build.ninja
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still looks outstanding from GitHub's diffs?

Copy link
Contributor

@alblue alblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert the .gitignore so that it doesn't make any changes to this commit?

Also, can you rebase the code onto master and get rid of the merge nodes so that we can see what is happening? The merge node committed previously makes it a little unclear as to what is here. Doing a git pull --rebase should fix this up.

.gitignore Outdated
@@ -20,3 +20,4 @@ Build
*.swp
*.orig
.arcconfig

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file doesn't need to be changed, and the addition of a newline doesn't add any value. Can you revert the file to what it was beforehand?

@amraboelela
Copy link
Contributor Author

I am now using -i~ but git status gives:

(use "git add ..." to include in what will be committed)

build.ninja~

Also I am not able to rebase the branch correctly.

@amraboelela
Copy link
Contributor Author

I am finally able to rebase it after fixing the conflicts :)

@alblue
Copy link
Contributor

alblue commented Oct 12, 2017

@swift-ci please test

1 similar comment
@alblue
Copy link
Contributor

alblue commented Oct 12, 2017

@swift-ci please test

Copy link
Contributor

@alblue alblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to be a pain - just when all the tests had run successfully, too :)

The TestNSLock.swift has ended up reverting a recent PR - can you remove this change from your request?

@@ -41,14 +41,11 @@ class TestNSLock: XCTestCase {
}

let thread = Thread() {
lock.lock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to revert #1261 presumably accidentally. Can you remove this file from this PR?

Copy link
Contributor

@xwu xwu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there's some more edits required anyway, here's some drive-by formatting nits.

@@ -28,6 +28,10 @@ open class Host: NSObject {
internal var _names = [String]()
internal var _addresses = [String]()

#if os(Android)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: #if and #endif should be de-indented (no spaces at the beginning of the line before #) and the enclosed statements should be indented as though it isn't surrounded by a compile-time condition (that is, static internal let NI_MAXHOST here should align with static internal let _current).

@@ -36,7 +40,7 @@ open class Host: NSObject {
}

static internal func currentHostName() -> String {
let hname = UnsafeMutablePointer<Int8>.allocate(capacity: Int(NI_MAXHOST))
let hname = UnsafeMutablePointer<Int8>.allocate(capacity: Int(NI_MAXHOST))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please restore the original indentation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one as well.

@@ -65,6 +69,9 @@ open class Host: NSObject {
}

internal func _resolveCurrent() {
#if os(Android)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same nit as above about indentation of #if and #endif.

@@ -65,6 +69,9 @@ open class Host: NSObject {
}

internal func _resolveCurrent() {
#if os(Android)
return
#else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise with indentation of #else.

@@ -256,7 +256,11 @@ open class Thread : NSObject {
let maxSupportedStackDepth = 128;
let addrs = UnsafeMutablePointer<UnsafeMutableRawPointer?>.allocate(capacity: maxSupportedStackDepth)
defer { addrs.deallocate(capacity: maxSupportedStackDepth) }
#if os(Android)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same nit here about indentation of #if, #else and #endif.

@@ -270,6 +274,9 @@ open class Thread : NSObject {
}

open class var callStackSymbols: [String] {
#if os(Android)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same nit here about #if, #else and #endif; please also de-indent return [] by four spaces so that it aligns with return backtraceAddresses.

@alblue
Copy link
Contributor

alblue commented Oct 13, 2017

@amraboelela There was another change recently from @johnno1962 that was merged yesterday regarding Android support: #1189

Can you rebase the changes on top of these and test that your changes still make sense? I'm not sure if there's overlap (the lack of conflicts suggests not) but it would be worth verifying it for Android support.

Separately, if you're interested, you can configure your git repository with git config pull.rebase true which means whenever you do a pull, it'll automatically rebase it instead of creating merge nodes. This makes it much easier to keep up-to-date with the branches :)

If you're doing local changes, you might also want to use git config rebase.autostash true - this allows you to a pull in place while not losing your local changes.

The above will apply to the single repository that you run in; if you want them to apply to all repositories, run git config --global with the above. Hope that's of interest!

Finally, keep up the good work. I know there's been a lot of back-and-forth on this, as well as delays, for which I apologise. I am working to clear the backlog and want to merge these changes in so keep going👍🏻

@amraboelela amraboelela force-pushed the build-android-script branch 3 times, most recently from 4d5bc3f to 2ba419d Compare October 13, 2017 15:49
@amraboelela
Copy link
Contributor Author

All good now?

@amraboelela
Copy link
Contributor Author

amraboelela commented Oct 13, 2017

@alblue did Apple assign you the task of "cleaning out" all the PRs in Foundation? :)

What about swift repo, I have a related PR there needs to get moving: swiftlang/swift#11870

And also in libdispatch: swiftlang/swift-corelibs-libdispatch#302

Copy link
Contributor

@alblue alblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor nits - @xwu might be able to clarify the indentation specifics too

}

internal func _resolve() {
#if os(Android)
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the indentation of this return doesn't line up - it should be one indent to the right, I think. @xwu can you confirm?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, return needs four additional preceding spaces.

.gitignore Outdated
@@ -10,6 +10,7 @@ project.xcworkspace

# build files generated by the configure script
*.ninja
*.ninja~
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're making other changes to this script, I'd suggest putting *~ at the top of the file and removing this line. That way any backup file won't get committed. It's a fairly standard thing to have in Linux repos, but tends to be forgotten on Mac ones.

See e.g. https://github.com/github/gitignore/blob/master/Global/Linux.gitignore#L1

@@ -28,6 +28,10 @@ open class Host: NSObject {
internal var _names = [String]()
internal var _addresses = [String]()

#if os(Android)
static internal let NI_MAXHOST = 1025
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line looks like it doesn't line up with the static internal let below - can you indent it to the left?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't forget to address this comment

@@ -270,6 +274,9 @@ open class Thread : NSObject {
}

open class var callStackSymbols: [String] {
#if os(Android)
return []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the return here should line up with the return of the return backtraceAddresses below. It's not rendering as that in the GitHub UI. Maybe a mix of tabs and spaces causing problems?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like all spaces here, but agree that return needs to be de-indented four spaces.

@alblue
Copy link
Contributor

alblue commented Oct 13, 2017

@alblue did Apple assign you the task of "cleaning out" all the PRs in Foundation? :)

No, I'm just trying to help clear out the queue :)

@alblue
Copy link
Contributor

alblue commented Oct 13, 2017

One other thing might help - there's two sorts of changes here; stubbing out APIs that don't work on Android, and the build script to help build it. Can we split those into two PRs? The build-script and the .gitignore can go in one and the fixes to help it build in another.

In swift's swiftlang/swift#11870 repo there seems to be a proposal of moving towards a CMake instead of autotools for building the code. Is that an approach we can think of using here?

@amraboelela
Copy link
Contributor Author

If we don’t include those changes, the build would give errors, so they should go together.

@amraboelela
Copy link
Contributor Author

The cmake proposal is for libdispatch I think. But the cmake script is not ready yet, so I suggest to keep the autoconf build script for now.

@alblue
Copy link
Contributor

alblue commented Oct 13, 2017

If we don’t include those changes, the build would give errors, so they should go together.

I was thinking, maybe we commit the code changes first, then have the build script as a dependent change.

The cmake proposal is for libdispatch I think. But the cmake script is not ready yet, so I suggest to keep the autoconf build script for now.

OK. We don't have a CMake list for now in foundation, so that makes sense. It would be interesting to know how much it would be to convert it to CMake in the future. Maybe that's something that @compnerd could advise with.

@alblue
Copy link
Contributor

alblue commented Oct 13, 2017

@swift-ci please test


#if __has_include(<malloc/malloc.h>)
#include <malloc/malloc.h>
#if __has_include(<execinfo.h>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is going on here now? Why is execinfo.h being conditionally included twice?

@@ -343,6 +343,9 @@ open class FileManager : NSObject {
This method replaces fileSystemAttributesAtPath:.
*/
open func attributesOfFileSystem(forPath path: String) throws -> [FileAttributeKey : Any] {
#if os(Android)
NSUnimplemented()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this line, NSUnimplemented() means 'This hasn't been implemented yet, but it will be in the future' - whereas NSUnsupported() means that 'This will not be implemented on this platform'. Can you confirm this is intended to be implemented in the future? If not, using NSUnsupported() would be preferable.

Copy link
Contributor Author

@amraboelela amraboelela Oct 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep it NSUnimplemented, as someone later should be able to implement it in Android.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@@ -256,7 +256,11 @@ open class Thread : NSObject {
let maxSupportedStackDepth = 128;
let addrs = UnsafeMutablePointer<UnsafeMutableRawPointer?>.allocate(capacity: maxSupportedStackDepth)
defer { addrs.deallocate(capacity: maxSupportedStackDepth) }
#if os(Android)
let count = maxSupportedStackDepth
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The count here is the number of successful frames returned by backtrace, and that they've been filled in by the caller. Since they won't have been any returned, isn't 0 the correct answer in the face of not being implemented? Admittedly this is being stubbed out from the caller below, but if it gets added elsewhere later then it would be better if this didn't contain a known bad number.

build-android Outdated

set -e

cd "$(dirname $0)/.." || exit 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small observation; this changes the directory you're currently in. If you wanted to just find out what directory you are in, you can do it in parenthesis e.g.

https://github.com/apple/swift/blob/cb3fcd4b83410f93558bb449695e1f1c2e69cfb9/utils/swift_build_support/test_swift_build_support.sh#L5

@alblue
Copy link
Contributor

alblue commented Oct 16, 2017

@swift-ci please test

1 similar comment
@alblue
Copy link
Contributor

alblue commented Oct 16, 2017

@swift-ci please test

@alblue
Copy link
Contributor

alblue commented Oct 16, 2017

@swift-ci please test

1 similar comment
@alblue
Copy link
Contributor

alblue commented Oct 17, 2017

@swift-ci please test

@alblue
Copy link
Contributor

alblue commented Oct 17, 2017

@swift-ci please test and merge

@swift-ci swift-ci merged commit 12c371a into swiftlang:master Oct 17, 2017
@amraboelela
Copy link
Contributor Author

Yeaaah :)
Thank you @alblue

@amraboelela amraboelela deleted the build-android-script branch October 20, 2017 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants